Skip to content

Commit 76e9b0f

Browse files
bjohansebasclaude
andcommitted
test(e2e): cover pagination clamping and page retention, drop the jsdom describe
The pagination e2e now clamps at the last page under real clicks and key presses, and a shared-state test drives a bundled copy through the page-index semantics: a re-publish of the same problems keeps the page the user navigated to, a different set starts back at page one. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 69b00b1 commit 76e9b0f

2 files changed

Lines changed: 44 additions & 60 deletions

File tree

test/e2e/overlay.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ describe("error overlay (browser)", () => {
323323
document.body.textContent.includes("2 / 2"),
324324
);
325325

326+
// Clamped at the last page.
327+
await frame.click('[aria-label="Next problem"]');
328+
await page.keyboard.press("ArrowRight");
326329
expect(await frame.evaluate(() => document.body.textContent)).toContain(
327330
"2 / 2",
328331
);
@@ -683,6 +686,47 @@ describe("overlay shared state across bundled copies (browser)", () => {
683686
expect(await page.$(`#${OVERLAY_ID}`)).toBeNull();
684687
});
685688

689+
it("resets the page for a new problem set and keeps it for a re-publish", async () => {
690+
await start();
691+
await page.goto(hotApp.url);
692+
693+
await page.evaluate(() => {
694+
globalThis.overlayA.showProblems("errors", ["first boom", "second boom"]);
695+
});
696+
const frame = await overlayFrame();
697+
await frame.click('[aria-label="Next problem"]');
698+
await frame.waitForFunction(() =>
699+
document.body.textContent.includes("2 / 2"),
700+
);
701+
702+
// Re-publishing the same problems (every clean rebuild does) keeps the
703+
// page the user navigated to…
704+
await page.evaluate(() => {
705+
globalThis.overlayA.showProblems("errors", ["first boom", "second boom"]);
706+
});
707+
await frame.waitForFunction(() =>
708+
document.body.textContent.includes("2 / 2"),
709+
);
710+
expect(await frame.evaluate(() => document.body.textContent)).toContain(
711+
"second boom",
712+
);
713+
714+
// …while a different set starts back at the first page.
715+
await page.evaluate(() => {
716+
globalThis.overlayA.showProblems("errors", [
717+
"new first",
718+
"new second",
719+
"new third",
720+
]);
721+
});
722+
await frame.waitForFunction(() =>
723+
document.body.textContent.includes("1 / 3"),
724+
);
725+
expect(await frame.evaluate(() => document.body.textContent)).toContain(
726+
"new first",
727+
);
728+
});
729+
686730
it("fills state fields missing from an older copy's shape", async () => {
687731
await start();
688732
// An older package version created a leaner shared state before the

test/overlay.test.js

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -202,66 +202,6 @@ describe("overlay", () => {
202202
});
203203
});
204204

205-
describe("pagination", () => {
206-
afterEach(() => {
207-
// Restore the default.
208-
configureOverlay({ paginate: true });
209-
});
210-
211-
it("navigates with the prev/next buttons and clamps at the ends", () => {
212-
showProblems("errors", ["first boom", "second boom"]);
213-
214-
const next = [...getCard().querySelectorAll("button")].find(
215-
(button) => button.getAttribute("aria-label") === "Next problem",
216-
);
217-
218-
next.click();
219-
expect(getCard().textContent).toContain("second boom");
220-
expect(getCard().textContent).toContain("2 / 2");
221-
222-
// Clamped at the last page.
223-
const nextAgain = [...getCard().querySelectorAll("button")].find(
224-
(button) => button.getAttribute("aria-label") === "Next problem",
225-
);
226-
227-
nextAgain.click();
228-
expect(getCard().textContent).toContain("2 / 2");
229-
230-
const prev = [...getCard().querySelectorAll("button")].find(
231-
(button) => button.getAttribute("aria-label") === "Previous problem",
232-
);
233-
234-
prev.click();
235-
expect(getCard().textContent).toContain("first boom");
236-
});
237-
238-
it("resets to the first page on a new problem set", () => {
239-
showProblems("errors", ["first boom", "second boom"]);
240-
241-
getOverlay().contentDocument.dispatchEvent(
242-
new KeyboardEvent("keydown", { key: "ArrowRight" }),
243-
);
244-
showProblems("errors", ["new first", "new second", "new third"]);
245-
246-
expect(getCard().textContent).toContain("new first");
247-
expect(getCard().textContent).toContain("1 / 3");
248-
});
249-
250-
it("keeps the current page when the same problems are re-published", () => {
251-
showProblems("errors", ["first boom", "second boom"]);
252-
253-
getOverlay().contentDocument.dispatchEvent(
254-
new KeyboardEvent("keydown", { key: "ArrowRight" }),
255-
);
256-
expect(getCard().textContent).toContain("2 / 2");
257-
258-
showProblems("errors", ["first boom", "second boom"]);
259-
260-
expect(getCard().textContent).toContain("second boom");
261-
expect(getCard().textContent).toContain("2 / 2");
262-
});
263-
});
264-
265205
describe("configureOverlay", () => {
266206
it("returns the overlay API", () => {
267207
const api = configureOverlay({});

0 commit comments

Comments
 (0)