import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { Segmented } from "./segmented"; describe("Segmented", () => { const options = [ { value: "a", label: "Alpha" }, { value: "b", label: "Beta" }, ] as const; it("marks only the chosen option pressed, inside a named group", () => { render( {}} />); expect(screen.getByRole("group", { name: "Mode" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Alpha" })).toHaveAttribute("aria-pressed", "true"); expect(screen.getByRole("button", { name: "Beta" })).toHaveAttribute("aria-pressed", "false"); }); it("reports the option pressed", async () => { const onChange = vi.fn(); render(); await userEvent.click(screen.getByRole("button", { name: "Beta" })); expect(onChange).toHaveBeenCalledWith("b"); }); });