// R-P6 interim-UI (AD-28) — KontaktNewPage unit test. Pure props (no VM); asserts // the create/duplicate-check callbacks and the duplicate banner. i18n mocked. import { fireEvent, render } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { KontaktNewPage, type KontaktNewPageActions } from "./KontaktNewPage"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }) })); function actions(over: Partial = {}): KontaktNewPageActions { return { onCheckDuplicates: vi.fn(), onCreate: vi.fn(), ...over }; } function renderPage(props: Partial[0]> = {}) { const acts = props.actions ?? actions(); render( , ); return acts; } describe("KontaktNewPage", () => { it("creates a contact with the typed fields", () => { const onCreate = vi.fn(); renderPage({ actions: actions({ onCreate }) }); fireEvent.change(document.querySelector("[data-ui-id='ui.crm.new.vorname']")!, { target: { value: "Anna" } }); fireEvent.click(document.querySelector("[data-ui-id='ui.crm.new.submit']")!); expect(onCreate).toHaveBeenCalledWith(expect.objectContaining({ kontaktTyp: "privatperson", vorname: "Anna", zustaendigerUserId: "u1" })); }); it("runs the live duplicate check on blur", () => { const onCheckDuplicates = vi.fn(); renderPage({ actions: actions({ onCheckDuplicates }) }); fireEvent.blur(document.querySelector("[data-ui-id='ui.crm.new.email']")!); expect(onCheckDuplicates).toHaveBeenCalledTimes(1); }); it("shows the hard-duplicate banner", () => { renderPage({ duplicates: { hard: [{ id: "k9", displayName: "Anna Muster", primaerEmail: "a@b.de", primaerTelefon: null, detailHref: "/acme/contacts/k9" }], soft: [] } }); expect(document.querySelector("[data-ui-id='ui.crm.new.duplicates.hard']")).not.toBeNull(); }); });