Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Fix flaky e2e tests (#8080)

James Bruntone466d199f7bb
diff --git a/frontend/editor/src/core/tests/helpers/ui-helpers.ts b/frontend/editor/src/core/tests/helpers/ui-helpers.ts
index ba3f8a963d..1a8583b168 100644
--- a/frontend/editor/src/core/tests/helpers/ui-helpers.ts
+++ b/frontend/editor/src/core/tests/helpers/ui-helpers.ts
@@ -134,7 +134,9 @@ async function waitForStoredFiles(page: Page, names: string[]): Promise<void> {
open.onblocked = () => resolve(false);
}),
names,
- { timeout: 10_000, polling: 100 },
+ // The IndexedDB write can lag the upload on WebKit under parallel CI load;
+ // it lands, just not always within 10s, so give the commit room to finish.
+ { timeout: 30_000, polling: 100 },
);
}
diff --git a/frontend/editor/src/core/tests/stubbed/classification-heuristic-upload.spec.ts b/frontend/editor/src/core/tests/stubbed/classification-heuristic-upload.spec.ts
index 30a9cd0353..bb4e3cc000 100644
--- a/frontend/editor/src/core/tests/stubbed/classification-heuristic-upload.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/classification-heuristic-upload.spec.ts
@@ -75,18 +75,26 @@ test("a 10-file upload wave classifies every file into its group", async ({
].map((f) => path.join(FIXTURES, f)),
);
- // Each group header is a collapsible button whose name carries the member count.
- // Classification runs a few files per idle pass; wait for the full drain.
+ // Group headers are collapsible buttons whose name carries the live member
+ // count. Classification drains a few files per idle pass, and until a file's
+ // verdict lands it is unclassified and counted under Other (see
+ // fileSidebarGroupingLogic). Every count therefore climbs to a final value, so
+ // the assertions must read the settled state, not a mid-drain snapshot.
const header = (name: string, count: number) =>
page.getByRole("button", { name: `${name} ${count}`, exact: true });
- await expect(header("Financial", 3)).toBeVisible({ timeout: 90_000 });
- await expect(header("HR", 3)).toBeVisible({ timeout: 30_000 });
- await expect(header("Legal", 2)).toBeVisible({ timeout: 30_000 });
- // The regression: nothing classifiable may be stranded in Other - only the
- // genuinely unlabellable pair (generic prose + non-English) belongs there.
- await expect(header("Other", 2)).toBeVisible({ timeout: 30_000 });
- // The filename can render in several places (Recent, group, viewer); any hit proves presence.
+ // Other falls to its one terminal member (generic_notes.pdf) only after every
+ // other file has classified out of it: the drain-complete signal to wait on.
+ await expect(header("Other", 1)).toBeVisible({ timeout: 150_000 });
+
+ // Settled distribution. spanish_contrato.pdf is a Spanish lease agreement the
+ // Spanish rules label as Legal, so nothing classifiable is stranded in Other -
+ // only genuinely unlabellable generic prose belongs there.
+ await expect(header("Financial", 3)).toBeVisible();
+ await expect(header("HR", 3)).toBeVisible();
+ await expect(header("Legal", 3)).toBeVisible();
+
+ // A filename can render in Recent, its group, or the viewer; any hit proves presence.
await expect(page.getByText("generic_notes.pdf").first()).toBeVisible();
await expect(page.getByText("spanish_contrato.pdf").first()).toBeVisible();
});
diff --git a/frontend/editor/src/core/tests/stubbed/encrypted-pdf-unlock.spec.ts b/frontend/editor/src/core/tests/stubbed/encrypted-pdf-unlock.spec.ts
index 430f5e4f24..c2844bba29 100644
--- a/frontend/editor/src/core/tests/stubbed/encrypted-pdf-unlock.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/encrypted-pdf-unlock.spec.ts
@@ -75,6 +75,21 @@ const MODAL_TITLE = "Remove password to continue";
const PASSWORD_PLACEHOLDER = "Enter the PDF password";
const UNLOCK_BUTTON_TEXT = "Unlock & Continue";
+/**
+ * Fill the password field and wait until the modal has registered it: the
+ * unlock button is disabled while the password is empty, so its becoming enabled
+ * proves the value landed in state. Retried because on WebKit the modal can
+ * remount mid open-transition and drop a one-shot fill, leaving it disabled.
+ */
+async function fillPassword(page: Page, password: string): Promise<void> {
+ const field = page.getByPlaceholder(PASSWORD_PLACEHOLDER);
+ const unlock = page.getByRole("button", { name: UNLOCK_BUTTON_TEXT });
+ await expect(async () => {
+ await field.fill(password);
+ await expect(unlock).toBeEnabled({ timeout: 1_000 });
+ }).toPass({ timeout: 15_000 });
+}
+
test.describe.configure({ mode: "serial" });
test.describe("Encrypted PDF Unlock Modal", () => {
@@ -114,7 +129,7 @@ test.describe("Encrypted PDF Unlock Modal", () => {
await uploadEncryptedFile(page, ENCRYPTED_PDF);
await expect(page.getByText(MODAL_TITLE)).toBeVisible({ timeout: 10000 });
- await page.getByPlaceholder(PASSWORD_PLACEHOLDER).fill("testpass123");
+ await fillPassword(page, "testpass123");
await page.getByRole("button", { name: UNLOCK_BUTTON_TEXT }).click();
await expect(page.getByText(MODAL_TITLE)).toBeHidden({ timeout: 10000 });
@@ -131,7 +146,7 @@ test.describe("Encrypted PDF Unlock Modal", () => {
await uploadEncryptedFile(page, ENCRYPTED_PDF);
await expect(page.getByText(MODAL_TITLE)).toBeVisible({ timeout: 10000 });
- await page.getByPlaceholder(PASSWORD_PLACEHOLDER).fill("wrongpassword");
+ await fillPassword(page, "wrongpassword");
await page.getByRole("button", { name: UNLOCK_BUTTON_TEXT }).click();
await expect(page.getByText("Incorrect password")).toBeVisible({
@@ -148,9 +163,8 @@ test.describe("Encrypted PDF Unlock Modal", () => {
await uploadEncryptedFile(page, ENCRYPTED_PDF);
await expect(page.getByText(MODAL_TITLE)).toBeVisible({ timeout: 10000 });
- const passwordInput = page.getByPlaceholder(PASSWORD_PLACEHOLDER);
- await passwordInput.fill("testpass123");
- await passwordInput.press("Enter");
+ await fillPassword(page, "testpass123");
+ await page.getByPlaceholder(PASSWORD_PLACEHOLDER).press("Enter");
await expect(page.getByText(MODAL_TITLE)).toBeHidden({ timeout: 10000 });
});
@@ -185,7 +199,7 @@ test.describe("Encrypted PDF Unlock Modal", () => {
const unlockAllBtn = page.getByRole("button", { name: /Use for all/ });
await expect(unlockAllBtn).toBeVisible({ timeout: 20000 });
- await page.getByPlaceholder(PASSWORD_PLACEHOLDER).fill("testpass123");
+ await fillPassword(page, "testpass123");
await unlockAllBtn.click();
await expect(page.getByText(MODAL_TITLE)).toBeHidden({ timeout: 15000 });
diff --git a/frontend/editor/src/core/tests/stubbed/files-page.spec.ts b/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
index 67a874e7b3..25a5e352ec 100644
--- a/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/files-page.spec.ts
@@ -1038,13 +1038,18 @@ test.describe("Files page", () => {
const topOf = async () =>
(await rows.first().boundingBox())?.y ?? Number.NaN;
+ // boundingBox() can be null for a beat after the row is "visible" (WebKit
+ // layout timing), so wait for a real y before capturing the baseline.
+ await expect
+ .poll(async () => Number.isFinite(await topOf()), { timeout: 15_000 })
+ .toBe(true);
const before = await topOf();
await rows.nth(0).click();
await rows.nth(1).click({ modifiers: ["ControlOrMeta"] });
await expect(page.locator(".files-page-list-selection-count")).toHaveText(
/2 selected/i,
);
- expect(await topOf()).toBeCloseTo(before, 0);
+ await expect.poll(topOf, { timeout: 15_000 }).toBeCloseTo(before, 0);
});
});
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-newline-register.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-newline-register.spec.ts
index 4fe2b3a628..ff9ea0ce33 100644
--- a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-newline-register.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-newline-register.spec.ts
@@ -120,13 +120,16 @@ test.describe("PDF text editor - the overlay stays in register with the page", (
await page.keyboard.type(LONG_LINE, { delay: 12 });
await page.waitForTimeout(1500);
+ // The overlay paints a frame or two after the keystrokes settle (WebKit under
+ // load is the slow case). Poll for the painted blocks before reading the run:
+ // with no blocks the row assertion below is vacuous.
+ await expect
+ .poll(async () => (await register(page, runId))?.blocks ?? 0, {
+ timeout: 15_000,
+ })
+ .toBeGreaterThan(1);
const reg = await register(page, runId);
expect(reg, "run vanished").not.toBeNull();
- // Guard: with no painted blocks the row assertion below is vacuous.
- expect(
- reg!.blocks,
- "the run should be painted as line blocks, not plain text",
- ).toBeGreaterThan(1);
expect(
reg!.blockWhiteSpace.every((w) => w === "pre"),
`a painted block was allowed to wrap: ${reg!.blockWhiteSpace.join(", ")}`,
@@ -153,9 +156,15 @@ test.describe("PDF text editor - the overlay stays in register with the page", (
await page.keyboard.type(LONG_LINE, { delay: 12 });
await page.waitForTimeout(1500);
+ // The overlay paints a frame or two after the keystrokes settle, so poll for
+ // the painted blocks before reading the run.
+ await expect
+ .poll(async () => (await register(page, runId))?.blocks ?? 0, {
+ timeout: 15_000,
+ })
+ .toBeGreaterThan(1);
const reg = await register(page, runId);
expect(reg).not.toBeNull();
- expect(reg!.blocks).toBeGreaterThan(1);
// The register invariant: the page draws one row per model line, so the
// overlay must show exactly that many. A block that wrapped added a row the
// page has no counterpart for, and everything below it lost alignment.
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-paragraphs.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-paragraphs.spec.ts
index 3be508fdd8..8d9bbdcdc3 100644
--- a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-paragraphs.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-paragraphs.spec.ts
@@ -200,13 +200,22 @@ test.describe("PDF text editor - paragraph editing battery", () => {
" ZZZZ YYYY XXXX WWWW VVVV UUUU TTTT SSSS RRRR QQQQ PPPP OOOO",
);
await blurRun(page, id);
+ // The reflow lands a variable number of frames after blur (WebKit under load
+ // is the slow case), so poll until the glyphs are back on the page rather
+ // than reading them one-shot mid-reflow.
+ await expect
+ .poll(
+ async () => {
+ const g = await readGlyphs(page, id);
+ return g
+ ? Math.max(...g.glyphs.map((x) => x.right)) - g.pageWidth
+ : Number.POSITIVE_INFINITY;
+ },
+ { timeout: 15_000 },
+ )
+ .toBeLessThanOrEqual(0);
const info = await readGlyphs(page, id);
if (!info) throw new Error("vanished");
- const maxRight = Math.max(...info.glyphs.map((g) => g.right));
- expect(
- maxRight,
- `text ran off the page (maxRight=${maxRight}, pageWidth=${info.pageWidth})`,
- ).toBeLessThanOrEqual(info.pageWidth);
expect(lineCount(info)).toBeGreaterThan(1);
});
@@ -225,24 +234,28 @@ test.describe("PDF text editor - paragraph editing battery", () => {
" ZZZZ YYYY XXXX WWWW VVVV UUUU TTTT SSSS RRRR QQQQ PPPP OOOO",
);
// NO blur - the box the user SEES while editing must stay within the page.
- await page.waitForTimeout(120);
- const box = await page.evaluate((rid: string) => {
- const el = document.querySelector<HTMLElement>(
- `[data-testid="pdf-editor-run-${rid}"]`,
- );
- const pageEl = document.querySelector<HTMLElement>(
- '[data-testid="pdf-editor-page-1"]',
- );
- if (!el || !pageEl) return null;
- const er = el.getBoundingClientRect();
- const pr = pageEl.getBoundingClientRect();
- return { elRight: er.right, pageRight: pr.right };
- }, id);
- expect(box, "elements missing").not.toBeNull();
- expect(
- box!.elRight,
- `editing box overflowed the page while typing (boxRight=${box!.elRight}, pageRight=${box!.pageRight})`,
- ).toBeLessThanOrEqual(box!.pageRight + 4);
+ // WebKit can apply the live reflow a few frames after the keystrokes land, so
+ // poll the visible box until it settles inside the page instead of reading it
+ // one-shot after a fixed wait.
+ await expect
+ .poll(
+ async () =>
+ page.evaluate((rid: string) => {
+ const el = document.querySelector<HTMLElement>(
+ `[data-testid="pdf-editor-run-${rid}"]`,
+ );
+ const pageEl = document.querySelector<HTMLElement>(
+ '[data-testid="pdf-editor-page-1"]',
+ );
+ if (!el || !pageEl) return Number.POSITIVE_INFINITY;
+ return (
+ el.getBoundingClientRect().right -
+ pageEl.getBoundingClientRect().right
+ );
+ }, id),
+ { timeout: 15_000 },
+ )
+ .toBeLessThanOrEqual(4);
// After click-off the baked glyphs stay on the page too.
await blurRun(page, id);
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-width-modes.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-width-modes.spec.ts
index 5135404b31..744cfc6aae 100644
--- a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-width-modes.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-width-modes.spec.ts
@@ -280,14 +280,21 @@ for (const which of ["single", "paragraph"] as const) {
expect(before).not.toBeNull();
await caretToEndAndType(page, testId, textFor(which));
+
+ // The overflow goes onto new lines AS THE USER TYPES (no blur), but WebKit
+ // can apply the reflow a few frames after the keystrokes land, so poll the
+ // box until it has settled back to its locked width rather than reading it
+ // one-shot mid-reflow.
+ await expect
+ .poll(
+ async () =>
+ (await shapeOf(page, testId, runId))?.boxW ??
+ Number.POSITIVE_INFINITY,
+ { timeout: 15_000 },
+ )
+ .toBeLessThan(before!.boxW + 12);
const typed = await shapeOf(page, testId, runId);
expect(typed).not.toBeNull();
-
- expect(
- typed!.boxW,
- `Wrap widened the box ${before!.boxW} -> ${typed!.boxW}; the hint says boxes keep their width`,
- ).toBeLessThan(before!.boxW + 12);
- // The headline fix: the overflow goes onto new lines AS THE USER TYPES.
// It used to wait for blur, so the text sat invisible past the box edge
// and the caret only dropped onto the new line once they clicked away.
expect(
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-wrap.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-wrap.spec.ts
index 6ad5880ed0..751f4ab9bb 100644
--- a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-wrap.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-wrap.spec.ts
@@ -122,7 +122,29 @@ async function blurRun(page: import("@playwright/test").Page, testId: string) {
await page.evaluate((id) => {
document.querySelector<HTMLDivElement>(`[data-testid="${id}"]`)?.blur();
}, testId);
- await page.waitForTimeout(2500);
+}
+
+/**
+ * The blur-triggered reflow updates the run's bounds a variable number of frames
+ * later (WebKit under load is the slow case), so poll the model until the width
+ * has settled at or below `maxWidth`, then return the settled shape. A one-shot
+ * read races the reflow and reads the still-grown box.
+ */
+async function readRunAfterReflow(
+ page: import("@playwright/test").Page,
+ runId: string,
+ maxWidth: number,
+): Promise<RunShape> {
+ await expect
+ .poll(
+ async () =>
+ (await readRun(page, runId))?.width ?? Number.POSITIVE_INFINITY,
+ { timeout: 15_000 },
+ )
+ .toBeLessThan(maxWidth);
+ const run = await readRun(page, runId);
+ expect(run).not.toBeNull();
+ return run!;
}
test.describe("PDF text editor - text wrap", () => {
@@ -146,16 +168,11 @@ test.describe("PDF text editor - text wrap", () => {
await typeAtEnd(page, testId, LONG_TEXT);
await blurRun(page, testId);
- const after = await readRun(page, runId);
- expect(after).not.toBeNull();
// The whole point of wrapping: the box keeps the width it was locked to
// and the overflow goes onto new lines.
+ const after = await readRunAfterReflow(page, runId, before!.width + 1);
expect(
- after!.width,
- `box grew from ${before!.width.toFixed(0)}pt to ${after!.width.toFixed(0)}pt instead of wrapping back to its locked width`,
- ).toBeLessThan(before!.width + 1);
- expect(
- after!.lines,
+ after.lines,
"the added text should have pushed onto new lines",
).toBeGreaterThan(before!.lines);
});
@@ -193,19 +210,14 @@ test.describe("PDF text editor - text wrap", () => {
await typeAtEnd(page, testId, LONG_TEXT);
await blurRun(page, testId);
- const after = await readRun(page, runId);
- expect(after).not.toBeNull();
- expect(
- after!.lines,
- "in wrap mode the overflow must go onto a second line",
- ).toBeGreaterThan(1);
// Wrapping at the page edge is not wrapping: "Wrap" means the run keeps
// the box it had. The old code reflowed at whatever width the box had
// grown to, so the heading spanned the page before it broke at all.
+ const after = await readRunAfterReflow(page, runId, before!.width + 1);
expect(
- after!.width,
- `wrap mode let the box grow from ${before!.width.toFixed(0)}pt to ${after!.width.toFixed(0)}pt`,
- ).toBeLessThan(before!.width + 1);
+ after.lines,
+ "in wrap mode the overflow must go onto a second line",
+ ).toBeGreaterThan(1);
});
// This used to assert that the overlay WRAPS text typed past the page edge.
@@ -261,11 +273,11 @@ test.describe("PDF text editor - text wrap", () => {
).toEqual(rows!.map(() => 1));
await blurRun(page, testId);
- const after = await readRun(page, runId);
- expect(after).not.toBeNull();
// The typed text survived and was re-broken onto lines that fit.
- expect(after!.lines, "the reflow should have added lines").toBeGreaterThan(
- before!.lines,
- );
+ await expect
+ .poll(async () => (await readRun(page, runId))?.lines ?? 0, {
+ timeout: 15_000,
+ })
+ .toBeGreaterThan(before!.lines);
});
});
diff --git a/frontend/editor/src/core/tests/stubbed/viewer-redaction-exit-restores-selection.spec.ts b/frontend/editor/src/core/tests/stubbed/viewer-redaction-exit-restores-selection.spec.ts
index b2c1fc1577..f7d72ef1f1 100644
--- a/frontend/editor/src/core/tests/stubbed/viewer-redaction-exit-restores-selection.spec.ts
+++ b/frontend/editor/src/core/tests/stubbed/viewer-redaction-exit-restores-selection.spec.ts
@@ -53,7 +53,11 @@ test("exiting redaction restores text selection", async ({ page }) => {
await expect
.poll(async () => (await viewerMode(page)).cursor, { timeout: 15_000 })
.toBe("crosshair");
- expect((await viewerMode(page)).touchScroll).toBe("off");
+ // cursor and touchScroll settle independently, so poll each rather than
+ // reading touchScroll one-shot the instant the cursor flips.
+ await expect
+ .poll(async () => (await viewerMode(page)).touchScroll, { timeout: 15_000 })
+ .toBe("off");
const exitButton = page
.getByRole("button", { name: /exit redaction mode/i })
@@ -67,7 +71,9 @@ test("exiting redaction restores text selection", async ({ page }) => {
await expect
.poll(async () => (await viewerMode(page)).touchScroll, { timeout: 15_000 })
.toBe("on");
- expect((await viewerMode(page)).cursor).toBe("auto");
+ await expect
+ .poll(async () => (await viewerMode(page)).cursor, { timeout: 15_000 })
+ .toBe("auto");
const box = await firstPage.boundingBox();
if (!box) throw new Error("Page wrapper has no bounding box");