import InfoButton from "$/component/button/InfoButton"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; const buttonText = "Info Button"; describe("InfoButton Component", () => { it("Renders with defaults", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-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"); //Colors expect(button).toHaveClass("bg-cyan-500", "hover:bg-cyan-600", "active:bg-cyan-700"); expect(button).toHaveClass("border-cyan-500", "hover:border-cyan-600", "active:border-cyan-700"); expect(button).toHaveClass("text-black"); }); it("Renders with custom className", () => { const customClass = "custom-info-button-class"; render({buttonText}); //Check button requirements const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass(customClass); }); it("Renders with aria-label", () => { const ariaLabel = "Info Button Aria Label"; render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveAttribute("aria-label", ariaLabel); }); it("Renders with onClick handler", async () => { const handleClick = vi.fn(); render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); await userEvent.click(button); expect(handleClick).toHaveBeenCalledTimes(1); }); describe("InfoButton Component Rounding", () => { it("Renders with small rounding", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-sm"); }); it("Renders with medium rounding", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-md"); }); it("Renders with large rounding", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-lg"); }); it("Renders with full rounding", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("rounded-full"); }); }); describe("InfoButton Component Size and Shape", () => { it("Renders with xs square", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-0"); }); it("Renders with sm square", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-1"); }); it("Renders with md square", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-2"); }); it("Renders with lg square", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-3"); }); it("Renders with xl square", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("p-4"); }); it("Renders with xs rectangle", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-1", "py-0"); }); it("Renders with sm rectangle", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-2", "py-1"); }); it("Renders with md rectangle", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-4", "py-2"); }); it("Renders with lg rectangle", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-6", "py-3"); }); it("Renders with xl rectangle", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("px-8", "py-4"); }); }); }); describe("InfoButton Component Disabled", () => { it("Render with defaults when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-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"); //Disabled state expect(button).not.toHaveClass("cursor-pointer"); expect(button).toHaveClass("bg-sky-300/80"); expect(button).toHaveClass("border-sky-300/80"); expect(button).toHaveClass("text-black"); }); it("Renders with custom className when disabled", () => { const customClass = "custom-info-button-class"; render({buttonText}); //Check button requirements const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass(customClass); }); it("Renders with aria-label when disabled", () => { const ariaLabel = "Info Button Aria Label"; render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveAttribute("aria-label", ariaLabel); }); it("Does not trigger onClick handler when disabled", async () => { const handleClick = vi.fn(); render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); await userEvent.click(button); expect(handleClick).toHaveBeenCalledTimes(0); }); }); describe("InfoButton Component Variants", () => { it("Renders with standard variant", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-cyan-500", "hover:bg-cyan-600", "active:bg-cyan-700"); expect(button).toHaveClass("border", "border-cyan-500", "hover:border-cyan-600", "active:border-cyan-700"); expect(button).toHaveClass("text-black"); }); it("Renders with outline variant", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border", "border-cyan-500", "hover:border-cyan-600", "active:border-cyan-700"); expect(button).toHaveClass("text-cyan-500", "hover:text-cyan-600", "active:text-cyan-700"); }); it("Renders with outline-ghost variant", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent", "hover:bg-cyan-500", "active:bg-cyan-600"); expect(button).toHaveClass("border", "border-cyan-500", "hover:border-cyan-500", "active:border-cyan-600"); expect(button).toHaveClass("text-cyan-500", "hover:text-black", "active:text-black"); }); it("Renders with ghost variant", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent", "hover:bg-cyan-500", "active:bg-cyan-600"); expect(button).toHaveClass("border-none"); expect(button).toHaveClass("text-cyan-500", "hover:text-black", "active:text-black"); }); it("Renders with icon variant", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border-none"); expect(button).toHaveClass("text-cyan-500", "hover:text-cyan-600", "active:text-cyan-700"); }); }); describe("InfoButton Component Variants Disabled", () => { it("Renders with standard variant when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-sky-300/80"); expect(button).toHaveClass("border", "border-sky-300/80"); expect(button).toHaveClass("text-black"); }); it("Renders with outline variant when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border", "border-sky-300/80"); expect(button).toHaveClass("text-sky-300/80"); }); it("Renders with outline-ghost variant when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border", "border-sky-300/80"); expect(button).toHaveClass("text-sky-300/80"); }); it("Renders with ghost variant when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border-none"); expect(button).toHaveClass("text-sky-300/80"); }); it("Renders with icon variant when disabled", () => { render({buttonText}); const button = screen.getByTestId("mattrixwv-info-button"); expect(button).toBeInTheDocument(); expect(button).toHaveClass("bg-transparent"); expect(button).toHaveClass("border-none"); expect(button).toHaveClass("text-sky-300/80"); }); });