import "@testing-library/jest-dom"; import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { buildProjectSignaturePanelVM, signatureDocumentStatusKey, signatureProviderKey, signatureSignerStatusKey, type ProjectSignatureDocumentRow, } from "@hivegrid/view-models"; import { ProjectSignaturePanel } from "./ProjectSignaturePanel"; vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { language: "de" } }), })); const documentRow: ProjectSignatureDocumentRow = { id: "doc-1", title: "Angebot 2026", provider: "ses_selfhosted", providerKey: signatureProviderKey("ses_selfhosted"), status: "sent", statusKey: signatureDocumentStatusKey("sent"), sourcePdfFileId: "file-1", signedPdfFileId: "file-2", completionCertFileId: null, sourcePdfUrl: "/acme/media/file-1/original", signedPdfUrl: "/acme/media/file-2/original", completionCertUrl: null, sentAtIso: "2026-07-01T10:00:00.000Z", completedAtIso: null, expiresAtIso: null, signers: [ { id: "signer-1", signerName: "Erika Mustermann", signerEmail: "erika@example.test", signerRole: "kunde", status: "sent", statusKey: signatureSignerStatusKey("sent"), signedAtIso: null, lastReminderAtIso: null, }, ], }; function renderPanel(rows: ProjectSignatureDocumentRow[] = [documentRow]) { const onSubmit = vi.fn(); const vm = buildProjectSignaturePanelVM({ rows, canRead: true, canSend: true, canRevoke: true, canAdmin: false }); render(); return { onSubmit }; } describe("ProjectSignaturePanel", () => { it("renders documents with signer status rows and artifact downloads", () => { renderPanel(); expect(screen.getByText("Angebot 2026")).toBeInTheDocument(); expect(screen.getByText("signature.status.document.sent")).toBeInTheDocument(); expect(screen.getByText("Erika Mustermann")).toBeInTheDocument(); expect(screen.getByText("signature.actions.downloadSource")).toHaveAttribute("href", "/acme/media/file-1/original"); expect(screen.getByText("signature.actions.downloadSigned")).toHaveAttribute("href", "/acme/media/file-2/original"); expect(screen.queryByText("signature.actions.downloadCertificate")).not.toBeInTheDocument(); }); it("shows the empty state when no documents exist", () => { renderPanel([]); expect(screen.getByText("signature.project.empty.headline")).toBeInTheDocument(); }); it("submits a reminder directly without a confirm dialog", () => { const { onSubmit } = renderPanel(); fireEvent.click(screen.getByText("signature.actions.remind")); expect(onSubmit).toHaveBeenCalledWith("remindSignatureSigner", { signerId: "signer-1" }); }); it("revokes only after the confirm dialog is accepted", () => { const { onSubmit } = renderPanel(); fireEvent.click(screen.getByText("signature.actions.revoke")); expect(onSubmit).not.toHaveBeenCalled(); expect(screen.getByText("signature.confirm.revoke.title")).toBeInTheDocument(); fireEvent.click(screen.getByText("signature.confirm.revoke.confirm")); expect(onSubmit).toHaveBeenCalledWith("revokeSignatureDocument", { documentId: "doc-1" }); }); it("opens the preparation wizard from the header action", () => { renderPanel(); fireEvent.click(screen.getByText("signature.actions.createDraft")); expect(screen.getByText("signature.wizard.title")).toBeInTheDocument(); }); });