mirror of
https://bitbucket.org/Mattrixwv/mattrixwvreactcomponents.git
synced 2025-12-06 21:53:57 -05:00
Added tests for buttons
This commit is contained in:
311
test/component/button/InfoButton.test.tsx
Normal file
311
test/component/button/InfoButton.test.tsx
Normal file
@@ -0,0 +1,311 @@
|
||||
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(<InfoButton>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton className={customClass}>{buttonText}</InfoButton>);
|
||||
|
||||
//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(<InfoButton aria-label={ariaLabel}>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton onClick={handleClick}>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton rounding="sm">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("rounded-sm");
|
||||
});
|
||||
it("Renders with medium rounding", () => {
|
||||
render(<InfoButton rounding="md">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("rounded-md");
|
||||
});
|
||||
it("Renders with large rounding", () => {
|
||||
render(<InfoButton rounding="lg">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("rounded-lg");
|
||||
});
|
||||
it("Renders with full rounding", () => {
|
||||
render(<InfoButton rounding="full">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton size="xs" shape="square">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("p-0");
|
||||
});
|
||||
it("Renders with sm square", () => {
|
||||
render(<InfoButton size="sm" shape="square">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("p-1");
|
||||
});
|
||||
it("Renders with md square", () => {
|
||||
render(<InfoButton size="md" shape="square">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("p-2");
|
||||
});
|
||||
it("Renders with lg square", () => {
|
||||
render(<InfoButton size="lg" shape="square">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("p-3");
|
||||
});
|
||||
it("Renders with xl square", () => {
|
||||
render(<InfoButton size="xl" shape="square">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("p-4");
|
||||
});
|
||||
it("Renders with xs rectangle", () => {
|
||||
render(<InfoButton size="xs" shape="rectangle">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("px-1", "py-0");
|
||||
});
|
||||
it("Renders with sm rectangle", () => {
|
||||
render(<InfoButton size="sm" shape="rectangle">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("px-2", "py-1");
|
||||
});
|
||||
it("Renders with md rectangle", () => {
|
||||
render(<InfoButton size="md" shape="rectangle">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("px-4", "py-2");
|
||||
});
|
||||
it("Renders with lg rectangle", () => {
|
||||
render(<InfoButton size="lg" shape="rectangle">{buttonText}</InfoButton>);
|
||||
|
||||
const button = screen.getByTestId("mattrixwv-info-button");
|
||||
expect(button).toBeInTheDocument();
|
||||
expect(button).toHaveClass("px-6", "py-3");
|
||||
});
|
||||
it("Renders with xl rectangle", () => {
|
||||
render(<InfoButton size="xl" shape="rectangle">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton className={customClass} disabled>{buttonText}</InfoButton>);
|
||||
|
||||
//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(<InfoButton aria-label={ariaLabel} disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton onClick={handleClick} disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="standard">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="outline">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="outline-ghost">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="ghost">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="icon">{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="standard" disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="outline" disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="outline-ghost" disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="ghost" disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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(<InfoButton variant="icon" disabled>{buttonText}</InfoButton>);
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user