Skip to content

[Editor] Add two integration tests for the signature feature #19512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions test/integration/ink_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import {
awaitPromise,
closePages,
createPromise,
dragAndDrop,
getAnnotationSelector,
getEditors,
Expand All @@ -33,17 +32,13 @@ import {
switchToEditor,
waitForAnnotationModeChanged,
waitForNoElement,
waitForPointerUp,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTimeout,
} from "./test_utils.mjs";

const waitForPointerUp = page =>
createPromise(page, resolve => {
window.addEventListener("pointerup", resolve, { once: true });
});

const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
Expand Down
123 changes: 123 additions & 0 deletions test/integration/signature_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
*/

import {
awaitPromise,
closePages,
getEditorSelector,
getRect,
loadAndWait,
switchToEditor,
waitForPointerUp,
waitForTimeout,
} from "./test_utils.mjs";

import { fileURLToPath } from "url";
import path from "path";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const switchToSignature = switchToEditor.bind(null, "Signature");

describe("Signature Editor", () => {
Expand Down Expand Up @@ -207,6 +214,122 @@ describe("Signature Editor", () => {
})
);
});

it("must check drawing with the mouse", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToSignature(page);
await page.click("#editorSignatureAddSignature");

await page.waitForSelector("#addSignatureDialog", {
visible: true,
});

await page.click("#addSignatureDrawButton");
const drawSelector = "#addSignatureDraw";
await page.waitForSelector(drawSelector, { visible: true });

let description = await page.$eval(
descriptionInputSelector,
el => el.value
);
expect(description).withContext(browserName).toEqual("");
await page.waitForSelector(`${addButtonSelector}:disabled`);

const { x, y, width, height } = await getRect(page, drawSelector);
const clickHandle = await waitForPointerUp(page);
await page.mouse.move(x + 0.1 * width, y + 0.1 * height);
await page.mouse.down();
await page.mouse.move(x + 0.3 * width, y + 0.3 * height);
await page.mouse.up();
await awaitPromise(clickHandle);
await page.waitForSelector(`${addButtonSelector}:not(:disabled)`);

// The save button should be enabled now.
await page.waitForSelector(
"#addSignatureSaveContainer:not([disabled])"
);
await page.waitForSelector("#addSignatureSaveCheckbox[checked=true]");

// The description has been filled in automatically.
await page.waitForFunction(
`document.querySelector("${descriptionInputSelector}").value !== ""`
);
description = await page.$eval(
descriptionInputSelector,
el => el.value
);
expect(description).withContext(browserName).toEqual("Signature");

await page.click("#addSignatureAddButton");
await page.waitForSelector("#addSignatureDialog", {
visible: false,
});

await page.waitForSelector(
".canvasWrapper > svg use[href='#path_p1_0']"
);
})
);
});

it("must check adding an image", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToSignature(page);
await page.click("#editorSignatureAddSignature");

await page.waitForSelector("#addSignatureDialog", {
visible: true,
});

await page.click("#addSignatureImageButton");
await page.waitForSelector("#addSignatureImagePlaceholder", {
visible: true,
});

let description = await page.$eval(
descriptionInputSelector,
el => el.value
);
expect(description).withContext(browserName).toEqual("");
await page.waitForSelector(`${addButtonSelector}:disabled`);

const input = await page.$("#addSignatureFilePicker");
await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}`
);
await page.waitForSelector(`#addSignatureImage > path:not([d=""])`);

// The save button should be enabled now.
await page.waitForSelector(
"#addSignatureSaveContainer:not([disabled])"
);
await page.waitForSelector("#addSignatureSaveCheckbox[checked=true]");

// The description has been filled in automatically.
await page.waitForFunction(
`document.querySelector("${descriptionInputSelector}").value !== ""`
);
description = await page.$eval(
descriptionInputSelector,
el => el.value
);
expect(description)
.withContext(browserName)
.toEqual("firefox_logo.png");

await page.click("#addSignatureAddButton");
await page.waitForSelector("#addSignatureDialog", {
visible: false,
});

await page.waitForSelector(
".canvasWrapper > svg use[href='#path_p1_0']"
);
})
);
});
});

describe("Bug 1948741", () => {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ async function waitAndClick(page, selector, clickOptions = {}) {
await page.click(selector, clickOptions);
}

function waitForPointerUp(page) {
return createPromise(page, resolve => {
window.addEventListener("pointerup", resolve, { once: true });
});
}

function getSelector(id) {
return `[data-element-id="${id}"]`;
}
Expand Down Expand Up @@ -895,6 +901,7 @@ export {
waitForEvent,
waitForNoElement,
waitForPageRendered,
waitForPointerUp,
waitForSandboxTrip,
waitForSelectedEditor,
waitForSerialized,
Expand Down