Use the waitForTextToBe helper function in the editor undo bar integration tests

This reduces the amount of code needed for the checks, and thereby makes
the intent of the assertions clearer.

Note that, thanks to the FSI/PDI constants, we can now also compare the
strings directly instead of having to do a manual replacement for the
case where more than one annotation is removed.
This commit is contained in:
Tim van der Meij
2026-09-13 13:55:40 +02:00
parent c0a774ee67
commit 6a53a8d3ee
5 changed files with 25 additions and 80 deletions
+5 -14
View File
@@ -34,6 +34,7 @@ import {
waitAndClick,
waitForBrowserTrip,
waitForSerialized,
waitForTextToBe,
waitForTimeout,
waitForTooltipToBe,
} from "./test_utils.mjs";
@@ -1056,21 +1057,11 @@ describe("Comment", () => {
await page.waitForSelector("#commentPopup", { visible: true });
await waitAndClick(page, "button.commentPopupDelete");
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(
el => el.textContent,
message
await waitForTextToBe(
page,
"#editorUndoBarMessage",
"Comment removed"
);
expect(messageText)
.withContext(`In ${browserName}`)
.toContain("Comment removed");
})
);
});
+2 -13
View File
@@ -59,6 +59,7 @@ import {
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTextToBe,
waitForTimeout,
waitForUnselectedEditor,
} from "./test_utils.mjs";
@@ -3470,19 +3471,7 @@ describe("FreeText Editor", () => {
await page.waitForSelector(`${editorSelector} button.deleteButton`);
await page.click(`${editorSelector} button.deleteButton`);
await waitForSerialized(page, 0);
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(
el => el.textContent,
message
);
expect(messageText).toContain("Text removed");
await waitForTextToBe(page, "#editorUndoBarMessage", "Text removed");
})
);
});
+11 -31
View File
@@ -16,6 +16,7 @@
import {
awaitPromise,
closePages,
FSI,
getAnnotationSelector,
getEditorSelector,
getFirstSerialized,
@@ -31,6 +32,7 @@ import {
kbSave,
kbUndo,
loadAndWait,
PDI,
scrollIntoView,
selectEditor,
selectEditors,
@@ -42,6 +44,7 @@ import {
waitForPointerUp,
waitForSelectedEditor,
waitForSerialized,
waitForTextToBe,
waitForTimeout,
} from "./test_utils.mjs";
import fs from "fs";
@@ -2401,20 +2404,11 @@ describe("Highlight Editor", () => {
await page.waitForSelector(`${editorSelector} button.deleteButton`);
await page.click(`${editorSelector} button.deleteButton`);
await waitForSerialized(page, 0);
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(
el => el.textContent,
message
await waitForTextToBe(
page,
"#editorUndoBarMessage",
"Highlight removed"
);
expect(messageText).toContain("Highlight removed");
})
);
});
@@ -2431,25 +2425,11 @@ describe("Highlight Editor", () => {
await page.waitForSelector(`${editorSelector} button.deleteButton`);
await page.click(`${editorSelector} button.deleteButton`);
await waitForSerialized(page, 0);
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(
el => el.textContent,
message
await waitForTextToBe(
page,
"#editorUndoBarMessage",
`${FSI}2${PDI} annotations removed`
);
// Cleans the message text by removing all non-ASCII characters.
// It eliminates any invisible characters such as directional marks
// that interfere with string comparisons
const cleanMessage = messageText.replaceAll(/\P{ASCII}/gu, "");
expect(cleanMessage).toContain(`2 annotations removed`);
})
);
});
+5 -12
View File
@@ -44,6 +44,7 @@ import {
waitForSelectedEditor,
waitForSerialized,
waitForStorageEntries,
waitForTextToBe,
waitForTimeout,
} from "./test_utils.mjs";
import { AnnotationEditorType } from "../../src/shared/util.js";
@@ -889,19 +890,11 @@ describe("Ink Editor", () => {
await page.waitForSelector(`${editorSelector} button.deleteButton`);
await page.click(`${editorSelector} button.deleteButton`);
await waitForSerialized(page, 0);
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(
el => el.textContent,
message
await waitForTextToBe(
page,
"#editorUndoBarMessage",
"Drawing removed"
);
expect(messageText).toContain("Drawing removed");
})
);
});
+2 -10
View File
@@ -49,6 +49,7 @@ import {
waitForPageRendered,
waitForSelectedEditor,
waitForSerialized,
waitForTextToBe,
waitForTimeout,
} from "./test_utils.mjs";
import fs from "fs";
@@ -1644,16 +1645,7 @@ describe("Stamp Editor", () => {
await page.waitForSelector(`${editorSelector} button.deleteButton`);
await page.click(`${editorSelector} button.deleteButton`);
await waitForSerialized(page, 0);
await page.waitForFunction(() => {
const messageElement = document.querySelector(
"#editorUndoBarMessage"
);
return messageElement && messageElement.textContent.trim() !== "";
});
const message = await page.waitForSelector("#editorUndoBarMessage");
const messageText = await page.evaluate(el => el.textContent, message);
expect(messageText).toContain("Image removed");
await waitForTextToBe(page, "#editorUndoBarMessage", "Image removed");
}
});