36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
import { describe, it, expect } from "vitest";
|
|
import { buildPaginationHtml } from "../src/ui/pagination.js";
|
|
|
|
function mount(html) {
|
|
const el = document.createElement("div");
|
|
el.innerHTML = html;
|
|
return el;
|
|
}
|
|
|
|
describe("ui/pagination builder", () => {
|
|
it("renders prev disabled on page 1", () => {
|
|
const el = mount(buildPaginationHtml({ currentPage: 1, itemsPerPage: 25, totalResults: 200 }));
|
|
const nav = el.querySelector(".pagination-controls");
|
|
expect(nav).toBeTruthy();
|
|
const disabled = nav.querySelectorAll(".disabled");
|
|
expect(disabled.length).toBeGreaterThan(0);
|
|
expect(nav.querySelector('[aria-current="page"]')?.textContent).toBe("1");
|
|
});
|
|
|
|
it("renders next disabled on last page", () => {
|
|
const el = mount(buildPaginationHtml({ currentPage: 8, itemsPerPage: 25, totalResults: 200 }));
|
|
const nav = el.querySelector(".pagination-controls");
|
|
const disabled = nav.querySelectorAll(".disabled");
|
|
expect(disabled.length).toBeGreaterThan(0);
|
|
expect(nav.querySelector('[aria-current="page"]')?.textContent).toBe("8");
|
|
});
|
|
|
|
it("has correct jump input bounds/value", () => {
|
|
const el = mount(buildPaginationHtml({ currentPage: 3, itemsPerPage: 10, totalResults: 95 }));
|
|
const input = el.querySelector(".jump-input");
|
|
expect(input.getAttribute("min")).toBe("1");
|
|
expect(input.getAttribute("max")).toBe(String(Math.ceil(95 / 10)));
|
|
expect(input.getAttribute("value")).toBe("3");
|
|
});
|
|
});
|