import { describe, it, expect } from "vitest"; import { screen } from "@testing-library/react"; import "@testing-library/jest-dom/vitest"; import { componentTestSuite, type ComponentTestSuiteConfig, } from "../utils/componentTestSuite"; import { renderWithProviders as render } from "../utils/test-utils"; import Chip from "../../app/components/controls/Chip"; type Props = React.ComponentProps; const config: ComponentTestSuiteConfig = { component: Chip, name: "Chip", props: { label: "Worker cooperative", state: "unselected", palette: "default", size: "m", } as Props, primaryRole: "button", testCases: { renders: true, accessibility: true, keyboardNavigation: true, disabledState: true, }, states: { disabledProps: { disabled: true, state: "disabled" }, }, }; describe("Chip", () => { componentTestSuite(config); it("exposes aria-pressed false when unselected", () => { render(); const chip = screen.getByRole("button", { name: "Worker cooperative" }); expect(chip).toHaveAttribute("aria-pressed", "false"); expect(chip.querySelector("svg")).toBeNull(); }); it("paints unselected chips on the element so native button styles cannot win", () => { render(); const chip = screen.getByRole("button", { name: "Worker cooperative" }); expect(chip.style.color).toContain("--color-content-default-brand-primary"); expect(chip.style.backgroundColor).toBe("transparent"); expect(chip.style.borderColor).toContain( "--color-border-default-tertiary", ); }); it("exposes aria-pressed and a check mark when selected", () => { render(); const chip = screen.getByRole("button", { name: "Worker cooperative" }); expect(chip).toHaveAttribute("aria-pressed", "true"); expect(chip.querySelector("svg[aria-hidden]")).not.toBeNull(); }); });