import { describe, expect, it, afterEach, vi } from "vitest"; import { render, screen, cleanup, fireEvent } from "@testing-library/react"; import { Button } from "./Button.js"; afterEach(() => { cleanup(); }); describe("Button", () => { it("should render children", () => { render(); expect(screen.getByRole("button")).toHaveTextContent("Click me"); }); describe("variants", () => { it("should apply primary variant styles by default", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("bg-blue-600"); }); it("should apply secondary variant styles", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("bg-gray-200"); }); it("should apply danger variant styles", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("bg-red-600"); }); }); describe("sizes", () => { it("should apply medium size by default", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("px-4"); }); it("should apply small size styles", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("px-3"); }); it("should apply large size styles", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("px-6"); }); }); describe("onClick", () => { it("should call onClick handler when clicked", () => { const handleClick = vi.fn(); render(); fireEvent.click(screen.getByRole("button")); expect(handleClick).toHaveBeenCalledTimes(1); }); it("should not call onClick when disabled", () => { const handleClick = vi.fn(); render( ); fireEvent.click(screen.getByRole("button")); expect(handleClick).not.toHaveBeenCalled(); }); }); it("should pass through additional props", () => { render(); expect(screen.getByRole("button")).toBeDisabled(); }); it("should merge custom className with default styles", () => { render(); const button = screen.getByRole("button"); expect(button.className).toContain("custom-class"); expect(button.className).toContain("bg-blue-600"); }); });