import { renderWithProviders as render, screen, fireEvent, } from "../utils/test-utils"; import { describe, it, expect, vi } from "vitest"; import Card from "../../app/components/cards/Card"; describe("Card Component", () => { const defaultProps = { label: "Label", supportText: "Support text here", orientation: "horizontal", }; it("renders label and supportText", () => { render(); expect(screen.getByText("Label")).toBeInTheDocument(); expect(screen.getByText("Support text here")).toBeInTheDocument(); }); it("renders RECOMMENDED pill when recommended is true", () => { render(); expect(screen.getByText("RECOMMENDED")).toBeInTheDocument(); }); it("does not render RECOMMENDED pill when recommended is false", () => { render(); expect(screen.queryByText("RECOMMENDED")).not.toBeInTheDocument(); }); it("renders SELECTED pill and inset dashed outline when selected is true", () => { render(); expect(screen.getByText("SELECTED")).toBeInTheDocument(); const card = screen.getByRole("button"); expect(card).toHaveClass("outline-dashed"); }); it("applies horizontal layout by default", () => { render(); expect(screen.getByText("Label")).toBeInTheDocument(); expect(screen.getByText("Support text here")).toBeInTheDocument(); }); it("applies vertical layout when orientation is vertical", () => { render(); const card = screen.getByRole("button"); expect(card).toHaveClass("flex-row"); }); it("handles click events", () => { const handleClick = vi.fn(); render(); const card = screen.getByRole("button"); fireEvent.click(card); expect(handleClick).toHaveBeenCalledTimes(1); }); it("handles keyboard events", () => { const handleClick = vi.fn(); render(); const card = screen.getByRole("button"); fireEvent.keyDown(card, { key: "Enter" }); expect(handleClick).toHaveBeenCalledTimes(1); fireEvent.keyDown(card, { key: " " }); expect(handleClick).toHaveBeenCalledTimes(2); }); it("renders with custom className", () => { const customClass = "custom-card"; render(); const card = screen.getByRole("button"); expect(card).toHaveClass(customClass); }); it("renders with proper accessibility attributes", () => { render(); const card = screen.getByRole("button"); expect(card).toHaveAttribute("aria-label", "Label: Support text here"); expect(card).toHaveAttribute("tabIndex", "0"); }); it("renders without supportText", () => { render(); expect(screen.getByText("Label only")).toBeInTheDocument(); expect(screen.getByRole("button")).toHaveAttribute( "aria-label", "Label only", ); }); });