Skip to content

Commit

Permalink
Fix 'must load a SVG, delete it and undo' integration test
Browse files Browse the repository at this point in the history
We wait for the canvas before trying to serialize the annotation in order to make sure the image has been loaded.
  • Loading branch information
calixteman committed Nov 18, 2024
1 parent f406119 commit eefaca0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions test/integration/stamp_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ describe("Stamp Editor", () => {
);
const editorSelector = getEditorSelector(0);
await waitForImage(page, editorSelector);

await waitForSerialized(page, 1);

await page.waitForSelector(`${editorSelector} button.delete`);
await page.click(`${editorSelector} button.delete`);

await waitForSerialized(page, 0);

await kbUndo(page);
await waitForImage(page, editorSelector);
await waitForSerialized(page, 1);

await waitForSelectedEditor(page, editorSelector);
Expand Down Expand Up @@ -654,8 +654,8 @@ describe("Stamp Editor", () => {
await waitForSerialized(page, 0);

await kbUndo(page);
await waitForImage(page, selector);
await waitForSerialized(page, 1);
await page.waitForSelector(`${selector} canvas`);
}
});
});
Expand Down Expand Up @@ -739,8 +739,8 @@ describe("Stamp Editor", () => {
}

await kbUndo(page);
await waitForImage(page, selector);
await waitForSerialized(page, 1);
await page.waitForSelector(`${selector} canvas`);
}
});
});
Expand Down
15 changes: 12 additions & 3 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,18 @@ async function waitForStorageEntries(page, nEntries) {

async function waitForSerialized(page, nEntries) {
return page.waitForFunction(
n =>
(window.PDFViewerApplication.pdfDocument.annotationStorage.serializable
.map?.size ?? 0) === n,
n => {
try {
return (
(window.PDFViewerApplication.pdfDocument.annotationStorage
.serializable.map?.size ?? 0) === n
);
} catch {
// When serializing a stamp annotation with a SVG, the transfer
// can fail because of the SVG, so we just retry.
return false;
}
},
{},
nEntries
);
Expand Down

0 comments on commit eefaca0

Please sign in to comment.