// R-P6 interim-UI (AD-28) — DuplicateToolPage unit test. Fixture VM via the real // buildDuplicateVM; asserts the pairs render side-by-side + the empty state. Read- // only screen (no actions). i18n mocked. import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { buildDuplicateVM, type DuplicateCardSource } from "@hivegrid/view-models"; import { DuplicateToolPage } from "./DuplicateToolPage"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }) })); function card(id: string, name: string): DuplicateCardSource { return { id, kontaktTyp: "privatperson", kontaktStatus: "kontakt", vorname: name, nachname: "Muster", orgName: null, primaerEmail: "same@example.com", primaerTelefon: null, zustaendigerUserId: null, createdAt: new Date("2026-06-01T10:00:00.000Z"), }; } const withPair = buildDuplicateVM({ pairs: [{ matchType: "hard", matchReason: "email", a: card("k1", "Anna"), b: card("k2", "Anna") }], userLabels: new Map(), canMerge: false, tenantSlug: "acme", }); const empty = buildDuplicateVM({ pairs: [], userLabels: new Map(), canMerge: false, tenantSlug: "acme" }); describe("DuplicateToolPage", () => { it("renders a side-by-side candidate pair", () => { render( `/acme/contacts/${id}`} />); expect(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.list']")).not.toBeNull(); expect(screen.getAllByText("Anna Muster").length).toBe(2); }); it("shows the empty state when no duplicates", () => { render( `/acme/contacts/${id}`} />); expect(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.empty']")).not.toBeNull(); }); it("hides the delete affordance without crm.delete", () => { render( `/acme/contacts/${id}`} actions={{ onDelete: vi.fn() }} />); expect(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.k1']")).toBeNull(); }); it("confirms before deleting: opens the dialog, then reports the confirmed id", () => { const onDelete = vi.fn(); render( `/acme/contacts/${id}`} actions={{ onDelete }} />); // The dialog stays closed until the row's delete icon is pressed. expect(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.dialog']")).toBeNull(); fireEvent.click(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.k1']")!); expect(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.dialog']")).not.toBeNull(); // Nothing is deleted just by opening the confirm. expect(onDelete).not.toHaveBeenCalled(); fireEvent.click(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.confirm']")!); expect(onDelete).toHaveBeenCalledWith("k1"); }); it("cancels without deleting", () => { const onDelete = vi.fn(); render( `/acme/contacts/${id}`} actions={{ onDelete }} />); fireEvent.click(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.k2']")!); fireEvent.click(document.querySelector("[data-ui-id='ui.crm.admin.duplicates.delete.cancel']")!); expect(onDelete).not.toHaveBeenCalled(); }); });