From 350e3e7b1c6f539069a8df0e57fdc261d6620676 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 5 Sep 2024 15:31:49 +0200 Subject: [PATCH] [Editor] Avoid to throw when an highlight annotation is resetted --- src/display/editor/editor.js | 2 +- test/integration/highlight_editor_spec.mjs | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js index bab0e62c85f3d..a3006975df87f 100644 --- a/src/display/editor/editor.js +++ b/src/display/editor/editor.js @@ -1796,7 +1796,7 @@ class AnnotationEditor { resetAnnotationElement(annotation) { const { firstChild } = annotation.container; if ( - firstChild.nodeName === "DIV" && + firstChild?.nodeName === "DIV" && firstChild.classList.contains("annotationContent") ) { firstChild.remove(); diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index e4fc2eee4d89f..31379b6c89fa5 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -2020,4 +2020,37 @@ describe("Highlight Editor", () => { ); }); }); + + describe("Highlight editor mustn't throw when disabled", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait( + "annotation-highlight.pdf", + ".annotationEditorLayer" + ); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must enable & disable highlight mode successfully", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + const modeChangedHandle = await waitForAnnotationModeChanged(page); + await switchToHighlight(page); + await awaitPromise(modeChangedHandle); + + await page.waitForSelector("#highlightParamsToolbarContainer", { + visible: true, + }); + await switchToHighlight(page, /* disable */ true); + await page.waitForSelector("#highlightParamsToolbarContainer", { + visible: false, + }); + }) + ); + }); + }); });