import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { MehrfachAuswahl } from "@/components/ui/MehrfachAuswahl"; const OPTIONEN = [ { wert: "l1", label: "Wien" }, { wert: "l2", label: "Wolkersdorf" }, { wert: "l3", label: "Linz" }, ]; function zeige(werte: string[], onChange = vi.fn()) { render(); return onChange; } describe("MehrfachAuswahl", () => { it("zeigt ohne Auswahl die Beschriftung für alle", () => { zeige([]); expect(screen.getByRole("combobox", { name: "Standort" })).toHaveDisplayValue("Alle Standorte"); }); it("nimmt einen weiteren Wert dazu", async () => { const onChange = zeige(["l1"]); await userEvent.setup().selectOptions(screen.getByRole("combobox", { name: "Standort" }), "l3"); expect(onChange).toHaveBeenCalledWith(["l1", "l3"]); }); it("bietet Gewähltes nicht noch einmal an und entfernt es über den Chip", async () => { const onChange = zeige(["l1", "l2"]); expect(screen.queryByRole("option", { name: "Wien" })).not.toBeInTheDocument(); await userEvent.setup().click(screen.getByRole("button", { name: "Wien entfernen" })); expect(onChange).toHaveBeenCalledWith(["l2"]); }); });