// @vitest-environment jsdom import { describe, it, expect, afterEach, vi } from "vitest"; import { render, screen, cleanup, fireEvent } from "@testing-library/react"; import { Button } from "./Button.tsx"; afterEach(cleanup); describe("Button", () => { it("renders its children and defaults to type=button", () => { render(); const btn = screen.getByRole("button", { name: "Save" }); expect(btn).toHaveProperty("type", "button"); }); it("applies the primary variant token classes by default", () => { render(); const btn = screen.getByRole("button", { name: "Go" }); expect(btn.className).toContain("bg-accent"); expect(btn.className).toContain("text-text-inv"); }); it("switches variant and size classes", () => { render( , ); const btn = screen.getByRole("button", { name: "Cancel" }); expect(btn.className).toContain("text-text-md"); expect(btn.className).toContain("h-7"); expect(btn.className).not.toContain("bg-accent"); }); it("merges a caller className without dropping base classes", () => { render(); const btn = screen.getByRole("button", { name: "Wide" }); expect(btn.className).toContain("w-full"); expect(btn.className).toContain("rounded-md"); }); it("fires onClick and blocks it when disabled", () => { const onClick = vi.fn(); const { rerender } = render(); fireEvent.click(screen.getByRole("button", { name: "Tap" })); expect(onClick).toHaveBeenCalledTimes(1); rerender( , ); fireEvent.click(screen.getByRole("button", { name: "Tap" })); expect(onClick).toHaveBeenCalledTimes(1); }); });