From c6b934ac9b7e2521a956aef7009442d575dfd39b Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sat, 18 Jan 2025 20:00:23 +0100 Subject: [PATCH] Implement a helper function for unselecting an editor in the integration tests This has multiple advantages: - it improves consistency between the various editor integration tests; - it makes the code easier to read/understand; - it reduces code duplication. --- test/integration/freetext_editor_spec.mjs | 16 ++++++---------- test/integration/highlight_editor_spec.mjs | 11 ++++------- test/integration/stamp_editor_spec.mjs | 8 +++----- test/integration/test_utils.mjs | 6 ++++++ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index 42a2c41dc3521..13afe708d4760 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -45,6 +45,7 @@ import { scrollIntoView, selectEditor, switchToEditor, + unselectEditor, waitForAnnotationEditorLayer, waitForAnnotationModeChanged, waitForEditorMovedInDOM, @@ -2225,8 +2226,7 @@ describe("FreeText Editor", () => { await commit(page); // Unselect. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); // Select the editor created previously. await selectEditor(page, editorSelector); @@ -2300,8 +2300,7 @@ describe("FreeText Editor", () => { await commit(page); // Unselect. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); // Select the editor created previously. await selectEditor(page, editorSelector); @@ -2481,8 +2480,7 @@ describe("FreeText Editor", () => { await commit(page); // Unselect. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); content = await page.$eval(getEditorSelector(1), el => el.innerText.trimEnd() @@ -2509,8 +2507,7 @@ describe("FreeText Editor", () => { await commit(page); // Unselect. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); let content = await page.$eval(getEditorSelector(2), el => el.innerText.trimEnd() @@ -2532,8 +2529,7 @@ describe("FreeText Editor", () => { await commit(page); // Unselect. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); content = await page.$eval(editorSelector, el => el.innerText.trimEnd() diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 5632bde2f8e72..b180239b9a486 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -34,12 +34,12 @@ import { selectEditor, setCaretAt, switchToEditor, + unselectEditor, waitAndClick, waitForAnnotationModeChanged, waitForSelectedEditor, waitForSerialized, waitForTimeout, - waitForUnselectedEditor, } from "./test_utils.mjs"; import { fileURLToPath } from "url"; import fs from "fs"; @@ -1045,8 +1045,7 @@ describe("Highlight Editor", () => { const y = rect.y + rect.height / 2; await page.mouse.click(x, y, { count: 2, delay: 100 }); await page.waitForSelector(`${getEditorSelector(0)}`); - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, getEditorSelector(0)); + await unselectEditor(page, getEditorSelector(0)); await setCaretAt( page, @@ -1796,8 +1795,7 @@ describe("Highlight Editor", () => { await page.mouse.click(x, y, { count: 2, delay: 100 }); await page.waitForSelector(editorSelector); await waitForSerialized(page, 1); - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); const clickHandle = await waitForPointerUp(page); y = rect.y - rect.height; @@ -1867,8 +1865,7 @@ describe("Highlight Editor", () => { await page.mouse.click(x, y, { count: 3, delay: 100 }); await page.waitForSelector(editorSelector); await waitForSerialized(page, 1); - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); const clickHandle = await waitForPointerUp(page); y = rect.y - 3 * rect.height; diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index 4d4cb8628308b..7118534c987c0 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -41,6 +41,7 @@ import { selectEditor, serializeBitmapDimensions, switchToEditor, + unselectEditor, waitForAnnotationEditorLayer, waitForAnnotationModeChanged, waitForEntryInStorage, @@ -48,7 +49,6 @@ import { waitForSerialized, waitForStorageEntries, waitForTimeout, - waitForUnselectedEditor, } from "./test_utils.mjs"; import { fileURLToPath } from "url"; import fs from "fs"; @@ -1056,8 +1056,7 @@ describe("Stamp Editor", () => { .toEqual("Review alt text"); // Unselect and select the editor and check that the badge is visible. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); await page.waitForSelector(".editToolbar", { visible: false }); await page.waitForSelector(".noAltTextBadge", { visible: true }); @@ -1106,8 +1105,7 @@ describe("Stamp Editor", () => { .toEqual("Missing alt text"); // Unselect and select the editor and check that the badge is visible. - await page.keyboard.press("Escape"); - await waitForUnselectedEditor(page, editorSelector); + await unselectEditor(page, editorSelector); await page.waitForSelector(".editToolbar", { visible: false }); await page.waitForSelector(".noAltTextBadge", { visible: true }); await page.evaluate(() => { diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index f67a02e235d40..ace187dddbf88 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -361,6 +361,11 @@ async function waitForSelectedEditor(page, selector) { return page.waitForSelector(`${selector}.selectedEditor`); } +async function unselectEditor(page, selector) { + await page.keyboard.press("Escape"); + await waitForUnselectedEditor(page, selector); +} + async function waitForUnselectedEditor(page, selector) { return page.waitForSelector(`${selector}:not(.selectedEditor)`); } @@ -882,6 +887,7 @@ export { serializeBitmapDimensions, setCaretAt, switchToEditor, + unselectEditor, waitAndClick, waitForAnnotationEditorLayer, waitForAnnotationModeChanged,