// Guards the contract the Gruppen tab relies on after "Gruppe erstellen" moved // from a slide-over sub-page into a popup: the dialog reports name, description, // colour and the picked members, and it defaults to a real colour — the old // slide-over let an empty select post NaN into the group's colour column. import { fireEvent, render, screen } from "@testing-library/react"; import "@testing-library/jest-dom/vitest"; import { describe, expect, it, vi } from "vitest"; import { Colors } from "~/application/enums/shared/Colors"; import { GroupNewDialog, type GroupNewInput } from "./GroupNewDialog"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }), })); const CANDIDATES = [ { userId: "u1", name: "Birgit Büro", email: "buero@hivegrid.de" }, { userId: "u2", name: "Murat Monteur", email: "monteur@hivegrid.de" }, ]; function renderDialog() { const onCreate = vi.fn<(input: GroupNewInput) => void>(); render( undefined} candidates={CANDIDATES} submitting={false} onCreate={onCreate} />); return { onCreate }; } function submitButton(): HTMLButtonElement { return document.querySelector("[data-ui-id='ui.settings.groups.newDialog.submit']") as HTMLButtonElement; } describe("GroupNewDialog", () => { it("reports name, description, default colour and the picked members", () => { const { onCreate } = renderDialog(); fireEvent.change(screen.getByLabelText("models.group.name"), { target: { value: " Montage Nord " } }); fireEvent.change(screen.getByLabelText("models.group.description"), { target: { value: " Team Nord " } }); fireEvent.click(screen.getByText("Murat Monteur")); fireEvent.click(submitButton()); expect(onCreate).toHaveBeenCalledWith({ name: "Montage Nord", description: "Team Nord", color: Colors.BLUE, userIds: ["u2"], }); }); it("keeps the submit disabled without a name", () => { renderDialog(); expect(submitButton()).toBeDisabled(); fireEvent.change(screen.getByLabelText("models.group.name"), { target: { value: "Montage Nord" } }); expect(submitButton()).not.toBeDisabled(); }); });