Skip to content

Commit

Permalink
Implement a helper function for unselecting an editor in the integrat…
Browse files Browse the repository at this point in the history
…ion 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.
  • Loading branch information
timvandermeij committed Jan 19, 2025
1 parent 663e416 commit 3b13e44
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
16 changes: 6 additions & 10 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
scrollIntoView,
selectEditor,
switchToEditor,
unselectEditor,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
waitForEditorMovedInDOM,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
11 changes: 4 additions & 7 deletions test/integration/highlight_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import {
scrollIntoView,
setCaretAt,
switchToEditor,
unselectEditor,
waitAndClick,
waitForAnnotationModeChanged,
waitForSelectedEditor,
waitForSerialized,
waitForTimeout,
waitForUnselectedEditor,
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
import fs from "fs";
Expand Down Expand Up @@ -1044,8 +1044,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,
Expand Down Expand Up @@ -1795,8 +1794,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;
Expand Down Expand Up @@ -1866,8 +1864,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;
Expand Down
8 changes: 3 additions & 5 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ import {
selectEditor,
serializeBitmapDimensions,
switchToEditor,
unselectEditor,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
waitForEntryInStorage,
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTimeout,
waitForUnselectedEditor,
} from "./test_utils.mjs";
import { fileURLToPath } from "url";
import fs from "fs";
Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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(() => {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
}
Expand Down Expand Up @@ -882,6 +887,7 @@ export {
serializeBitmapDimensions,
setCaretAt,
switchToEditor,
unselectEditor,
waitAndClick,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
Expand Down

0 comments on commit 3b13e44

Please sign in to comment.