// R-P8a interim-UI (AD-28) — ProjektDetailPage unit test. Fixture built via the // real buildProjektDetailVM / buildActivityStreamVM; interactions asserted on the // injected onSubmit callback. i18n mocked so `t` echoes the key. import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { buildActivityStreamVM, buildProjektDetailVM, type BuildProjektDetailVMInput, type ProjektDetailData } from "@hivegrid/view-models"; import { ProjektDetailPage, type ProjektDetailPageActions } from "./ProjektDetailPage"; const byUiId = (id: string) => document.querySelector(`[data-ui-id='${id}']`) as HTMLElement; /** S02 contacts fold; their details only exist in the DOM while a row is open. */ const openContact = (contactId: string) => fireEvent.click(byUiId(`ui.projects.detail.contacts.${contactId}.trigger`)); /** The three ways to add a contact hang behind one button. */ const openAddContactMenu = () => fireEvent.keyDown(byUiId("ui.projects.detail.contacts.add.trigger"), { key: "ArrowDown" }); /** Address slots fold like contacts; their fields only exist while open. */ const openAddressSlot = (slot: string) => fireEvent.click(byUiId(`ui.projects.detail.addresses.${slot}.trigger`)); const openRailArea = (area: string) => fireEvent.click(byUiId(`ui.projects.detail.rail.tab.${area}`)); vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (s: string) => s, i18n: { language: "de" } }), })); const NOW = "2026-07-08T12:00:00.000Z"; const emptyActivity = buildActivityStreamVM({ rows: [], userLabels: new Map(), hasMore: false }); function baseInput(over: Partial = {}): BuildProjektDetailVMInput { return { project: { id: "p1", projektNummer: "P-00001", projektname: "Dach Nord", beschreibung: null, prioritaet: "normal", stageId: "s1", startDatumIso: null, deadlineIso: null, zustaendigePersonId: null, projektleiterId: null, konvertiertAusLeadId: null, wonAtIso: null, lostAtIso: null, undoStageChangeUntilIso: null, lostReasonId: null, }, pipelineName: "Sales", pipelineTypHint: "sales", stages: [ { id: "s1", name: "Neu", stageKind: "offen", winProbability: 10, color: "#000" }, { id: "s2", name: "Angebot", stageKind: "offen", winProbability: 60, color: "#111" }, { id: "s3", name: "Gewonnen", stageKind: "gewonnen", winProbability: 100, color: "#0a0" }, { id: "s4", name: "Verloren", stageKind: "verloren", winProbability: 0, color: "#a00" }, ], kontakte: [], lostReasons: [{ id: "lr1", name: "Preis" }], value: "10000.00", orderVolume: "20000.00", valueVisible: true, ownerLabel: null, projektleiterLabel: null, mitglieder: [], adressen: { projekt: null, rechnung: null, bauherr: null }, perms: { canWrite: true, canChangeStage: true, canInviteToPortal: true, canManageMembers: true }, nowIso: NOW, ...over, }; } type KontaktInput = BuildProjektDetailVMInput["kontakte"][number]; function kontakt(over: Partial = {}): KontaktInput { return { id: "project-contact-1", kontaktId: "contact-1", kontaktTyp: "privatperson", rolle: "auftraggeber", primaer: true, label: "Ada Lovelace", email: null, telefon: null, detailHref: null, portalInviteEligible: true, stammdaten: [], lastContactAtIso: null, ...over, }; } function data(over: Partial = {}): ProjektDetailData { const vm = buildProjektDetailVM(baseInput(over)); if (vm.status !== "ready") throw new Error("fixture not ready"); return vm.data; } function renderPage(props: Partial[0]> = {}) { const acts: ProjektDetailPageActions = props.actions ?? { onSubmit: vi.fn() }; render( ); return acts; } describe("ProjektDetailPage", () => { it("renders the project number, name and stages", () => { renderPage(); // Number/stage name also appear in the edit-mode system boxes. expect(screen.getAllByText("P-00001").length).toBeGreaterThan(0); expect(screen.getAllByText("Dach Nord").length).toBeGreaterThan(0); expect(screen.getAllByText("Neu").length).toBeGreaterThan(0); fireEvent.keyDown(byUiId("ui.projects.detail.status.trigger"), { key: "ArrowDown" }); expect(screen.getByText("Gewonnen")).toBeTruthy(); }); it("submits stammdaten via onSubmit", () => { const acts = renderPage(); fireEvent.click(byUiId("ui.projects.detail.stammdaten.save")); expect(acts.onSubmit).toHaveBeenCalledWith("updateStammdaten", expect.objectContaining({ projektname: "Dach Nord", prioritaet: "normal" })); }); it("puts save in the header and keeps Grunddaten to the export's fields", () => { renderPage(); // S02: the single save path lives in the header, not in a banner above the // fields, so it stays reachable while scrolling through the sections. expect(byUiId("ui.projects.detail.header").contains(byUiId("ui.projects.detail.stammdaten.save"))).toBe(true); // Project id, board, board column and outcome were four grey "System" boxes // at the end of Grunddaten. They repeat the header and the status field, and // the export has no such boxes. expect(byUiId("ui.projects.detail.systemFields")).toBeNull(); expect(byUiId("ui.projects.detail.system.projectId")).toBeNull(); // Priority is a coloured badge picker, like the export's. expect(byUiId("ui.projects.detail.priority.current").textContent).toBe("projects.priority.normal"); }); it("offers the S02 quick-action bar with the direct call and mail actions", () => { renderPage({ data: data({ project: { ...baseInput().project, telefon: "+49 761 1", email: "bau@example.test" } }), quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile: vi.fn() }, }); const bar = byUiId("ui.projects.detail.quickActions"); expect(bar).toBeTruthy(); // Anrufen and E-Mail are direct actions, the four others open a modal. expect(bar.contains(byUiId("ui.projects.detail.quickActions.call"))).toBe(true); expect(bar.contains(byUiId("ui.projects.detail.quickActions.mail"))).toBe(true); for (const action of ["appointment", "task", "note", "file"]) { expect(bar.contains(byUiId(`ui.projects.detail.quickActions.${action}`))).toBe(true); } }); it("keeps call and mail in place but disabled when the project carries neither", () => { renderPage({ quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile: vi.fn() } }); // The bar keeps its six buttons in the export's order; a missing number // disables the button rather than moving the five next to it. expect((byUiId("ui.projects.detail.quickActions.call") as HTMLButtonElement).disabled).toBe(true); expect((byUiId("ui.projects.detail.quickActions.mail") as HTMLButtonElement).disabled).toBe(true); }); it("hides save and the system boxes without write permission", () => { renderPage({ data: data({ perms: { canWrite: false, canChangeStage: false } }) }); expect(byUiId("ui.projects.detail.stammdaten.save")).toBeNull(); expect(byUiId("ui.projects.detail.systemFields")).toBeNull(); }); it("keeps the header to the export's three controls", () => { renderPage(); const header = byUiId("ui.projects.detail.header"); // Project id, the way back to the board and save — nothing else. A cancel // button next to save is not part of S02. expect(header.contains(byUiId("ui.projects.detail.header.projectId"))).toBe(true); expect(header.contains(byUiId("ui.projects.detail.header.board.link"))).toBe(true); expect(header.contains(byUiId("ui.projects.detail.stammdaten.save"))).toBe(true); expect(byUiId("ui.projects.detail.stammdaten.cancel")).toBeNull(); // The board this project sits on reads as the line under its name. expect(byUiId("ui.projects.detail.header.board").textContent).toBe("Sales"); }); it("formats the read-only project value as euros", () => { renderPage({ data: data({ perms: { canWrite: false, canChangeStage: false, canInviteToPortal: false } }) }); expect((document.body.textContent ?? "").replace(/[\u00a0\u202f]/g, " ")).toContain("10.000,00 €"); }); it("keeps editable monetary inputs as raw decimal values", () => { renderPage(); expect(screen.getByDisplayValue("10000.00").getAttribute("type")).toBe("number"); expect(screen.getByDisplayValue("20000.00").getAttribute("type")).toBe("number"); }); it("submits the project leader together with the other stammdaten", () => { const acts = renderPage({ ownerOptions: [{ id: "u9", label: "Lea Leiter" }] }); fireEvent.click(byUiId("ui.projects.detail.stammdaten.save")); expect(acts.onSubmit).toHaveBeenCalledWith("updateStammdaten", expect.objectContaining({ projektleiterId: "" })); }); it("adds and removes S02 members through the two people pickers", () => { const acts = renderPage({ ownerOptions: [ { id: "u9", label: "Lea Leiter" }, { id: "u8", label: "Mo Monteur" }, ], data: data({ mitglieder: [{ id: "m1", userId: "u8", rolle: "monteur", label: "Mo Monteur" }] }), }); // A user who is not a member yet is added with the picker's role... fireEvent.keyDown(byUiId("ui.projects.detail.members.zustaendig.trigger"), { key: "ArrowDown" }); fireEvent.click(byUiId("ui.projects.detail.members.zustaendig.option.u9")); expect(acts.onSubmit).toHaveBeenCalledWith("addMember", { userId: "u9", rolle: "zustaendig" }); // ...and an existing member row is removed by its member id, not its user id. fireEvent.keyDown(byUiId("ui.projects.detail.members.monteur.trigger"), { key: "ArrowDown" }); fireEvent.click(byUiId("ui.projects.detail.members.monteur.option.u8")); expect(acts.onSubmit).toHaveBeenCalledWith("removeMember", { memberId: "m1" }); }); it("shows the members as plain names without a picker when the actor cannot manage members", () => { renderPage({ ownerOptions: [{ id: "u8", label: "Mo Monteur" }], data: data({ mitglieder: [{ id: "m1", userId: "u8", rolle: "monteur", label: "Mo Monteur" }], perms: { canWrite: true, canChangeStage: true, canInviteToPortal: true, canManageMembers: false }, }), }); expect(byUiId("ui.projects.detail.members.monteur.value").textContent).toBe("Mo Monteur"); expect(byUiId("ui.projects.detail.members.monteur.trigger")).toBeNull(); }); it("drops the single owner select in favour of the people multi-select", () => { renderPage({ ownerOptions: [{ id: "u9", label: "Lea Leiter" }] }); // "Zuständig" held one name and said the same thing as "Zuständige // Personen"; only the multi-select survives. expect(byUiId("ui.projects.detail.field.owner")).toBeNull(); expect(byUiId("ui.projects.detail.members.zustaendig.trigger")).toBeTruthy(); expect(byUiId("ui.projects.detail.field.projectLeader")).toBeTruthy(); }); it("moves directly to an open stage", () => { const acts = renderPage(); fireEvent.keyDown(byUiId("ui.projects.detail.status.trigger"), { key: "ArrowDown" }); fireEvent.click(byUiId("ui.projects.detail.stage.s2")); expect(acts.onSubmit).toHaveBeenCalledWith("moveStage", { targetStageId: "s2" }); }); it("invites a linked contact from a sales project through the project-contact action", () => { const acts = renderPage({ data: data({ pipelineTypHint: "sales", kontakte: [kontakt()], }), }); openContact("project-contact-1"); fireEvent.click(byUiId("ui.projects.detail.contacts.project-contact-1.portalInvite")); expect(acts.onSubmit).toHaveBeenCalledWith("invitePortalProjectContact", { contactId: "contact-1" }); }); it("splits the S02 contacts accordion into a company card and the person cards", () => { renderPage({ data: data({ kontakte: [ kontakt({ id: "pc-person", kontaktId: "c-person", primaer: true, label: "Ada Lovelace", telefon: "+49 761 2" }), kontakt({ id: "pc-firma", kontaktId: "c-firma", kontaktTyp: "organisation", rolle: "auftraggeber", primaer: false, label: "Weber GmbH", email: "info@weber.test", detailHref: "/acme/contacts/companies/c-firma", portalInviteEligible: false, }), ], }), }); expect(byUiId("ui.projects.detail.contacts.pc-firma").textContent).toContain("projects.detail.contacts.company"); // The pencil leads to the record in the CRM, which owns contact master data. expect(byUiId("ui.projects.detail.contacts.pc-firma.open").getAttribute("href")).toBe("/acme/contacts/companies/c-firma"); openContact("pc-firma"); expect(byUiId("ui.projects.detail.contacts.pc-firma.email").textContent).toContain("info@weber.test"); // The primary link is the first person card, whatever order the loader used. expect(byUiId("ui.projects.detail.contacts.pc-person").textContent).toContain("projects.detail.contacts.primaryPerson"); openContact("pc-person"); expect(byUiId("ui.projects.detail.contacts.pc-person.telefon").textContent).toContain("+49 761 2"); }); it("shows the KWP block read-only for a bound project and not at all otherwise", () => { renderPage(); expect(byUiId("ui.projects.detail.kwp")).toBeNull(); renderPage({ data: data({ kwp: { externalProjectNumber: "2026-0815", statusLabel: "In Bearbeitung", lastSyncedAtIso: "2026-07-08T10:00:00.000Z" } }), }); const block = byUiId("ui.projects.detail.kwp"); expect(block.textContent).toContain("2026-0815"); expect(block.textContent).toContain("In Bearbeitung"); // Abteilungsnummer and Sachbearbeiter are drawn by the export, but the // inbound contract carries neither — a row that can never fill is out. expect(byUiId("ui.projects.detail.kwp.departmentNumber")).toBeNull(); expect(byUiId("ui.projects.detail.kwp.agent")).toBeNull(); // KWP is an inbound mirror: no field in this block may be writable. expect(block.querySelector("input")).toBeNull(); }); it("shows the contact master data the loader resolved on the card", () => { renderPage({ data: data({ kontakte: [ kontakt({ id: "pc-firma", kontaktTyp: "organisation", label: "Weber GmbH", stammdaten: [ { labelKey: "projects.detail.contacts.vatId", value: "DE123456789" }, { labelKey: "projects.detail.contacts.industry", value: "SHK" }, ], }), ], }), }); openContact("pc-firma"); expect(byUiId("ui.projects.detail.contacts.pc-firma.stammdaten.vatId").textContent).toContain("DE123456789"); expect(byUiId("ui.projects.detail.contacts.pc-firma.stammdaten.industry").textContent).toContain("SHK"); }); it("shows the derived last contact only when the timeline has one", () => { renderPage({ data: data({ kontakte: [kontakt({ id: "pc-1" })] }) }); openContact("pc-1"); expect(byUiId("ui.projects.detail.contacts.pc-1.lastContact")).toBeNull(); renderPage({ data: data({ kontakte: [kontakt({ id: "pc-2", lastContactAtIso: "2026-07-08T10:00:00.000Z" })] }) }); openContact("pc-2"); expect(byUiId("ui.projects.detail.contacts.pc-2.lastContact")).toBeTruthy(); }); it("saves the three S02 address slots and clears the ones left switched off", () => { const acts = renderPage({ data: data({ adressen: { projekt: { strasse: "Hauptstr.", hausnummer: "1", plz: "79098", ort: "Freiburg", land: "DE" }, rechnung: { strasse: "Rechnungsweg", hausnummer: "9", plz: "79100", ort: "Freiburg", land: "DE", zahlungsziel: "30 Tage" }, bauherr: null, }, }), }); // Each slot ships collapsed, like the export. openAddressSlot("projekt"); fireEvent.change(byUiId("ui.projects.detail.addresses.projekt.ort"), { target: { value: "Emmendingen" } }); // A slot extra rides along in the same payload as the address itself. fireEvent.change(byUiId("ui.projects.detail.addresses.projekt.zufahrt"), { target: { value: "Hofeinfahrt links" } }); // Switching the invoice slot off must clear it, not keep the old row. The // switch sits in the project address, which is the row already open. fireEvent.click(byUiId("ui.projects.detail.addresses.rechnung.toggle")); fireEvent.click(byUiId("ui.projects.detail.addresses.projekt.save")); const [[, fields]] = (acts.onSubmit as ReturnType).mock.calls.slice(-1); const slots = JSON.parse((fields as { slots: string }).slots); expect(slots.projekt).toMatchObject({ ort: "Emmendingen", zufahrt: "Hofeinfahrt links" }); expect(slots.rechnung).toBeNull(); expect(slots.bauherr).toBeNull(); }); it("only offers a slot the extras that belong to it", () => { renderPage({ data: data({ adressen: { projekt: { strasse: "Hauptstr.", hausnummer: "1", plz: "79098", ort: "Freiburg", land: "DE" }, rechnung: { strasse: "Rechnungsweg", hausnummer: "9", plz: "79100", ort: "Freiburg", land: "DE" }, bauherr: { strasse: "Bauherrweg", hausnummer: "3", plz: "79101", ort: "Freiburg", land: "DE" }, }, }), }); for (const slot of ["projekt", "rechnung", "bauherr"]) openAddressSlot(slot); // Site access belongs to the project address, payment terms to the invoice // one, and the postal-mail switch to the building owner. expect(byUiId("ui.projects.detail.addresses.projekt.zufahrt")).toBeTruthy(); expect(byUiId("ui.projects.detail.addresses.rechnung.zufahrt")).toBeNull(); expect(byUiId("ui.projects.detail.addresses.rechnung.zahlungsziel")).toBeTruthy(); expect(byUiId("ui.projects.detail.addresses.projekt.zahlungsziel")).toBeNull(); expect(byUiId("ui.projects.detail.addresses.bauherr.postErwuenscht")).toBeTruthy(); expect(byUiId("ui.projects.detail.addresses.projekt.postErwuenscht")).toBeNull(); // Invoice mail only on the invoice slot, the on-site contact only on the // building owner's — a slot must not offer a field nobody would fill there. expect(byUiId("ui.projects.detail.addresses.rechnung.rechnungsEmail")).toBeTruthy(); expect(byUiId("ui.projects.detail.addresses.projekt.rechnungsEmail")).toBeNull(); expect(byUiId("ui.projects.detail.addresses.bauherr.ansprechpartnerVorOrt")).toBeTruthy(); expect(byUiId("ui.projects.detail.addresses.rechnung.ansprechpartnerVorOrt")).toBeNull(); // The note is the one extra every slot has. for (const slot of ["projekt", "rechnung", "bauherr"]) { expect(byUiId(`ui.projects.detail.addresses.${slot}.notizen`)).toBeTruthy(); } }); it("saves a slot note together with its address instead of through a second intent", () => { const acts = renderPage({ data: data({ adressen: { projekt: { strasse: "Hauptstr.", hausnummer: "1", plz: "79098", ort: "Freiburg", land: "DE" }, rechnung: null, bauherr: null, }, }), }); openAddressSlot("projekt"); fireEvent.change(byUiId("ui.projects.detail.addresses.projekt.notizen"), { target: { value: "Anlieferung nur 7-16 Uhr" } }); fireEvent.click(byUiId("ui.projects.detail.addresses.projekt.save")); const [[intent, fields]] = (acts.onSubmit as ReturnType).mock.calls.slice(-1); expect(intent).toBe("updateAddresses"); expect(JSON.parse((fields as { slots: string }).slots).projekt.notizen).toBe("Anlieferung nur 7-16 Uhr"); }); it("gives each typed number its own row and shows the contact's address", () => { renderPage({ data: data({ kontakte: [ kontakt({ telefon: "+49 761 1", durchwahl: "+49 761 117", mobil: "+49 170 2", fax: "+49 761 199", adresseLabel: "Lindenweg 14, 79110 Freiburg", }), ], }), }); openContact("project-contact-1"); expect(byUiId("ui.projects.detail.contacts.project-contact-1.durchwahl").textContent).toContain("+49 761 117"); expect(byUiId("ui.projects.detail.contacts.project-contact-1.mobil").textContent).toContain("+49 170 2"); expect(byUiId("ui.projects.detail.contacts.project-contact-1.fax").textContent).toContain("+49 761 199"); expect(byUiId("ui.projects.detail.contacts.project-contact-1.adresse").textContent).toContain("Lindenweg 14, 79110 Freiburg"); }); it("leaves out a typed number the contact does not have instead of rendering an empty row", () => { renderPage({ data: data({ kontakte: [kontakt({ telefon: "+49 761 1" })] }) }); openContact("project-contact-1"); expect(byUiId("ui.projects.detail.contacts.project-contact-1.telefon")).toBeTruthy(); expect(byUiId("ui.projects.detail.contacts.project-contact-1.durchwahl")).toBeNull(); expect(byUiId("ui.projects.detail.contacts.project-contact-1.mobil")).toBeNull(); expect(byUiId("ui.projects.detail.contacts.project-contact-1.adresse")).toBeNull(); }); it("shows the contact note as its own block, keeping the author's line breaks", () => { renderPage({ data: data({ kontakte: [kontakt({ notizen: "Entscheider für Budget.\nRuft lieber vormittags an." })], }), }); openContact("project-contact-1"); const block = byUiId("ui.projects.detail.contacts.project-contact-1.notizen"); expect(block).toBeTruthy(); expect(block.textContent).toContain("Entscheider für Budget."); expect(block.textContent).toContain("Ruft lieber vormittags an."); }); it("lists the project documents in the S02 rail grouped by their upload category", () => { renderPage({ documents: [ { id: "f1", name: "Angebot.pdf", mimeType: "application/pdf", sizeLabel: "1 MB", linkRole: "angebot", href: "/acme/files/f1" }, { id: "f2", name: "Auftrag.pdf", mimeType: "application/pdf", sizeLabel: "2 MB", linkRole: "auftrag", href: "/acme/files/f2" }, ], quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile: vi.fn() }, }); expect(byUiId("ui.projects.detail.rail.files.group.angebot").textContent).toContain("Angebot.pdf"); expect(byUiId("ui.projects.detail.rail.files.f2").getAttribute("href")).toBe("/acme/files/f2"); expect(byUiId("ui.projects.detail.rail.upload")).toBeTruthy(); }); it("keeps the rail upload out of reach without the quick actions", () => { renderPage(); expect(byUiId("ui.projects.detail.rail")).toBeTruthy(); expect(byUiId("ui.projects.detail.rail.upload")).toBeNull(); expect(byUiId("ui.projects.detail.rail.dropzone")).toBeNull(); }); it("links a file dropped on the pipeline panel without opening the modal", async () => { const uploadFile = vi.fn().mockResolvedValue({ id: "file-9", displayName: "Angebot.pdf" }); const acts = renderPage({ quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile } }); const file = new File(["x"], "Angebot.pdf", { type: "application/pdf" }); fireEvent.drop(byUiId("ui.projects.detail.rail.dropzone"), { dataTransfer: { files: [file] } }); await waitFor(() => expect(uploadFile).toHaveBeenCalledWith(file)); // No category dialog in between: the panel attaches, the quick action files. expect(byUiId("ui.projects.quickAction.file")).toBeNull(); const [[intent, fields]] = (acts.onSubmit as ReturnType).mock.calls.slice(-1); expect(intent).toBe("attachFile"); expect(fields).toMatchObject({ fileId: "file-9", kategorie: "sonstiges" }); }); it("says so when the panel upload failed instead of pretending it worked", async () => { const uploadFile = vi.fn().mockRejectedValue(new Error("nope")); renderPage({ quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile } }); fireEvent.drop(byUiId("ui.projects.detail.rail.dropzone"), { dataTransfer: { files: [new File(["x"], "Angebot.pdf", { type: "application/pdf" })] }, }); await waitFor(() => expect(byUiId("ui.projects.detail.rail.uploadError")).toBeTruthy()); }); it("shows clear feedback after the project invitation was queued", () => { renderPage({ messageKey: "customerPortal.invitation.sent" }); expect(byUiId("ui.projects.detail.portalInviteSuccess")).toBeTruthy(); expect(screen.getByText("customerPortal.invitation.sent")).toBeTruthy(); }); it("hides project-contact portal invitations when the loader gate is closed", () => { renderPage({ data: data({ kontakte: [kontakt()], perms: { canWrite: true, canChangeStage: true, canInviteToPortal: false, canManageMembers: true }, }), }); expect(document.querySelector("[data-ui-id$='.portalInvite']")).toBeNull(); }); it("does not move immediately when picking a verloren stage (opens the lost dialog)", () => { const acts = renderPage(); fireEvent.keyDown(byUiId("ui.projects.detail.status.trigger"), { key: "ArrowDown" }); fireEvent.click(byUiId("ui.projects.detail.stage.s4")); expect(acts.onSubmit).not.toHaveBeenCalled(); }); it("carries no custom-field group any more", () => { renderPage(); // "Individuelle Felder" is off S02; the definitions live in the pipeline // field template (S05), not in a set-form at the end of the detail page. expect(byUiId("ui.projects.detail.customFields")).toBeNull(); }); it("shows a won outcome with an undo button and fires undoStage", () => { const acts = renderPage({ data: data({ project: { ...baseInput().project, stageId: "s3", wonAtIso: NOW, undoStageChangeUntilIso: "2026-07-08T20:00:00.000Z" } }), }); fireEvent.click(byUiId("ui.projects.detail.undo")); expect(acts.onSubmit).toHaveBeenCalledWith("undoStage"); }); it("exposes click-to-call only through the optional VM and callback prop", () => { const onCall = vi.fn(); const number = { id: "phone-1", label: "Hauptkontakt", e164: "+49401234567", primary: true } as const; renderPage({ // Telephony rides in the quick-action bar next to "Anrufen" (S02 keeps the // header to project id, board and save), so the bar has to be there. quickActions: { assigneeOptions: [], canChooseInternalNote: false, uploadFile: vi.fn() }, clickToCall: { vm: { mode: "provider", numbers: [number], requiresSelection: false, reasonKey: null }, onCall, }, }); expect(byUiId("ui.projects.detail.quickActions").contains(byUiId("ui.telephony.clickToCall.open"))).toBe(true); fireEvent.click(screen.getByRole("button", { name: "telephony.clickToCall.open" })); fireEvent.click(screen.getByRole("button", { name: "telephony.clickToCall.startCall" })); expect(onCall).toHaveBeenCalledWith(number, "provider"); }); it("offers Davids three ways to add a contact, and only to a writer", () => { renderPage(); openAddContactMenu(); expect(byUiId("ui.projects.detail.contacts.add.search")).toBeTruthy(); expect(byUiId("ui.projects.detail.contacts.add.person")).toBeTruthy(); expect(byUiId("ui.projects.detail.contacts.add.company")).toBeTruthy(); cleanup(); renderPage({ data: data({ perms: { canWrite: false, canChangeStage: false, canInviteToPortal: false, canManageMembers: false } }) }); expect(byUiId("ui.projects.detail.contacts.add")).toBeNull(); }); it("links the picked contact through the link intent", async () => { const rows = [{ id: "c9", label: "Weber Immobilien GmbH", kontaktTyp: "organisation", email: "kontakt@weber.test" }]; const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ rows }) }); vi.stubGlobal("fetch", fetchMock); const acts = renderPage(); openAddContactMenu(); fireEvent.click(byUiId("ui.projects.detail.contacts.add.search")); // The search is debounced, so the result list needs the timer to elapse. await waitFor(() => expect(byUiId("ui.projects.detail.contacts.add.result.c9")).toBeTruthy()); fireEvent.click(byUiId("ui.projects.detail.contacts.add.result.c9")); const [[intent, fields]] = (acts.onSubmit as ReturnType).mock.calls.slice(-1); expect(intent).toBe("linkKontakt"); expect(fields).toMatchObject({ kontaktId: "c9" }); expect(String(fetchMock.mock.calls[0][0])).toContain("/acme/projects/p1/contact-search?q="); vi.unstubAllGlobals(); }); it("creates a company with its name and links it in one intent", () => { const acts = renderPage(); openAddContactMenu(); fireEvent.click(byUiId("ui.projects.detail.contacts.add.company")); fireEvent.change(byUiId("ui.projects.detail.contacts.add.orgName"), { target: { value: "Weber Immobilien GmbH" } }); fireEvent.click(byUiId("ui.projects.detail.contacts.add.createSubmit")); const [[intent, fields]] = (acts.onSubmit as ReturnType).mock.calls.slice(-1); expect(intent).toBe("createKontakt"); expect(fields).toMatchObject({ kontaktTyp: "organisation", orgName: "Weber Immobilien GmbH" }); }); it("keeps the create button closed until the name the type needs is there", () => { renderPage(); openAddContactMenu(); fireEvent.click(byUiId("ui.projects.detail.contacts.add.person")); // A person without a surname would be a contact nobody can find again. expect((byUiId("ui.projects.detail.contacts.add.createSubmit") as HTMLButtonElement).disabled).toBe(true); fireEvent.change(byUiId("ui.projects.detail.contacts.add.nachname"), { target: { value: "Weber" } }); expect((byUiId("ui.projects.detail.contacts.add.createSubmit") as HTMLButtonElement).disabled).toBe(false); }); it("fills all six rail areas and links only the ones whose editor lives below", () => { renderPage({ railAreas: { history: [{ id: "h1", label: "Neu → Angebot", meta: "Birgit Büro", atIso: NOW }], appointments: [{ id: "a1", label: "Aufmaß vor Ort", meta: "Murat Monteur", atIso: NOW }], tasks: [{ id: "t1", label: "Angebot schreiben", meta: "Vera Vertrieb", atIso: NOW }], notes: [{ id: "n1", label: "Kunde ruft vormittags an", meta: "Vera Vertrieb · alle", atIso: NOW }], activity: [ { id: "ac1", label: "Projekt P-00001 wurde aktualisiert.", labelKey: "activity.runtime.projects.detailsUpdated", meta: "Vera Vertrieb", atIso: NOW, }, ], }, operationsHref: "#operations", }); // The panel shows one area at a time, like the export — switch to each. const expected: Record = { history: ["h1", "Neu → Angebot"], appointments: ["a1", "Aufmaß vor Ort"], tasks: ["t1", "Angebot schreiben"], notes: ["n1", "Kunde ruft vormittags an"], activity: ["ac1", "activity.runtime.projects.detailsUpdated"], }; for (const [area, [entryId, label]] of Object.entries(expected)) { openRailArea(area); expect(byUiId(`ui.projects.detail.rail.${area}.${entryId}`).textContent).toContain(label); // Appointments and tasks are edited in the operations panel, so those two // areas point there; history, notes and activity have nothing to manage. const manage = byUiId(`ui.projects.detail.rail.${area}.manage`); expect(Boolean(manage)).toBe(area === "appointments" || area === "tasks"); } }); it("keeps the pipeline panel open, with no way to fold it away", () => { renderPage(); expect(byUiId("ui.projects.detail.rail")).toBeTruthy(); expect(byUiId("ui.projects.detail.rail.files")).toBeTruthy(); expect(byUiId("ui.projects.detail.rail.toggle")).toBeNull(); }); it("opens on the files area and keeps the other five one click away", () => { renderPage(); // Dateien is the built area of the export, and the only one with an editor. expect(byUiId("ui.projects.detail.rail.files")).toBeTruthy(); expect(byUiId("ui.projects.detail.rail.history")).toBeNull(); openRailArea("history"); expect(byUiId("ui.projects.detail.rail.files")).toBeNull(); expect(byUiId("ui.projects.detail.rail.history")).toBeTruthy(); }); it("shows a plain empty state per rail area instead of a blank panel", () => { renderPage(); openRailArea("history"); expect(byUiId("ui.projects.detail.rail.history").textContent).toContain("projects.detail.rail.historyEmpty"); }); });