import { act, render, screen, waitFor } from "@testing-library/react"; import React from "react"; import userEvent from "@testing-library/user-event"; import { buildTheme, loadTokens } from ":/tests/Theme"; import { Button } from ":/components/Button"; describe("); const button = screen.getByRole("button", { name: "Test button" }); expect(Array.from(button.classList)).toContain("c__button"); }); it("renders with custom class when using left icon", () => { render(); const button = screen.getByText("Test button"); const classes = Array.from(button.classList); expect(classes).toContain("c__button"); expect(classes).toContain("c__button--with-icon--left"); }); it("renders with modifier class --icon-only when only icon is defined", () => { render(, ); const button = screen.getByText("Test button"); const classes = Array.from(button.classList); expect(classes).toContain("c__button"); expect(classes).toContain("c__button--with-icon--right"); }); it("call onClick when click occurs", async () => { const user = userEvent.setup(); const handleClick = vi.fn(); render(); const button = screen.getByRole("button", { name: "Test button" }); expect(handleClick).not.toBeCalled(); user.click(button); await waitFor(() => expect(handleClick).toHaveBeenCalled()); }); it("does not call onClick when click occurs on a disabled button", async () => { const user = userEvent.setup(); const handleClick = vi.fn(); render( , ); const button = screen.getByRole("button", { name: "Test button" }); expect(handleClick).not.toBeCalled(); await act(async () => user.click(button)); expect(handleClick).not.toHaveBeenCalled(); }); it("uses custom token", async () => { await buildTheme(); const tokens = await loadTokens(); expect(tokens.components.button["border-radius"]).toBeDefined(); }); });