1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #19543 from timvandermeij/integration-tests-helpers

Refactor the editor integration test helper functions
This commit is contained in:
Jonas Jenwald 2025-02-23 22:56:38 +01:00 committed by GitHub
commit ed64faa88c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 59 deletions

View file

@ -15,6 +15,7 @@
import {
awaitPromise,
clearEditors,
closePages,
copy,
copyToClipboard,
@ -37,7 +38,6 @@ import {
kbModifierDown,
kbModifierUp,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
moveEditor,
@ -45,6 +45,7 @@ import {
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
switchToEditor,
unselectEditor,
waitForAnnotationEditorLayer,
@ -57,20 +58,9 @@ import {
} from "./test_utils.mjs";
import { PNG } from "pngjs";
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".freeTextEditor:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "freeText");
const clearAll = async page => {
await selectAll(page);
await page.keyboard.down("Control");
await page.keyboard.press("Backspace");
await page.keyboard.up("Control");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "freeText");
const commit = async page => {
await page.keyboard.press("Escape");

View file

@ -16,26 +16,27 @@
import {
awaitPromise,
closePages,
createPromise,
getEditorSelector,
getFirstSerialized,
getRect,
getSerialized,
getSpanRectFromText,
getXY,
kbBigMoveLeft,
kbBigMoveUp,
kbFocusNext,
kbFocusPrevious,
kbSave,
kbSelectAll,
kbUndo,
loadAndWait,
scrollIntoView,
selectEditors,
setCaretAt,
switchToEditor,
unselectEditor,
waitAndClick,
waitForAnnotationModeChanged,
waitForPointerUp,
waitForSelectedEditor,
waitForSerialized,
waitForTimeout,
@ -46,25 +47,10 @@ import path from "path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".highlightEditor:not(.selectedEditor)")
);
};
const waitForPointerUp = page =>
createPromise(page, resolve => {
window.addEventListener("pointerup", resolve, { once: true });
});
const selectAll = selectEditors.bind(null, "highlight");
const switchToHighlight = switchToEditor.bind(null, "Highlight");
const getXY = async (page, selector) => {
const rect = await getRect(page, selector);
return `${rect.x}::${rect.y}`;
};
describe("Highlight Editor", () => {
describe("Editor must be removed without exception", () => {
let pages;

View file

@ -15,6 +15,7 @@
import {
awaitPromise,
clearEditors,
closePages,
dragAndDrop,
getAnnotationSelector,
@ -24,12 +25,12 @@ import {
getSerialized,
isCanvasWhite,
kbRedo,
kbSelectAll,
kbUndo,
loadAndWait,
moveEditor,
scrollIntoView,
selectEditor,
selectEditors,
switchToEditor,
waitForAnnotationModeChanged,
waitForNoElement,
@ -40,18 +41,9 @@ import {
waitForTimeout,
} from "./test_utils.mjs";
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".inkEditor.disabled:not(.selectedEditor)")
);
};
const selectAll = selectEditors.bind(null, "ink");
const clearAll = async page => {
await selectAll(page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "ink");
const commit = async page => {
await page.keyboard.press("Escape");

View file

@ -17,6 +17,7 @@ import {
applyFunctionToEditor,
awaitPromise,
cleanupEditing,
clearEditors,
clearInput,
closePages,
copy,
@ -32,7 +33,6 @@ import {
isVisible,
kbBigMoveDown,
kbBigMoveRight,
kbSelectAll,
kbUndo,
loadAndWait,
paste,
@ -47,7 +47,6 @@ import {
waitForEntryInStorage,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTimeout,
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
@ -57,18 +56,7 @@ import { PNG } from "pngjs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const selectAll = async page => {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(".stampEditor:not(.selectedEditor)")
);
};
const clearAll = async page => {
await selectAll(page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
};
const clearAll = clearEditors.bind(null, "stamp");
const waitForImage = async (page, selector) => {
await page.waitForSelector(`${selector} canvas`);

View file

@ -809,6 +809,19 @@ async function switchToEditor(name, page, disable = false) {
await awaitPromise(modeChangedHandle);
}
async function selectEditors(name, page) {
await kbSelectAll(page);
await page.waitForFunction(
() => !document.querySelector(`.${name}Editor:not(.selectedEditor)`)
);
}
async function clearEditors(name, page) {
await selectEditors(name, page);
await page.keyboard.press("Backspace");
await waitForStorageEntries(page, 0);
}
function waitForNoElement(page, selector) {
return page.waitForFunction(
sel => !document.querySelector(sel),
@ -881,6 +894,7 @@ export {
applyFunctionToEditor,
awaitPromise,
cleanupEditing,
clearEditors,
clearInput,
closePages,
closeSinglePage,
@ -901,6 +915,7 @@ export {
getSelector,
getSerialized,
getSpanRectFromText,
getXY,
hover,
isCanvasWhite,
isVisible,
@ -926,6 +941,7 @@ export {
pasteFromClipboard,
scrollIntoView,
selectEditor,
selectEditors,
serializeBitmapDimensions,
setCaretAt,
switchToEditor,
@ -933,7 +949,6 @@ export {
waitAndClick,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
waitForEditorMovedInDOM,
waitForEntryInStorage,
waitForEvent,
waitForNoElement,