master @ 29 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { paginationItems, type PageItem } from "./Pagination"; │
│ │
│ const render = (items: PageItem[]) => │
│ items.map((it) => (it.kind === "gap" ? "..." : it.current ? `[${it.n}]` : String │
│ (it.n))).join(" "); │
│ │
│ describe("paginationItems", () => { │
│ it("windows around the current page with edge pages pinned", () => { │
│ expect(render(paginationItems(6, 20))).toBe("1 ... 4 5 [6] 7 8 ... 20"); │
│ }); │
│ │
│ it("collapses gaps that would hide a single page", () => { │
│ expect(render(paginationItems(4, 20))).toBe("1 2 3 [4] 5 6 ... 20"); │
│ }); │
│ │
│ it("handles the first and last pages", () => { │
│ expect(render(paginationItems(1, 20))).toBe("[1] 2 3 4 5 ... 20"); │
│ expect(render(paginationItems(20, 20))).toBe("1 ... 16 17 18 19 [20]"); │
│ }); │
│ │
│ it("shows every page when total fits the window", () => { │
│ expect(render(paginationItems(2, 4))).toBe("1 [2] 3 4"); │
│ }); │
│ │
│ it("clamps out-of-range current pages", () => { │
│ expect(render(paginationItems(99, 3))).toBe("1 2 [3]"); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { paginationItems, type PageItem } fr │
│ om "./Pagination"; │
│ │
│ const render = (items: PageItem[]) => │
│ items.map((it) => (it.kind === "gap" ? ".. │
│ ." : it.current ? `[${it.n}]` : String(it.n) │
│ )).join(" "); │
│ │
│ describe("paginationItems", () => { │
│ it("windows around the current page with e │
│ dge pages pinned", () => { │
│ expect(render(paginationItems(6, 20))).t │
│ oBe("1 ... 4 5 [6] 7 8 ... 20"); │
│ }); │
│ │
│ it("collapses gaps that would hide a singl │
│ e page", () => { │
│ expect(render(paginationItems(4, 20))).t │
│ oBe("1 2 3 [4] 5 6 ... 20"); │
│ }); │
│ │
│ it("handles the first and last pages", () │
│ => { │
│ expect(render(paginationItems(1, 20))).t │
│ oBe("[1] 2 3 4 5 ... 20"); │
│ expect(render(paginationItems(20, 20))). │
│ toBe("1 ... 16 17 18 19 [20]"); │
│ }); │
│ │
│ it("shows every page when total fits the w │
│ indow", () => { │
│ expect(render(paginationItems(2, 4))).to │
│ Be("1 [2] 3 4"); │
│ }); │
│ │
│ it("clamps out-of-range current pages", () │
│ => { │
│ expect(render(paginationItems(99, 3))).t │
│ oBe("1 2 [3]"); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET