Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/components/screens/crm/KontaktNewPage.test.tsx
T

54 lines
2.2 KiB
TypeScript

// 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> = {}): KontaktNewPageActions {
return { onCheckDuplicates: vi.fn(), onCreate: vi.fn(), ...over };
}
function renderPage(props: Partial<Parameters<typeof KontaktNewPage>[0]> = {}) {
const acts = props.actions ?? actions();
render(
<KontaktNewPage
moduleActive
ownerOptions={[{ id: "u1", label: "Owner One" }]}
defaultOwnerId="u1"
backHref="/acme/contacts"
listLabelKey="crm.contacts.title"
duplicates={props.duplicates ?? null}
submitting={false}
errorKey={null}
actions={acts}
{...props}
/>,
);
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();
});
});