import { render, screen } from "@testing-library/react"; import { Button, ButtonSize, ButtonType, ButtonVariant, } from "../../components/Button/Button"; import { axe } from "jest-axe"; describe("Button", () => { test("Should render component correctly.", () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); describe("Accessibility", () => { test("Should have no accessibility violations.", async () => { const { container } = render(); const results = await axe(container); expect(results).toHaveNoViolations(); }); }); describe("Props", () => { test.each(["primary", "secondary"])( "Should render variants correctly.", (variant) => { render(); expect( screen.getByRole("button", { name: "Button" }) ).toHaveClass(variant); } ); test.each(["small", "medium", "large"])( "Should render sizes correctly", (size) => { render(); expect( screen.getByRole("button", { name: "Button" }) ).toHaveClass(size); } ); test("Should render leading icon correctly.", () => { render(); expect( screen.getByRole("button", { name: "leading Button" }) ).toBeInTheDocument(); }); test("Should render trailing icon correctly.", () => { render(); expect( screen.getByRole("button", { name: "Button trailing" }) ).toBeInTheDocument(); }); test("Should render children correctly.", () => { render(); expect( screen.getByRole("button", { name: "Button" }) ).toBeInTheDocument(); }); test("Should render disabled correctly.", () => { render(); expect( screen.getByRole("button", { name: "Button" }) ).toHaveClass("disabled"); }); test.each(["button", "reset", "submit"])( "Should render type correctly.", (type) => { render(); expect( screen.getByRole("button", { name: "Button" }) ).toHaveAttribute("type", type); } ); });