fix(presentation): window pagination links and stop nesting its landmark (Q-6.8-12)
Pagination links only the first and last page, the current page and its neighbours, with an aria-hidden ellipsis for a longer gap and the page itself for a one-page gap, so 5000 pages render five links instead of 5000. Inside CollectionPage, whose slot already is the pagination `nav`, Pagination renders a labelled group instead of a nested `nav`; on its own it stays a navigation landmark. Verified with tests/component/pagination.test.tsx (RED: 3 of 5 failed before the change) and the lane gates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
21233e8d9b
commit
22d4e8a29d
@@ -0,0 +1,80 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Pagination } from "../../src/presentation/design-system/index.ts";
|
||||
import { CollectionPage } from "../../src/presentation/templates/index.ts";
|
||||
|
||||
function pagination(page: number, pageCount: number) {
|
||||
return (
|
||||
<Pagination
|
||||
label="Pages"
|
||||
nextLabel="Next"
|
||||
onChange={() => {}}
|
||||
page={page}
|
||||
pageCount={pageCount}
|
||||
pageLabel={(candidate) => `Page ${candidate}`}
|
||||
previousLabel="Previous"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function pageLinks(): string[] {
|
||||
return screen
|
||||
.getAllByRole("link")
|
||||
.map((link) => link.textContent ?? "");
|
||||
}
|
||||
|
||||
describe("Pagination windowing", () => {
|
||||
it("links the first, last and neighbouring pages only", () => {
|
||||
render(pagination(50, 5000));
|
||||
|
||||
expect(pageLinks()).toEqual([
|
||||
"Page 1",
|
||||
"Page 49",
|
||||
"Page 50",
|
||||
"Page 51",
|
||||
"Page 5000",
|
||||
]);
|
||||
expect(screen.getByRole("link", { name: "Page 50" })).toHaveAttribute(
|
||||
"aria-current",
|
||||
"page",
|
||||
);
|
||||
});
|
||||
|
||||
it("links a single skipped page instead of eliding it", () => {
|
||||
render(pagination(3, 5000));
|
||||
expect(pageLinks()).toEqual([
|
||||
"Page 1",
|
||||
"Page 2",
|
||||
"Page 3",
|
||||
"Page 4",
|
||||
"Page 5000",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps every page of a short range", () => {
|
||||
render(pagination(1, 3));
|
||||
expect(pageLinks()).toEqual(["Page 1", "Page 2", "Page 3"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination landmarks", () => {
|
||||
it("is a navigation landmark on its own", () => {
|
||||
render(pagination(1, 2));
|
||||
expect(screen.getByRole("navigation", { name: "Pages" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("does not nest a navigation landmark inside the collection page slot", () => {
|
||||
render(
|
||||
<CollectionPage heading={{ title: "Collection" }} pagination={pagination(1, 2)}>
|
||||
Results
|
||||
</CollectionPage>,
|
||||
);
|
||||
|
||||
const slot = screen.getByRole("navigation", { name: "페이지 탐색" });
|
||||
expect(within(slot).queryAllByRole("navigation")).toHaveLength(0);
|
||||
expect(within(slot).getByRole("group", { name: "Pages" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user