mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-10-18 07:55:48 +02:00
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:
@@ -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");
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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`);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user