diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 404e24eb9..29c24a487 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -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"); diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 9ced1cf50..f9d4199c2 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -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; diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 2e927231f..ea6634a5a 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -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"); diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index be3780230..fbd153762 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -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`); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index b89d0feae..bd0af5f56 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -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,