Skip to content

Commit ed08a6a

Browse files
committed
Isolate the "basic operations" freetext editor integration tests
This commit reduces the number of freetext editor integration test suite failures, in full isolation, from 5 to 0 by fixing the following issues in the "basic operations" block: - Most tests relied on the first test to enable freetext editing mode. For isolation we now do it explicitly in all tests. - Most tests relied on the other tests having created editors. For isolation we now create the editors explicitly in the tests themselves. - Most tests relied on previous tests for the editor numbering. For isolation we change the editor numbering to the one after initial document load. Since we can't have state (editors) from a previous test anymore we can remove various `clearAll` calls as well.
1 parent f32254d commit ed08a6a

1 file changed

Lines changed: 50 additions & 21 deletions

File tree

test/integration/freetext_editor_spec.mjs

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ describe("FreeText Editor", () => {
8787
describe("FreeText", () => {
8888
let pages;
8989

90-
beforeAll(async () => {
90+
beforeEach(async () => {
9191
pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
9292
});
9393

94-
afterAll(async () => {
94+
afterEach(async () => {
9595
await closePages(pages);
9696
});
9797

@@ -134,7 +134,17 @@ describe("FreeText Editor", () => {
134134
it("must copy/paste", async () => {
135135
// Run sequentially to avoid clipboard issues.
136136
for (const [browserName, page] of pages) {
137+
await switchToFreeText(page);
138+
139+
const rect = await getRect(page, ".annotationEditorLayer");
137140
const firstEditorSelector = getEditorSelector(0);
141+
const data = "Hello PDF.js World !!";
142+
await page.mouse.click(rect.x + 100, rect.y + 100);
143+
await page.waitForSelector(firstEditorSelector, { visible: true });
144+
await page.type(`${firstEditorSelector} .internal`, data);
145+
await commit(page);
146+
await waitForStorageEntries(page, 1);
147+
138148
await selectEditor(page, firstEditorSelector);
139149
await copy(page);
140150
await paste(page);
@@ -168,27 +178,46 @@ describe("FreeText Editor", () => {
168178
it("must clear all", async () => {
169179
await Promise.all(
170180
pages.map(async ([browserName, page]) => {
181+
await switchToFreeText(page);
182+
183+
const rect = await getRect(page, ".annotationEditorLayer");
184+
for (const n of [0, 1, 2]) {
185+
const editorSelector = getEditorSelector(n);
186+
const data = "Hello PDF.js World !!";
187+
await page.mouse.click(rect.x + 100 * n, rect.y + 100 * n);
188+
await page.waitForSelector(editorSelector, { visible: true });
189+
await page.type(`${editorSelector} .internal`, data);
190+
await commit(page);
191+
192+
const hasEditor = await page.evaluate(
193+
sel => !!document.querySelector(sel),
194+
editorSelector
195+
);
196+
expect(hasEditor).withContext(`In ${browserName}`).toEqual(true);
197+
}
198+
199+
await waitForStorageEntries(page, 3);
171200
await clearAll(page);
201+
await waitForStorageEntries(page, 0);
172202

173203
for (const n of [0, 1, 2]) {
174204
const hasEditor = await page.evaluate(
175205
sel => !!document.querySelector(sel),
176206
getEditorSelector(n)
177207
);
178-
179208
expect(hasEditor).withContext(`In ${browserName}`).toEqual(false);
180209
}
181-
182-
await waitForStorageEntries(page, 0);
183210
})
184211
);
185212
});
186213

187214
it("must check that a paste has been undone", async () => {
188215
// Run sequentially to avoid clipboard issues.
189216
for (const [, page] of pages) {
217+
await switchToFreeText(page);
218+
190219
const rect = await getRect(page, ".annotationEditorLayer");
191-
let editorSelector = getEditorSelector(3);
220+
let editorSelector = getEditorSelector(0);
192221
const data = "Hello PDF.js World !!";
193222
await page.mouse.click(rect.x + 100, rect.y + 100);
194223
await page.waitForSelector(editorSelector, { visible: true });
@@ -198,7 +227,7 @@ describe("FreeText Editor", () => {
198227
await selectEditor(page, editorSelector);
199228
await copy(page);
200229
await paste(page);
201-
editorSelector = getEditorSelector(4);
230+
editorSelector = getEditorSelector(1);
202231
await page.waitForSelector(editorSelector, { visible: true });
203232

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

211240
for (let i = 0; i < 2; i++) {
212241
await paste(page);
213-
await page.waitForSelector(getEditorSelector(5 + i));
242+
await page.waitForSelector(getEditorSelector(2 + i));
214243
}
215244

216245
for (let i = 0; i < 2; i++) {
217246
await kbUndo(page);
218247
await page.waitForFunction(
219248
sel => !document.querySelector(sel),
220249
{},
221-
getEditorSelector(6 - i)
250+
getEditorSelector(3 - i)
222251
);
223252
}
224253
}
@@ -227,6 +256,8 @@ describe("FreeText Editor", () => {
227256
it("must check that aria-owns is correct", async () => {
228257
await Promise.all(
229258
pages.map(async ([browserName, page]) => {
259+
await switchToFreeText(page);
260+
230261
await page.$eval(".textLayer", el => {
231262
for (const span of el.querySelectorAll(
232263
`span[role="presentation"]`
@@ -246,7 +277,7 @@ describe("FreeText Editor", () => {
246277

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

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

264-
expect(ariaOwns.endsWith("_7-editor"))
295+
expect(ariaOwns.endsWith("_0-editor"))
265296
.withContext(`In ${browserName}`)
266297
.toEqual(true);
267298
await scrollIntoView(page, ".annotationEditorLayer");
@@ -272,11 +303,10 @@ describe("FreeText Editor", () => {
272303
it("must check that right click doesn't select", async () => {
273304
await Promise.all(
274305
pages.map(async ([browserName, page]) => {
275-
const rect = await getRect(page, ".annotationEditorLayer");
276-
277-
await clearAll(page);
306+
await switchToFreeText(page);
278307

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

286316
expect(await getEditors(page, "selected"))
287317
.withContext(`In ${browserName}`)
288-
.toEqual([8]);
318+
.toEqual([0]);
289319

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

300330
// Escape.
301331
await page.keyboard.press("Escape");
@@ -317,11 +347,10 @@ describe("FreeText Editor", () => {
317347
it("must check that text change can be undone/redone", async () => {
318348
// Run sequentially to avoid clipboard issues.
319349
for (const [browserName, page] of pages) {
320-
const rect = await getRect(page, ".annotationEditorLayer");
321-
322-
await clearAll(page);
350+
await switchToFreeText(page);
323351

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

0 commit comments

Comments
 (0)