import assert from "node:assert/strict"; import { dirname, join } from "node:path"; import { test } from "node:test"; import { fileURLToPath } from "node:url"; import * as ejs from "ejs"; const pagination = join(dirname(fileURLToPath(import.meta.url)), "..", "views", "partials", "pagination.ejs"); const render = (data: Record = {}): Promise => ejs.renderFile(pagination, data); const flat = (s: string): string => s.replace(/>\s+<").replace(/\s+/g, " ").trim(); const config = { summary: { from: "1", to: 12, total: "1,284" }, rows: { name: "rows", value: 25, // active option options: [12, 25, 50, 100], hidden: [{ name: "q", value: "ada" }, { name: "status", value: "active" }], // list state carried forward }, prev: {}, // first page → disabled (no href) pages: [ { label: "1", current: true }, { label: "2", href: "?sort=name&page=2" }, // & must be escaped { label: "3", href: "?page=3" }, { ellipsis: true }, { label: "107", href: "?page=107" }, ], next: { href: "?page=2" }, }; test("pagination renders summary, rows-per-page form, page links, current, ellipsis and prev/next", async () => { const html = flat(await render(config)); assert.match(html, /