import { useCallback, useEffect, useRef, useState } from "react"; import { Button, ComposedModal, InlineLoading, InlineNotification, ModalBody, ModalFooter, ModalHeader, Tag } from "@carbon/react"; import { reportToText, runSelfTest, type Check, type SelfTestReport } from "../lib/selfTest"; const STATUS_TAG: Record = { pass: { type: "green", text: "Pass" }, fail: { type: "red", text: "Fail" }, info: { type: "gray", text: "Info" }, }; /** Renders the fixtures in this webview's real render client and reports what it found. */ export default function DiagnosticsPanel({ open, onClose }: { open: boolean; onClose: () => void }) { const [report, setReport] = useState(null); const [fatal, setFatal] = useState(null); const [copied, setCopied] = useState<"ok" | "failed" | null>(null); const runId = useRef(0); const run = useCallback(async () => { const id = ++runId.current; setReport(null); setFatal(null); setCopied(null); try { // Loaded on demand: the fixtures, goldens and pdf.js are only needed here. const { browserSelfTestDeps } = await import("../lib/selfTestBrowser"); await runSelfTest(browserSelfTestDeps(), (r) => { if (runId.current === id) setReport(r); }); } catch (e) { if (runId.current === id) setFatal(e instanceof Error ? e.message : String(e)); } }, []); useEffect(() => { if (open) void run(); else runId.current++; }, [open, run]); const copy = async () => { if (!report) return; try { await navigator.clipboard.writeText(reportToText(report)); setCopied("ok"); } catch { setCopied("failed"); } }; const running = open && !fatal && !report?.done; return (

Renders two sample invoices in this app's own renderer, reads them back and compares them with the reference layouts. Nothing is saved or sent.

{fatal ? : null} {report && report.done ? ( ) : null} {report?.sections.map((section) => (

{section.title}

{section.checks.map((check, i) => (
{STATUS_TAG[check.status].text} {check.label} {check.ms !== undefined ? {check.ms} ms : null}
{check.detail ?

{check.detail}

: null}
))}
))} {running ? (
) : null} {copied ? (
) : null}
); }