Some checks are pending
CI / check (push) Waiting to run
- 51 headless Web Components (45 core + 6 animation) - Shared helpers: emit(), part(), listen(), wireLabel(), initialValue() - Zero `new CustomEvent` or `static #counter` — all use shared utils - Zod schemas for all 44 core components - MCP package with discover, inspect, compose, validate tools - Showcase with Aperture Science theme, M3 Expressive motion - 81 tests passing, TypeScript strict mode clean - Signals (~500B), SPA router (~400B), zero dependencies
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { PettyPagination } from "../src/components/pagination/index";
|
|
import { h } from "./helpers";
|
|
|
|
describe("petty-pagination", () => {
|
|
let el: PettyPagination;
|
|
|
|
beforeEach(() => {
|
|
document.body.textContent = "";
|
|
el = document.createElement("petty-pagination") as PettyPagination;
|
|
el.setAttribute("total", "50");
|
|
el.setAttribute("page-size", "10");
|
|
el.appendChild(h("petty-pagination-item", { type: "prev" }, "Prev"));
|
|
el.appendChild(h("petty-pagination-item", { value: "1" }, "1"));
|
|
el.appendChild(h("petty-pagination-item", { value: "2" }, "2"));
|
|
el.appendChild(h("petty-pagination-item", { value: "3" }, "3"));
|
|
el.appendChild(h("petty-pagination-item", { type: "next" }, "Next"));
|
|
document.body.appendChild(el);
|
|
});
|
|
|
|
it("registers and calculates totalPages", () => {
|
|
expect(customElements.get("petty-pagination")).toBe(PettyPagination);
|
|
expect(el.totalPages).toBe(5);
|
|
expect(el.currentPage).toBe(1);
|
|
});
|
|
|
|
it("marks page 1 as active with aria-current", () => {
|
|
const item1 = el.querySelector("[value='1']")!;
|
|
expect(item1.getAttribute("data-state")).toBe("active");
|
|
expect(item1.getAttribute("aria-current")).toBe("page");
|
|
});
|
|
|
|
it("disables prev on first page", () => {
|
|
expect(el.querySelector("[type=prev]")!.hasAttribute("disabled")).toBe(true);
|
|
});
|
|
|
|
it("clamps goToPage to valid range", () => {
|
|
el.goToPage(0);
|
|
expect(el.currentPage).toBe(1);
|
|
el.goToPage(999);
|
|
expect(el.currentPage).toBe(5);
|
|
});
|
|
|
|
it("fires petty-change on goToPage", () => {
|
|
let detail: { page: number } | null = null;
|
|
el.addEventListener("petty-change", ((e: CustomEvent) => { detail = e.detail; }) as EventListener);
|
|
el.goToPage(3);
|
|
expect(detail).toEqual({ page: 3 });
|
|
expect(el.currentPage).toBe(3);
|
|
});
|
|
|
|
it("disables next on last page", () => {
|
|
el.goToPage(5);
|
|
expect(el.querySelector("[type=next]")!.hasAttribute("disabled")).toBe(true);
|
|
});
|
|
});
|