import { describe, it, expect, beforeEach } from "vitest"; import { PettyTabs } from "../src/components/tabs/index"; import { h } from "./helpers"; describe("petty-tabs", () => { let el: PettyTabs; beforeEach(() => { document.body.textContent = ""; el = document.createElement("petty-tabs") as PettyTabs; el.setAttribute("default-value", "one"); const tab1 = h("petty-tab", { value: "one" }, "Tab 1"); const tab2 = h("petty-tab", { value: "two" }, "Tab 2"); const tablist = h("div", { role: "tablist" }, tab1, tab2); const panel1 = h("petty-tab-panel", { value: "one" }, "Content 1"); const panel2 = h("petty-tab-panel", { value: "two" }, "Content 2"); el.appendChild(tablist); el.appendChild(panel1); el.appendChild(panel2); document.body.appendChild(el); }); it("registers the custom elements", () => { expect(customElements.get("petty-tabs")).toBe(PettyTabs); }); it("initializes with default-value", () => { expect(el.value).toBe("one"); }); it("sets data-state and aria-selected on active tab", () => { const tab1 = el.querySelector("petty-tab[value='one']")!; const tab2 = el.querySelector("petty-tab[value='two']")!; expect(tab1.getAttribute("data-state")).toBe("active"); expect(tab1.getAttribute("aria-selected")).toBe("true"); expect(tab2.getAttribute("data-state")).toBe("inactive"); }); it("hides inactive panels", () => { const panel2 = el.querySelector("petty-tab-panel[value='two']")!; expect(panel2.hasAttribute("hidden")).toBe(true); }); it("fires petty-change on selectTab", () => { let detail: { value: string } | null = null; el.addEventListener("petty-change", ((e: CustomEvent) => { detail = e.detail; }) as EventListener); el.selectTab("two"); expect(detail).toEqual({ value: "two" }); expect(el.value).toBe("two"); }); });