import { describe, expect, it } from "vitest"; import { renderToStaticMarkup } from "react-dom/server"; import { I18nProvider } from "@/lib/i18n/context"; import type { InboundDocumentDto } from "@/lib/validations/inbound-documents"; import { DocumentCard, UploadStateCard } from "../document-card"; import type { UploadQueueItem } from "../use-document-upload"; /** * The vault card's render contract: title falls back filename → "untitled", * the meta line stays muted, the attachment-class badge appears ONLY for * download-only formats, condition links paint as pills, and the two * transient upload cards (in-flight ring / translated failure) render from * the same footprint. */ function doc(overrides: Partial = {}): InboundDocumentDto { return { id: "doc-1", kind: "IMAGING", title: "MRT Knie", filename: "mrt-knie.pdf", mimeType: "application/pdf", byteSize: 2_500_000, status: "STORED", providerType: null, reportDate: null, documentDate: "2025-10-04", errorReason: null, factCount: 0, pendingCount: 0, conditionLinks: [{ episodeId: "ep-knee", name: "Knie" }], servingClass: "inline", hasContentIndex: false, createdAt: "2025-10-05T08:00:00.000Z", updatedAt: "2025-10-05T08:00:00.000Z", ...overrides, }; } function render(node: React.ReactNode) { return renderToStaticMarkup( {node}, ); } const noop = () => {}; describe("", () => { it("renders title, condition pill, and NO attachment badge for inline docs", () => { const html = render( , ); expect(html).toContain("MRT Knie"); expect(html).toContain("Knie"); expect(html).toContain('data-document-id="doc-1"'); expect(html).not.toContain("Download only"); }); it("shows the download-only badge for attachment-class documents", () => { const html = render( , ); expect(html).toContain("Download only"); // Title falls back to the filename. expect(html).toContain("befund.docx"); }); it("falls back to the untitled label and rings when highlighted", () => { const html = render( , ); expect(html).toContain("Untitled document"); expect(html).toContain("ring-2"); }); }); describe("", () => { const base: UploadQueueItem = { localId: "u1", fileName: "scan.jpg", byteSize: 4_000_000, status: "uploading", progress: 0.4, }; it("paints the progress ring while uploading", () => { const html = render(); expect(html).toContain('role="progressbar"'); expect(html).toContain('aria-valuenow="40"'); expect(html).toContain("scan.jpg"); }); it("renders the translated over-limit reason with the configured cap", () => { const html = render( , ); expect(html).toContain('role="alert"'); expect(html).toContain("25 MB"); expect(html).not.toContain('role="progressbar"'); }); it("renders the quota reason with used/quota figures", () => { const html = render( , ); expect(html).toContain("Storage is full"); expect(html).toContain("1 GB"); }); });