import Button from "$/component/button/Button"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; const buttonText = "Test Button"; describe("Button Component", () => { it("Render with defaults", () => { render(); const button = screen.getByTestId("mattrixwv-button"); //Check button requirements expect(button).toBeInTheDocument(); expect(button).toHaveTextContent(buttonText); //Classes expect(button).toHaveClass("rounded-lg"); expect(button).toHaveClass("px-4", "py-2"); expect(button).toHaveClass("border"); expect(button).toHaveClass("cursor-pointer"); }); it("Renders with custom className", () => { const customClass = "custom-button-class"; render(); //Check button requirements const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass(customClass); }); it("Renders with aria-label", () => { const ariaLabel = "Custom Aria Label"; render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveAttribute("aria-label", ariaLabel); }); it("Renders with onClick handler", async () => { const handleClick = vi.fn(); render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); await userEvent.click(button); expect(handleClick).toHaveBeenCalledTimes(1); }); describe("Button Rounding Variants", () => { it("Renders with small rounding", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-sm"); }); it("Renders with medium rounding", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-md"); }); it("Renders with large rounding", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-lg"); }); it("Renders with full rounding", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-full"); }); }); describe("Button Size and Shape Variants", () => { it("Renders with xs square", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-0"); }); it("Renders with sm square", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-1"); }); it("Renders with md square", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-2"); }); it("Renders with lg square", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-3"); }); it("Renders with xl square", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-4"); }); it("Renders with xs rectangle", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-1", "py-0"); }); it("Renders with sm rectangle", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-2", "py-1"); }); it("Renders with md rectangle", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-4", "py-2"); }); it("Renders with lg rectangle", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-6", "py-3"); }); it("Renders with xl rectangle", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-8", "py-4"); }); }); describe("Button Variant Types", () => { it("Renders with standard variant", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("border"); }); it("Renders with outline variant", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("border"); }); it("Renders with outline-ghost variant", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("border"); }); it("Renders with ghost variant", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("border-none"); }); it("Renders with icon variant", () => { render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("border-none"); }); }); }); describe("Button Component Disabled", () => { it("Render with defaults", () => { render(); const button = screen.getByTestId("mattrixwv-button"); //Check button requirements expect(button).toBeInTheDocument(); expect(button).toHaveTextContent(buttonText); //Classes expect(button).toHaveClass("rounded-lg"); expect(button).toHaveClass("px-4", "py-2"); expect(button).toHaveClass("border"); expect(button).not.toHaveClass("cursor-pointer"); }); it("Renders with custom className", () => { const customClass = "custom-button-class"; render(); //Check button requirements const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass(customClass); }); it("Renders with aria-label", () => { const ariaLabel = "Custom Aria Label"; render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); expect(button).toHaveAttribute("aria-label", ariaLabel); }); it("Does not trigger onClick when disabled", async () => { const handleClick = vi.fn(); render(); const button = screen.getByTestId("mattrixwv-button"); expect(button).toBeInTheDocument(); await userEvent.click(button); expect(handleClick).not.toHaveBeenCalled(); }); });