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