mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-24 09:08:07 +02:00
[Editor] Add two integration tests for the signature feature
- one test about adding a drawn signature - an other one about adding a signature extracted from an image.
This commit is contained in:
parent
a857ca3261
commit
3fe55baa5e
3 changed files with 131 additions and 6 deletions
|
@ -16,7 +16,6 @@
|
|||
import {
|
||||
awaitPromise,
|
||||
closePages,
|
||||
createPromise,
|
||||
dragAndDrop,
|
||||
getAnnotationSelector,
|
||||
getEditors,
|
||||
|
@ -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(
|
||||
|
|
|
@ -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", () => {
|
||||
|
@ -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", () => {
|
||||
|
|
|
@ -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}"]`;
|
||||
}
|
||||
|
@ -895,6 +901,7 @@ export {
|
|||
waitForEvent,
|
||||
waitForNoElement,
|
||||
waitForPageRendered,
|
||||
waitForPointerUp,
|
||||
waitForSandboxTrip,
|
||||
waitForSelectedEditor,
|
||||
waitForSerialized,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue