mirror of
https://bitbucket.org/Mattrixwv/mattrixwvreactcomponents.git
synced 2025-12-06 13:43:59 -05:00
312 lines
12 KiB
TypeScript
312 lines
12 KiB
TypeScript
import LightButton from "$/component/button/LightButton";
|
|
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
const buttonText = "Light Button";
|
|
|
|
|
|
describe("LightButton Component", () => {
|
|
it("Renders with defaults", () => {
|
|
render(<LightButton>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-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-white", "hover:bg-neutral-300", "active:bg-neutral-400");
|
|
expect(button).toHaveClass("border-white", "hover:border-neutral-300", "active:border-neutral-400");
|
|
expect(button).toHaveClass("text-black");
|
|
});
|
|
|
|
it("Renders with custom className", () => {
|
|
const customClass = "custom-light-button-class";
|
|
|
|
render(<LightButton className={customClass}>{buttonText}</LightButton>);
|
|
|
|
//Check button requirements
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass(customClass);
|
|
});
|
|
|
|
it("Renders with aria-label", () => {
|
|
const ariaLabel = "Light Button Aria Label";
|
|
|
|
render(<LightButton aria-label={ariaLabel}>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveAttribute("aria-label", ariaLabel);
|
|
});
|
|
|
|
it("Renders with onClick handler", async () => {
|
|
const handleClick = vi.fn();
|
|
|
|
render(<LightButton onClick={handleClick}>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
|
|
await userEvent.click(button);
|
|
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
describe("LightButton Component Rounding", () => {
|
|
it("Renders with small rounding", () => {
|
|
render(<LightButton rounding="sm">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("rounded-sm");
|
|
});
|
|
it("Renders with medium rounding", () => {
|
|
render(<LightButton rounding="md">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("rounded-md");
|
|
});
|
|
it("Renders with large rounding", () => {
|
|
render(<LightButton rounding="lg">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("rounded-lg");
|
|
});
|
|
it("Renders with full rounding", () => {
|
|
render(<LightButton rounding="full">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("rounded-full");
|
|
});
|
|
});
|
|
|
|
describe("LightButton Component Size and Shape", () => {
|
|
it("Renders with xs square", () => {
|
|
render(<LightButton size="xs" shape="square">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("p-0");
|
|
});
|
|
it("Renders with sm square", () => {
|
|
render(<LightButton size="sm" shape="square">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("p-1");
|
|
});
|
|
it("Renders with md square", () => {
|
|
render(<LightButton size="md" shape="square">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("p-2");
|
|
});
|
|
it("Renders with lg square", () => {
|
|
render(<LightButton size="lg" shape="square">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("p-3");
|
|
});
|
|
it("Renders with xl square", () => {
|
|
render(<LightButton size="xl" shape="square">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("p-4");
|
|
});
|
|
it("Renders with xs rectangle", () => {
|
|
render(<LightButton size="xs" shape="rectangle">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("px-1", "py-0");
|
|
});
|
|
it("Renders with sm rectangle", () => {
|
|
render(<LightButton size="sm" shape="rectangle">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("px-2", "py-1");
|
|
});
|
|
it("Renders with md rectangle", () => {
|
|
render(<LightButton size="md" shape="rectangle">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("px-4", "py-2");
|
|
});
|
|
it("Renders with lg rectangle", () => {
|
|
render(<LightButton size="lg" shape="rectangle">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("px-6", "py-3");
|
|
});
|
|
it("Renders with xl rectangle", () => {
|
|
render(<LightButton size="xl" shape="rectangle">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("px-8", "py-4");
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("LightButton Component Disabled", () => {
|
|
it("Render with defaults when disabled", () => {
|
|
render(<LightButton disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-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-neutral-400/80");
|
|
expect(button).toHaveClass("border-neutral-400/80");
|
|
expect(button).toHaveClass("text-black");
|
|
});
|
|
it("Renders with custom className when disabled", () => {
|
|
const customClass = "custom-light-button-class";
|
|
|
|
render(<LightButton className={customClass} disabled>{buttonText}</LightButton>);
|
|
|
|
//Check button requirements
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass(customClass);
|
|
});
|
|
it("Renders with aria-label when disabled", () => {
|
|
const ariaLabel = "Light Button Aria Label";
|
|
|
|
render(<LightButton aria-label={ariaLabel} disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveAttribute("aria-label", ariaLabel);
|
|
});
|
|
it("Does not trigger onClick handler when disabled", async () => {
|
|
const handleClick = vi.fn();
|
|
|
|
render(<LightButton onClick={handleClick} disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
|
|
await userEvent.click(button);
|
|
expect(handleClick).toHaveBeenCalledTimes(0);
|
|
});
|
|
});
|
|
|
|
describe("LightButton Component Variants", () => {
|
|
it("Renders with standard variant", () => {
|
|
render(<LightButton variant="standard">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-white", "hover:bg-neutral-300", "active:bg-neutral-400");
|
|
expect(button).toHaveClass("border", "border-white", "hover:border-neutral-300", "active:border-neutral-400");
|
|
expect(button).toHaveClass("text-black");
|
|
});
|
|
it("Renders with outline variant", () => {
|
|
render(<LightButton variant="outline">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border", "border-white", "hover:border-neutral-300", "active:border-neutral-400");
|
|
expect(button).toHaveClass("text-white", "hover:text-neutral-300", "active:text-neutral-400");
|
|
});
|
|
it("Renders with outline-ghost variant", () => {
|
|
render(<LightButton variant="outline-ghost">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent", "hover:bg-white", "active:bg-neutral-300");
|
|
expect(button).toHaveClass("border", "border-white", "hover:border-white", "active:border-neutral-300");
|
|
expect(button).toHaveClass("text-white", "hover:text-black", "active:text-black");
|
|
});
|
|
it("Renders with ghost variant", () => {
|
|
render(<LightButton variant="ghost">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent", "hover:bg-white", "active:bg-neutral-300");
|
|
expect(button).toHaveClass("border-none");
|
|
expect(button).toHaveClass("text-white", "hover:text-black", "active:text-black");
|
|
});
|
|
it("Renders with icon variant", () => {
|
|
render(<LightButton variant="icon">{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border-none");
|
|
expect(button).toHaveClass("text-white", "hover:text-neutral-300", "active:text-neutral-400");
|
|
});
|
|
});
|
|
|
|
describe("LightButton Component Variants Disabled", () => {
|
|
it("Renders with standard variant when disabled", () => {
|
|
render(<LightButton variant="standard" disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-neutral-400/80");
|
|
expect(button).toHaveClass("border", "border-neutral-400/80");
|
|
expect(button).toHaveClass("text-black");
|
|
});
|
|
it("Renders with outline variant when disabled", () => {
|
|
render(<LightButton variant="outline" disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border", "border-neutral-400/80");
|
|
expect(button).toHaveClass("text-neutral-400/80");
|
|
});
|
|
it("Renders with outline-ghost variant when disabled", () => {
|
|
render(<LightButton variant="outline-ghost" disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border", "border-neutral-400/80");
|
|
expect(button).toHaveClass("text-neutral-400/80");
|
|
});
|
|
it("Renders with ghost variant when disabled", () => {
|
|
render(<LightButton variant="ghost" disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border-none");
|
|
expect(button).toHaveClass("text-neutral-400/80");
|
|
});
|
|
it("Renders with icon variant when disabled", () => {
|
|
render(<LightButton variant="icon" disabled>{buttonText}</LightButton>);
|
|
|
|
const button = screen.getByTestId("mattrixwv-light-button");
|
|
expect(button).toBeInTheDocument();
|
|
expect(button).toHaveClass("bg-transparent");
|
|
expect(button).toHaveClass("border-none");
|
|
expect(button).toHaveClass("text-neutral-400/80");
|
|
});
|
|
});
|