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