Isolate the stamp editor integration tests

To avoid being able to introduce dependencies between tests this commit
makes sure that we close the document between tests so that we can't
accidentally rely on state set by a previous test.
This commit is contained in:
Tim van der Meij 2025-04-13 14:19:24 +02:00
parent 44243761a5
commit 7c8262ccc9
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 43 additions and 105 deletions

View File

@ -16,7 +16,6 @@
import { import {
applyFunctionToEditor, applyFunctionToEditor,
awaitPromise, awaitPromise,
cleanupEditing,
clearEditors, clearEditors,
clearInput, clearInput,
closePages, closePages,
@ -31,7 +30,6 @@ import {
getRect, getRect,
getSerialized, getSerialized,
isCanvasMonochrome, isCanvasMonochrome,
isVisible,
kbBigMoveDown, kbBigMoveDown,
kbBigMoveRight, kbBigMoveRight,
kbUndo, kbUndo,
@ -101,7 +99,7 @@ describe("Stamp Editor", () => {
describe("Basic operations", () => { describe("Basic operations", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", null, { pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", null, {
eventBusSetup: eventBus => { eventBusSetup: eventBus => {
eventBus.on("annotationeditoruimanager", ({ uiManager }) => { eventBus.on("annotationeditoruimanager", ({ uiManager }) => {
@ -112,10 +110,6 @@ describe("Stamp Editor", () => {
}); });
afterEach(async () => { afterEach(async () => {
await cleanupEditing(pages, switchToStamp);
});
afterAll(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -203,7 +197,7 @@ describe("Stamp Editor", () => {
describe("Resize", () => { describe("Resize", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50, { pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50, {
eventBusSetup: eventBus => { eventBusSetup: eventBus => {
eventBus.on("annotationeditoruimanager", ({ uiManager }) => { eventBus.on("annotationeditoruimanager", ({ uiManager }) => {
@ -213,12 +207,8 @@ describe("Stamp Editor", () => {
}); });
}); });
afterAll(async () => {
await closePages(pages);
});
afterEach(async () => { afterEach(async () => {
await cleanupEditing(pages, switchToStamp); await closePages(pages);
}); });
it("must check that an added image stay within the page", async () => { it("must check that an added image stay within the page", async () => {
@ -325,11 +315,11 @@ describe("Stamp Editor", () => {
describe("Alt text dialog", () => { describe("Alt text dialog", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -500,11 +490,11 @@ describe("Stamp Editor", () => {
describe("Resize an image with the keyboard", () => { describe("Resize an image with the keyboard", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -631,12 +621,12 @@ describe("Stamp Editor", () => {
describe("Copy/paste from a tab to an other", () => { describe("Copy/paste from a tab to an other", () => {
let pages1, pages2; let pages1, pages2;
beforeAll(async () => { beforeEach(async () => {
pages1 = await loadAndWait("empty.pdf", ".annotationEditorLayer"); pages1 = await loadAndWait("empty.pdf", ".annotationEditorLayer");
pages2 = await loadAndWait("empty.pdf", ".annotationEditorLayer"); pages2 = await loadAndWait("empty.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages1); await closePages(pages1);
await closePages(pages2); await closePages(pages2);
}); });
@ -665,11 +655,11 @@ describe("Stamp Editor", () => {
describe("Undo a stamp", () => { describe("Undo a stamp", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer"); pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -697,11 +687,11 @@ describe("Stamp Editor", () => {
describe("Delete a stamp and undo it on another page", () => { describe("Delete a stamp and undo it on another page", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer"); pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -742,11 +732,11 @@ describe("Stamp Editor", () => {
describe("Delete a stamp, scroll and undo it", () => { describe("Delete a stamp, scroll and undo it", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer"); pages = await loadAndWait("tracemonkey.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -782,11 +772,11 @@ describe("Stamp Editor", () => {
describe("Resize a stamp", () => { describe("Resize a stamp", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -832,7 +822,7 @@ describe("Stamp Editor", () => {
describe("Add a stamp in odd spread mode", () => { describe("Add a stamp in odd spread mode", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait( pages = await loadAndWait(
"empty.pdf", "empty.pdf",
".annotationEditorLayer", ".annotationEditorLayer",
@ -844,7 +834,7 @@ describe("Stamp Editor", () => {
); );
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -873,11 +863,11 @@ describe("Stamp Editor", () => {
describe("Copy and paste a stamp with an alt text", () => { describe("Copy and paste a stamp with an alt text", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -918,7 +908,7 @@ describe("Stamp Editor", () => {
describe("New alt-text flow", () => { describe("New alt-text flow", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait( pages = await loadAndWait(
"empty.pdf", "empty.pdf",
".annotationEditorLayer", ".annotationEditorLayer",
@ -942,23 +932,6 @@ describe("Stamp Editor", () => {
}); });
afterEach(async () => { afterEach(async () => {
for (const [, page] of pages) {
if (await isVisible(page, "#newAltTextDialog")) {
await page.keyboard.press("Escape");
await page.waitForSelector("#newAltTextDisclaimer", {
visible: false,
});
}
await page.evaluate(() => {
window.uiManager.reset();
window.telemetry = [];
});
// Disable editing mode.
await switchToStamp(page, /* disable */ true);
}
});
afterAll(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1296,7 +1269,7 @@ describe("Stamp Editor", () => {
describe("New alt-text flow (bug 1920515)", () => { describe("New alt-text flow (bug 1920515)", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait( pages = await loadAndWait(
"empty.pdf", "empty.pdf",
".annotationEditorLayer", ".annotationEditorLayer",
@ -1318,22 +1291,6 @@ describe("Stamp Editor", () => {
}); });
afterEach(async () => { afterEach(async () => {
for (const [, page] of pages) {
if (await isVisible(page, "#newAltTextDialog")) {
await page.keyboard.press("Escape");
await page.waitForSelector("#newAltTextDisclaimer", {
visible: false,
});
}
await page.evaluate(() => {
window.uiManager.reset();
});
// Disable editing mode.
await switchToStamp(page, /* disable */ true);
}
});
afterAll(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1364,11 +1321,11 @@ describe("Stamp Editor", () => {
describe("No auto-resize", () => { describe("No auto-resize", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 67); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 67);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1410,11 +1367,11 @@ describe("Stamp Editor", () => {
describe("A stamp musn't be on top of the secondary toolbar", () => { describe("A stamp musn't be on top of the secondary toolbar", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 600); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 600);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1453,11 +1410,11 @@ describe("Stamp Editor", () => {
describe("Stamp (move existing)", () => { describe("Stamp (move existing)", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("stamps.pdf", getAnnotationSelector("25R")); pages = await loadAndWait("stamps.pdf", getAnnotationSelector("25R"));
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1491,11 +1448,11 @@ describe("Stamp Editor", () => {
describe("Stamp (change alt-text)", () => { describe("Stamp (change alt-text)", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("stamps.pdf", getAnnotationSelector("58R")); pages = await loadAndWait("stamps.pdf", getAnnotationSelector("58R"));
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1551,11 +1508,11 @@ describe("Stamp Editor", () => {
describe("Stamp (delete existing and undo)", () => { describe("Stamp (delete existing and undo)", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("stamps.pdf", getAnnotationSelector("37R")); pages = await loadAndWait("stamps.pdf", getAnnotationSelector("37R"));
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1599,11 +1556,11 @@ describe("Stamp Editor", () => {
describe("Drag a stamp annotation and click on a touchscreen", () => { describe("Drag a stamp annotation and click on a touchscreen", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer"); pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1725,11 +1682,11 @@ describe("Stamp Editor", () => {
describe("Switch to edit mode a pdf with an existing stamp annotation on an invisible and rendered page", () => { describe("Switch to edit mode a pdf with an existing stamp annotation on an invisible and rendered page", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("issue19239.pdf", ".annotationEditorLayer"); pages = await loadAndWait("issue19239.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1755,11 +1712,11 @@ describe("Stamp Editor", () => {
describe("Switch to edit mode a pdf with an existing stamp annotation on an invisible and unrendered page", () => { describe("Switch to edit mode a pdf with an existing stamp annotation on an invisible and unrendered page", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("issue19239.pdf", ".annotationEditorLayer"); pages = await loadAndWait("issue19239.pdf", ".annotationEditorLayer");
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1794,11 +1751,11 @@ describe("Stamp Editor", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("issue19239.pdf", annotationSelector); pages = await loadAndWait("issue19239.pdf", annotationSelector);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });
@ -1825,11 +1782,11 @@ describe("Stamp Editor", () => {
let pages; let pages;
beforeAll(async () => { beforeEach(async () => {
pages = await loadAndWait("red_stamp.pdf", annotationSelector, 20); pages = await loadAndWait("red_stamp.pdf", annotationSelector, 20);
}); });
afterAll(async () => { afterEach(async () => {
await closePages(pages); await closePages(pages);
}); });

View File

@ -137,13 +137,6 @@ function closePages(pages) {
return Promise.all(pages.map(([_, page]) => closeSinglePage(page))); return Promise.all(pages.map(([_, page]) => closeSinglePage(page)));
} }
function isVisible(page, selector) {
return page.evaluate(
sel => document.querySelector(sel)?.checkVisibility(),
selector
);
}
async function closeSinglePage(page) { async function closeSinglePage(page) {
// Avoid to keep something from a previous test. // Avoid to keep something from a previous test.
await page.evaluate(async () => { await page.evaluate(async () => {
@ -861,16 +854,6 @@ function isCanvasMonochrome(page, pageNumber, rectangle, color) {
); );
} }
async function cleanupEditing(pages, switcher) {
for (const [, page] of pages) {
await page.evaluate(() => {
window.uiManager.reset();
});
// Disable editing mode.
await switcher(page, /* disable */ true);
}
}
async function getXY(page, selector) { async function getXY(page, selector) {
const rect = await getRect(page, selector); const rect = await getRect(page, selector);
return `${rect.x}::${rect.y}`; return `${rect.x}::${rect.y}`;
@ -902,7 +885,6 @@ async function moveEditor(page, selector, n, pressKey) {
export { export {
applyFunctionToEditor, applyFunctionToEditor,
awaitPromise, awaitPromise,
cleanupEditing,
clearEditors, clearEditors,
clearInput, clearInput,
closePages, closePages,
@ -927,7 +909,6 @@ export {
getXY, getXY,
hover, hover,
isCanvasMonochrome, isCanvasMonochrome,
isVisible,
kbBigMoveDown, kbBigMoveDown,
kbBigMoveLeft, kbBigMoveLeft,
kbBigMoveRight, kbBigMoveRight,