From 4f3dbcf24dcba7db9af1a2407630544bcf514f29 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Feb 2025 18:37:42 +0100 Subject: [PATCH 1/5] Remove the `waitForEditorMovedInDOM` helper function export It's no longer used outside of `test_utils.mjs` since commit 301f1bb. --- test/integration/test_utils.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index b89d0feae..0f4a879e6 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -933,7 +933,6 @@ export { waitAndClick, waitForAnnotationEditorLayer, waitForAnnotationModeChanged, - waitForEditorMovedInDOM, waitForEntryInStorage, waitForEvent, waitForNoElement, From 07629e105cec1a786ec98e08baa785723239f0f7 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Feb 2025 18:39:42 +0100 Subject: [PATCH 2/5] Deduplicate the `getXY` helper function in the highlight editor integration tests The helper function is available in `test_utils.mjs` since commit 301f1bb, so by exporting it there it can be reused. --- test/integration/highlight_editor_spec.mjs | 6 +----- test/integration/test_utils.mjs | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 9ced1cf50..e24698ca5 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -22,6 +22,7 @@ import { getRect, getSerialized, getSpanRectFromText, + getXY, kbBigMoveLeft, kbBigMoveUp, kbFocusNext, @@ -60,11 +61,6 @@ const waitForPointerUp = page => 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/test_utils.mjs b/test/integration/test_utils.mjs index 0f4a879e6..68761f187 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -901,6 +901,7 @@ export { getSelector, getSerialized, getSpanRectFromText, + getXY, hover, isCanvasWhite, isVisible, From 060ef0e15e8147457cbad75f229dd7c5b2ba3793 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Feb 2025 19:03:29 +0100 Subject: [PATCH 3/5] Deduplicate the `waitForPointerUp` helper function in the highlight editor integration tests The helper function is available in `test_utils.mjs` since commit 3fe55ba, so we can remove the local copy by importing it. --- test/integration/highlight_editor_spec.mjs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index e24698ca5..6241195d2 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -16,7 +16,6 @@ import { awaitPromise, closePages, - createPromise, getEditorSelector, getFirstSerialized, getRect, @@ -37,6 +36,7 @@ import { unselectEditor, waitAndClick, waitForAnnotationModeChanged, + waitForPointerUp, waitForSelectedEditor, waitForSerialized, waitForTimeout, @@ -54,11 +54,6 @@ const selectAll = async page => { ); }; -const waitForPointerUp = page => - createPromise(page, resolve => { - window.addEventListener("pointerup", resolve, { once: true }); - }); - const switchToHighlight = switchToEditor.bind(null, "Highlight"); describe("Highlight Editor", () => { From f155b69c077e0534a1d22a7c23e1e4a85b354b61 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Feb 2025 18:49:14 +0100 Subject: [PATCH 4/5] Introduce a generic `selectEditors` helper function This replaces the various copies of this logic with a single helper that we template for each editor type, similar to what we already do for the `switchToEditor` helper. --- test/integration/freetext_editor_spec.mjs | 9 ++------- test/integration/highlight_editor_spec.mjs | 9 ++------- test/integration/ink_editor_spec.mjs | 9 ++------- test/integration/stamp_editor_spec.mjs | 9 ++------- test/integration/test_utils.mjs | 8 ++++++++ 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 404e24eb9..9056ca222 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -37,7 +37,6 @@ import { kbModifierDown, kbModifierUp, kbRedo, - kbSelectAll, kbUndo, loadAndWait, moveEditor, @@ -45,6 +44,7 @@ import { pasteFromClipboard, scrollIntoView, selectEditor, + selectEditors, switchToEditor, unselectEditor, waitForAnnotationEditorLayer, @@ -57,12 +57,7 @@ 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); diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 6241195d2..f9d4199c2 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -27,10 +27,10 @@ import { kbFocusNext, kbFocusPrevious, kbSave, - kbSelectAll, kbUndo, loadAndWait, scrollIntoView, + selectEditors, setCaretAt, switchToEditor, unselectEditor, @@ -47,12 +47,7 @@ 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 selectAll = selectEditors.bind(null, "highlight"); const switchToHighlight = switchToEditor.bind(null, "Highlight"); diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 2e927231f..a9de1bd3e 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -24,12 +24,12 @@ import { getSerialized, isCanvasWhite, kbRedo, - kbSelectAll, kbUndo, loadAndWait, moveEditor, scrollIntoView, selectEditor, + selectEditors, switchToEditor, waitForAnnotationModeChanged, waitForNoElement, @@ -40,12 +40,7 @@ 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); diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index be3780230..8f319ba75 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -32,13 +32,13 @@ import { isVisible, kbBigMoveDown, kbBigMoveRight, - kbSelectAll, kbUndo, loadAndWait, paste, pasteFromClipboard, scrollIntoView, selectEditor, + selectEditors, serializeBitmapDimensions, switchToEditor, unselectEditor, @@ -57,12 +57,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 selectAll = selectEditors.bind(null, "stamp"); const clearAll = async page => { await selectAll(page); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index 68761f187..d204a59d3 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -809,6 +809,13 @@ 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)`) + ); +} + function waitForNoElement(page, selector) { return page.waitForFunction( sel => !document.querySelector(sel), @@ -927,6 +934,7 @@ export { pasteFromClipboard, scrollIntoView, selectEditor, + selectEditors, serializeBitmapDimensions, setCaretAt, switchToEditor, From acc5a2153a55f90bd7e1491f34096cd681d11ff1 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Feb 2025 18:52:19 +0100 Subject: [PATCH 5/5] Introduce a generic `clearEditors` helper function This replaces the various copies of this logic with a single helper that we template for each editor type, similar to what we already do for the `switchToEditor` helper. --- test/integration/freetext_editor_spec.mjs | 9 ++------- test/integration/ink_editor_spec.mjs | 7 ++----- test/integration/stamp_editor_spec.mjs | 11 ++--------- test/integration/test_utils.mjs | 7 +++++++ 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 9056ca222..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, @@ -59,13 +60,7 @@ import { PNG } from "pngjs"; 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/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index a9de1bd3e..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, @@ -42,11 +43,7 @@ import { 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 8f319ba75..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, @@ -38,7 +39,6 @@ import { pasteFromClipboard, scrollIntoView, selectEditor, - selectEditors, serializeBitmapDimensions, switchToEditor, unselectEditor, @@ -47,7 +47,6 @@ import { waitForEntryInStorage, waitForSelectedEditor, waitForSerialized, - waitForStorageEntries, waitForTimeout, } from "./test_utils.mjs"; import { fileURLToPath } from "url"; @@ -57,13 +56,7 @@ import { PNG } from "pngjs"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const selectAll = selectEditors.bind(null, "stamp"); - -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 d204a59d3..bd0af5f56 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -816,6 +816,12 @@ async function selectEditors(name, page) { ); } +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), @@ -888,6 +894,7 @@ export { applyFunctionToEditor, awaitPromise, cleanupEditing, + clearEditors, clearInput, closePages, closeSinglePage,