1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Refactor the copy/paste logic in the integration tests

The integration tests are currently not consistent in how they do
copy/pasting: some tests use the `kbCopy`/`kbPaste` functions with
waiting for the event inline, some have their own helper function to
combine those actions and some even call `kbCopy`/`kbPaste` without
waiting for the event at all (which can cause intermittent failures).

This commit fixes the issues by providing a set of four helper functions
that all tests use and that abstract e.g. waiting for the event away
from the caller. This makes the invididual tests simpler and consistent,
reduces code duplication and fixes possible intermittent failures
due to not waiting for events to trigger.
This commit is contained in:
Tim van der Meij 2024-06-21 20:37:01 +02:00
parent 2fbd61944b
commit 55ba4aa66a
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
4 changed files with 69 additions and 85 deletions

View file

@ -17,6 +17,8 @@ import {
applyFunctionToEditor,
awaitPromise,
closePages,
copy,
copyToClipboard,
getEditorDimensions,
getEditorSelector,
getFirstSerialized,
@ -24,11 +26,10 @@ import {
getSerialized,
kbBigMoveDown,
kbBigMoveRight,
kbCopy,
kbPaste,
kbSelectAll,
kbUndo,
loadAndWait,
paste,
pasteFromClipboard,
scrollIntoView,
serializeBitmapDimensions,
@ -78,12 +79,10 @@ const copyImage = async (page, imagePath, number) => {
const data = fs
.readFileSync(path.join(__dirname, imagePath))
.toString("base64");
await pasteFromClipboard(
page,
{ "image/png": `data:image/png;base64,${data}` },
"",
500
);
await copyToClipboard(page, { "image/png": `data:image/png;base64,${data}` });
await pasteFromClipboard(page);
await waitForImage(page, getEditorSelector(number));
};
@ -570,13 +569,13 @@ describe("Stamp Editor", () => {
await page1.click("#editorStamp");
await copyImage(page1, "../images/firefox_logo.png", 0);
await kbCopy(page1);
await copy(page1);
const [, page2] = pages2[i];
await page2.bringToFront();
await page2.click("#editorStamp");
await kbPaste(page2);
await paste(page2);
await waitForImage(page2, getEditorSelector(0));
}
@ -831,8 +830,8 @@ describe("Stamp Editor", () => {
);
await page.waitForSelector(`${getEditorSelector(0)} .altText.done`);
await kbCopy(page);
await kbPaste(page);
await copy(page);
await paste(page);
await page.waitForSelector(`${getEditorSelector(1)} .altText.done`);
await waitForSerialized(page, 2);