From b6b02ccff60456637e9c13dfaa95ff1e0e821453 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Fri, 24 May 2024 19:11:37 +0200 Subject: [PATCH] Simplify the integration test in adding a function to turn on/off an editing tool --- test/integration/freetext_editor_spec.mjs | 56 +++---------- test/integration/highlight_editor_spec.mjs | 98 ++++++++-------------- test/integration/ink_editor_spec.mjs | 29 +++---- test/integration/stamp_editor_spec.mjs | 23 +++-- test/integration/test_utils.mjs | 18 ++++ 5 files changed, 86 insertions(+), 138 deletions(-) diff --git a/test/integration/freetext_editor_spec.mjs b/test/integration/freetext_editor_spec.mjs index a32edab883d2f..d7afe96ab52c4 100644 --- a/test/integration/freetext_editor_spec.mjs +++ b/test/integration/freetext_editor_spec.mjs @@ -42,6 +42,7 @@ import { loadAndWait, pasteFromClipboard, scrollIntoView, + switchToEditor, waitForAnnotationEditorLayer, waitForEvent, waitForSelectedEditor, @@ -77,10 +78,7 @@ const clearAll = async page => { await waitForStorageEntries(page, 0); }; -const switchToFreeText = async page => { - await page.click("#editorFreeText"); - await page.waitForSelector(".annotationEditorLayer.freetextEditing"); -}; +const switchToFreeText = switchToEditor.bind(null, "FreeText"); const getXY = async (page, selector) => { const rect = await getRect(page, selector); @@ -1045,10 +1043,7 @@ describe("FreeText Editor", () => { ); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); // We want to check that the editor is displayed but not the original // canvas. @@ -1149,10 +1144,7 @@ describe("FreeText Editor", () => { await page.waitForSelector(`${editorSelector} .overlay.enabled`); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); await page.waitForSelector(`[data-annotation-id='popup_32R']`, { visible: true, @@ -1235,10 +1227,7 @@ describe("FreeText Editor", () => { ]); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); // We want to check that nothing is displayed. editorIds = await getEditors(page, "freeText"); @@ -1361,10 +1350,7 @@ describe("FreeText Editor", () => { await switchToFreeText(page); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); // TODO: remove this when we switch to BiDi. await hover(page, "[data-annotation-id='23R']"); @@ -1399,10 +1385,7 @@ describe("FreeText Editor", () => { ); // Exit editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); // Wait for the popup to be visible. await page.waitForFunction( @@ -2782,10 +2765,7 @@ describe("FreeText Editor", () => { expect(content).withContext(`In ${browserName}`).toEqual(data); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); await page.focus("#editorFreeText"); await page.keyboard.press(" "); @@ -3086,10 +3066,7 @@ describe("FreeText Editor", () => { await page.click(getEditorSelector(0), { count: 2 }); await page.type(`${getEditorSelector(0)} .internal`, "C"); - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); const [value] = await getSerialized(page, x => x.value); expect(value) @@ -3118,10 +3095,7 @@ describe("FreeText Editor", () => { await page.click(getEditorSelector(0), { count: 2 }); await page.type(`${getEditorSelector(0)} .internal`, "Z"); - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); const [value] = await getSerialized(page, x => x.value); expect(value) @@ -3593,10 +3567,7 @@ describe("FreeText Editor", () => { ); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); const oneToOne = Array.from(new Array(13).keys(), n => n + 2).concat( Array.from(new Array(13).keys(), n => 13 - n) @@ -3640,10 +3611,7 @@ describe("FreeText Editor", () => { await waitForSerialized(page, 0); // Disable editing mode. - await page.click("#editorFreeText"); - await page.waitForSelector( - `.annotationEditorLayer:not(.freetextEditing)` - ); + await switchToFreeText(page, /* disable = */ true); const thirteenToOne = Array.from(new Array(13).keys(), n => 13 - n); for (const pageNumber of thirteenToOne) { diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 927536e6ab1f7..27d8047e5a73d 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -30,6 +30,7 @@ import { kbUndo, loadAndWait, scrollIntoView, + switchToEditor, waitForSerialized, } from "./test_utils.mjs"; @@ -45,6 +46,8 @@ const waitForPointerUp = page => window.addEventListener("pointerup", resolve, { once: true }); }); +const switchToHighlight = switchToEditor.bind(null, "Highlight"); + const getXY = async (page, selector) => { const rect = await getRect(page, selector); return `${rect.x}::${rect.y}`; @@ -65,8 +68,7 @@ describe("Highlight Editor", () => { it("must scroll and check that the draw layer is there", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -114,8 +116,7 @@ describe("Highlight Editor", () => { it("must scroll and check that the highlight is selected", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -165,8 +166,7 @@ describe("Highlight Editor", () => { it("must highlight with red color", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -211,8 +211,7 @@ describe("Highlight Editor", () => { it("must scroll and change the color without exceptions", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); let rect = await getSpanRectFromText(page, 1, "Abstract"); let x = rect.x + rect.width / 2; @@ -300,8 +299,7 @@ describe("Highlight Editor", () => { it("must be correctly serialized", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -361,8 +359,7 @@ describe("Highlight Editor", () => { it("must check that we can use the keyboard to select a color", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const sel = getEditorSelector(0); const rect = await getSpanRectFromText(page, 1, "Abstract"); @@ -473,8 +470,7 @@ describe("Highlight Editor", () => { it("must check that a text highlight don't move when arrows are pressed", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -520,8 +516,7 @@ describe("Highlight Editor", () => { it("must check that the dropdown is hidden", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const sel = getEditorSelector(0); const rect = await getSpanRectFromText(page, 1, "Abstract"); @@ -562,8 +557,7 @@ describe("Highlight Editor", () => { it("must check that editor is unselected when the mouse is down on the text layer", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const sel = getEditorSelector(0); const rect = await getSpanRectFromText(page, 1, "Abstract"); @@ -606,8 +600,7 @@ describe("Highlight Editor", () => { it("must check that the thickness is correctly updated", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -683,8 +676,7 @@ describe("Highlight Editor", () => { it("must check that some text has been highlighted", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const sel = getEditorSelector(0); const spanRect = await getRect( @@ -746,8 +738,7 @@ describe("Highlight Editor", () => { it("must check that highlight is at the correct position", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -833,8 +824,7 @@ describe("Highlight Editor", () => { it("must check that it's possible to highlight a part of a link", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText( page, @@ -879,8 +869,7 @@ describe("Highlight Editor", () => { it("must check that it's possible to highlight a part of a form", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect1 = await getRect(page, "#pdfjs_internal_id_5R"); const rect2 = await getRect(page, "#pdfjs_internal_id_16R"); @@ -1029,10 +1018,7 @@ describe("Highlight Editor", () => { window.uiManager.reset(); }); // Disable editing mode. - await page.click("#editorHighlight"); - await page.waitForSelector( - `.annotationEditorLayer:not(.highlightEditing)` - ); + await switchToHighlight(page, /* disable */ true); } }); @@ -1043,8 +1029,7 @@ describe("Highlight Editor", () => { it("must check that the caret can move a highlighted text", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -1084,8 +1069,7 @@ describe("Highlight Editor", () => { it("must check that selection is correctly highlighted on arrow down key pressed", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); await page.evaluate(() => { const text = @@ -1120,8 +1104,7 @@ describe("Highlight Editor", () => { it("must check that an highlight can be left with the keyboard", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); if (browserName === "chrome") { // Unfortunately, we can't test this on Chrome because we can't set @@ -1208,8 +1191,7 @@ describe("Highlight Editor", () => { it("must check that the highlight has been deleted", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -1243,8 +1225,7 @@ describe("Highlight Editor", () => { it("must check the thickness input state", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); let rect = await getSpanRectFromText(page, 1, "Abstract"); await page.mouse.click( @@ -1273,13 +1254,8 @@ describe("Highlight Editor", () => { await page.waitForSelector(getEditorSelector(0)); await page.waitForSelector("#editorFreeHighlightThickness[disabled]"); - await page.click("#editorHighlight"); - await page.waitForSelector( - ".annotationEditorLayer:not(.highlightEditing)" - ); - - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page, /* disable */ true); + await switchToHighlight(page); await page.waitForSelector( "#editorFreeHighlightThickness:not([disabled])" @@ -1303,8 +1279,7 @@ describe("Highlight Editor", () => { it("must check that the quadpoints for an highlight are almost correct", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Languages"); await page.mouse.click( @@ -1339,8 +1314,7 @@ describe("Highlight Editor", () => { it("must check that the highlight editor is unselected", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -1371,8 +1345,7 @@ describe("Highlight Editor", () => { it("must check the editor coordinates", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -1409,8 +1382,7 @@ describe("Highlight Editor", () => { it("must check that the highlights are correctly hidden/shown", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); let rect = await getRect(page, ".annotationEditorLayer"); const clickHandle = await waitForPointerUp(page); @@ -1517,8 +1489,7 @@ describe("Highlight Editor", () => { it("must check the focus order", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); let rect = await getSpanRectFromText(page, 1, "Abstract"); let x = rect.x + rect.width / 2; @@ -1559,8 +1530,7 @@ describe("Highlight Editor", () => { it("must check that a highlight can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -1604,8 +1574,7 @@ describe("Highlight Editor", () => { it("must check that a highlight can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; @@ -1665,8 +1634,7 @@ describe("Highlight Editor", () => { it("must check that a highlight can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorHighlight"); - await page.waitForSelector(".annotationEditorLayer.highlightEditing"); + await switchToHighlight(page); const rect = await getSpanRectFromText(page, 1, "Abstract"); const x = rect.x + rect.width / 2; diff --git a/test/integration/ink_editor_spec.mjs b/test/integration/ink_editor_spec.mjs index 6c758b01390d8..8cf5059dfb2ae 100644 --- a/test/integration/ink_editor_spec.mjs +++ b/test/integration/ink_editor_spec.mjs @@ -25,6 +25,7 @@ import { kbUndo, loadAndWait, scrollIntoView, + switchToEditor, waitForSerialized, waitForStorageEntries, } from "./test_utils.mjs"; @@ -52,6 +53,8 @@ const commit = async page => { await page.waitForSelector(".inkEditor.selectedEditor.draggable.disabled"); }; +const switchToInk = switchToEditor.bind(null, "Ink"); + describe("Ink Editor", () => { describe("Basic operations", () => { let pages; @@ -67,7 +70,7 @@ describe("Ink Editor", () => { it("must draw, undo a deletion and check that the editors are not selected", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -151,7 +154,7 @@ describe("Ink Editor", () => { it("must draw something", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -190,8 +193,7 @@ describe("Ink Editor", () => { it("must check that the editor layer is disabled", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -214,8 +216,7 @@ describe("Ink Editor", () => { ); } - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer:not(.inkEditing)"); + await switchToInk(page, /* disable */ true); const fourteenToOne = Array.from(new Array(13).keys(), n => 13 - n); for (const pageNumber of fourteenToOne) { @@ -247,8 +248,7 @@ describe("Ink Editor", () => { it("must check that the ink editor is committed", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -282,8 +282,7 @@ describe("Ink Editor", () => { it("must check that a draw can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -326,8 +325,7 @@ describe("Ink Editor", () => { it("must check that a draw can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -383,8 +381,7 @@ describe("Ink Editor", () => { it("must check that a draw can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); @@ -435,9 +432,7 @@ describe("Ink Editor", () => { it("must check that we can draw several times on the same canvas", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorInk"); - await page.waitForSelector(".annotationEditorLayer.inkEditing"); - + await switchToInk(page); const rect = await getRect(page, ".annotationEditorLayer"); let xStart = rect.x + 10; diff --git a/test/integration/stamp_editor_spec.mjs b/test/integration/stamp_editor_spec.mjs index 050a48fff8c77..82979e6f85c8e 100644 --- a/test/integration/stamp_editor_spec.mjs +++ b/test/integration/stamp_editor_spec.mjs @@ -30,6 +30,7 @@ import { pasteFromClipboard, scrollIntoView, serializeBitmapDimensions, + switchToEditor, waitForAnnotationEditorLayer, waitForEntryInStorage, waitForSelectedEditor, @@ -84,6 +85,8 @@ const copyImage = async (page, imagePath, number) => { await waitForImage(page, getEditorSelector(number)); }; +const switchToStamp = switchToEditor.bind(null, "Stamp"); + describe("Stamp Editor", () => { describe("Basic operations", () => { let pages; @@ -104,7 +107,7 @@ describe("Stamp Editor", () => { return; } - await page.click("#editorStamp"); + await switchToStamp(page); await page.click("#editorStampAddImage"); const input = await page.$("#stampEditorFileInput"); @@ -181,7 +184,7 @@ describe("Stamp Editor", () => { return; } - await page.click("#editorStamp"); + await switchToStamp(page); const names = ["bottomLeft", "bottomRight", "topRight", "topLeft"]; for (let i = 0; i < 4; i++) { @@ -256,7 +259,7 @@ describe("Stamp Editor", () => { it("must check that the alt-text flow is correctly implemented", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); @@ -425,7 +428,7 @@ describe("Stamp Editor", () => { it("must check that the dimensions change", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); @@ -593,8 +596,7 @@ describe("Stamp Editor", () => { it("must check that a stamp can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); - await page.waitForSelector(".annotationEditorLayer.stampEditing"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); await page.waitForSelector(getEditorSelector(0)); @@ -626,8 +628,7 @@ describe("Stamp Editor", () => { it("must check that a stamp can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); - await page.waitForSelector(".annotationEditorLayer.stampEditing"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); await page.waitForSelector(getEditorSelector(0)); @@ -672,8 +673,7 @@ describe("Stamp Editor", () => { it("must check that a stamp can be undone", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); - await page.waitForSelector(".annotationEditorLayer.stampEditing"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); await page.waitForSelector(getEditorSelector(0)); @@ -713,8 +713,7 @@ describe("Stamp Editor", () => { it("must check that a resized stamp has its canvas at the right position", async () => { await Promise.all( pages.map(async ([browserName, page]) => { - await page.click("#editorStamp"); - await page.waitForSelector(".annotationEditorLayer.stampEditing"); + await switchToStamp(page); await copyImage(page, "../images/firefox_logo.png", 0); await page.waitForSelector(getEditorSelector(0)); diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index 9078674bbc57a..2113c4ed224b1 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -581,6 +581,23 @@ async function kbFocusPrevious(page) { await awaitPromise(handle); } +async function switchToEditor(name, page, disable = false) { + const modeChangedHandle = await createPromise(page, resolve => { + window.PDFViewerApplication.eventBus.on( + "annotationeditormodechanged", + resolve, + { once: true } + ); + }); + await page.click(`#editor${name}`); + name = name.toLowerCase(); + await page.waitForSelector( + ".annotationEditorLayer" + + (disable ? `:not(.${name}Editing)` : `.${name}Editing`) + ); + await awaitPromise(modeChangedHandle); +} + export { awaitPromise, clearInput, @@ -622,6 +639,7 @@ export { pasteFromClipboard, scrollIntoView, serializeBitmapDimensions, + switchToEditor, waitForAnnotationEditorLayer, waitForEntryInStorage, waitForEvent,