Skip to content

Isolate the "basic operations" freetext editor integration tests #19743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 50 additions & 21 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ describe("FreeText Editor", () => {
describe("FreeText", () => {
let pages;

beforeAll(async () => {
beforeEach(async () => {
pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
});

afterAll(async () => {
afterEach(async () => {
await closePages(pages);
});

Expand Down Expand Up @@ -134,7 +134,17 @@ describe("FreeText Editor", () => {
it("must copy/paste", async () => {
// Run sequentially to avoid clipboard issues.
for (const [browserName, page] of pages) {
await switchToFreeText(page);

const rect = await getRect(page, ".annotationEditorLayer");
const firstEditorSelector = getEditorSelector(0);
const data = "Hello PDF.js World !!";
await page.mouse.click(rect.x + 100, rect.y + 100);
await page.waitForSelector(firstEditorSelector, { visible: true });
await page.type(`${firstEditorSelector} .internal`, data);
await commit(page);
await waitForStorageEntries(page, 1);

await selectEditor(page, firstEditorSelector);
await copy(page);
await paste(page);
Expand Down Expand Up @@ -168,27 +178,46 @@ describe("FreeText Editor", () => {
it("must clear all", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToFreeText(page);

const rect = await getRect(page, ".annotationEditorLayer");
for (const n of [0, 1, 2]) {
const editorSelector = getEditorSelector(n);
const data = "Hello PDF.js World !!";
await page.mouse.click(rect.x + 100 * n, rect.y + 100 * n);
await page.waitForSelector(editorSelector, { visible: true });
await page.type(`${editorSelector} .internal`, data);
await commit(page);

const hasEditor = await page.evaluate(
sel => !!document.querySelector(sel),
editorSelector
);
expect(hasEditor).withContext(`In ${browserName}`).toEqual(true);
}

await waitForStorageEntries(page, 3);
await clearAll(page);
await waitForStorageEntries(page, 0);

for (const n of [0, 1, 2]) {
const hasEditor = await page.evaluate(
sel => !!document.querySelector(sel),
getEditorSelector(n)
);

expect(hasEditor).withContext(`In ${browserName}`).toEqual(false);
}

await waitForStorageEntries(page, 0);
})
);
});

it("must check that a paste has been undone", async () => {
// Run sequentially to avoid clipboard issues.
for (const [, page] of pages) {
await switchToFreeText(page);

const rect = await getRect(page, ".annotationEditorLayer");
let editorSelector = getEditorSelector(3);
let editorSelector = getEditorSelector(0);
const data = "Hello PDF.js World !!";
await page.mouse.click(rect.x + 100, rect.y + 100);
await page.waitForSelector(editorSelector, { visible: true });
Expand All @@ -198,7 +227,7 @@ describe("FreeText Editor", () => {
await selectEditor(page, editorSelector);
await copy(page);
await paste(page);
editorSelector = getEditorSelector(4);
editorSelector = getEditorSelector(1);
await page.waitForSelector(editorSelector, { visible: true });

await kbUndo(page);
Expand All @@ -210,15 +239,15 @@ describe("FreeText Editor", () => {

for (let i = 0; i < 2; i++) {
await paste(page);
await page.waitForSelector(getEditorSelector(5 + i));
await page.waitForSelector(getEditorSelector(2 + i));
}

for (let i = 0; i < 2; i++) {
await kbUndo(page);
await page.waitForFunction(
sel => !document.querySelector(sel),
{},
getEditorSelector(6 - i)
getEditorSelector(3 - i)
);
}
}
Expand All @@ -227,6 +256,8 @@ describe("FreeText Editor", () => {
it("must check that aria-owns is correct", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToFreeText(page);

await page.$eval(".textLayer", el => {
for (const span of el.querySelectorAll(
`span[role="presentation"]`
Expand All @@ -246,7 +277,7 @@ describe("FreeText Editor", () => {

expect(oldAriaOwns).withContext(`In ${browserName}`).toEqual(null);

const editorSelector = getEditorSelector(7);
const editorSelector = getEditorSelector(0);
const data = "Hello PDF.js World !!";
await page.mouse.click(
stacksRect.x + stacksRect.width + 1,
Expand All @@ -261,7 +292,7 @@ describe("FreeText Editor", () => {
return span?.getAttribute("aria-owns") || null;
});

expect(ariaOwns.endsWith("_7-editor"))
expect(ariaOwns.endsWith("_0-editor"))
.withContext(`In ${browserName}`)
.toEqual(true);
await scrollIntoView(page, ".annotationEditorLayer");
Expand All @@ -272,11 +303,10 @@ describe("FreeText Editor", () => {
it("must check that right click doesn't select", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const rect = await getRect(page, ".annotationEditorLayer");

await clearAll(page);
await switchToFreeText(page);

const editorSelector = getEditorSelector(8);
const rect = await getRect(page, ".annotationEditorLayer");
const editorSelector = getEditorSelector(0);
const data = "Hello PDF.js World !!";
await page.mouse.click(rect.x + 100, rect.y + 100);
await page.waitForSelector(editorSelector, { visible: true });
Expand All @@ -285,7 +315,7 @@ describe("FreeText Editor", () => {

expect(await getEditors(page, "selected"))
.withContext(`In ${browserName}`)
.toEqual([8]);
.toEqual([0]);

await page.keyboard.press("Escape");
await page.waitForFunction(
Expand All @@ -295,7 +325,7 @@ describe("FreeText Editor", () => {
await selectEditor(page, editorSelector);
expect(await getEditors(page, "selected"))
.withContext(`In ${browserName}`)
.toEqual([8]);
.toEqual([0]);

// Escape.
await page.keyboard.press("Escape");
Expand All @@ -317,11 +347,10 @@ describe("FreeText Editor", () => {
it("must check that text change can be undone/redone", async () => {
// Run sequentially to avoid clipboard issues.
for (const [browserName, page] of pages) {
const rect = await getRect(page, ".annotationEditorLayer");

await clearAll(page);
await switchToFreeText(page);

const editorSelector = getEditorSelector(9);
const rect = await getRect(page, ".annotationEditorLayer");
const editorSelector = getEditorSelector(0);
await page.mouse.click(rect.x + 200, rect.y + 100);
await page.waitForSelector(editorSelector, { visible: true });

Expand Down