// @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 ( {}} 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( Results , ); const slot = screen.getByRole("navigation", { name: "페이지 탐색" }); expect(within(slot).queryAllByRole("navigation")).toHaveLength(0); expect(within(slot).getByRole("group", { name: "Pages" })).toBeVisible(); }); });