import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { InvestigationReportBlocks } from "./investigation-report-blocks"; import type { OperationalTask, OperationalTaskReport } from "../api/operational-task-client"; const now = "2026-10-20T08:00:00Z"; const task: Pick = { evidence: [{ evidence_id: "saved-evidence", kind: "synthetic", summary: "保存的演练压力,不代表现场事实。", source_label: "保存的监测来源", observed_at: now, recorded_at: now, recorded_by: "agent", source_ref: null, has_snapshot: false, }] }; const snapshot: OperationalTaskReport = { revision: 3, execution_generation: 2, source_session_id: "session", published_at: now, published_by: "agent", report: { title: "演练调查报告", current_conclusion: "待核验", conclusion_boundary: "演练数据", evidence_refs: ["saved-evidence"], recommendations: [], pending_items: [], ui_blocks: [{ evidence_refs: ["saved-evidence"], block: { version: "answer-ui@1", block_id: "analysis", fallback_text: "分析待核验。", spec: { root: "evidence", elements: { evidence: { type: "Evidence", children: [], props: { title: "监测依据", summary: "模型填写的错误摘要", source: "模型填写的错误来源", kind: "observed", observed_at: null, evidence_id: "saved-evidence", } } } }, }, }] }, }; describe("formal report interactive content", () => { it("uses saved evidence facts and quotes the selected report version without dispatching work", () => { const onContinue = vi.fn(); render(); fireEvent.click(screen.getByRole("button", { name: /监测依据/ })); expect(screen.getByText("保存的演练压力,不代表现场事实。")).toBeVisible(); expect(screen.queryByText(/模型填写/)).not.toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: "针对这部分提问" })); expect(onContinue).toHaveBeenCalledWith(expect.objectContaining({ context: { report_revision: 3 }, reportGeneration: 2, reference: { title: "演练调查报告 · 报告第 3 版 · 监测依据", text: expect.stringContaining("保存的监测来源\n类别:演练数据") }, })); expect(onContinue.mock.calls[0][0].reference.text).toContain("报告第 3 版 · 第 2 轮"); expect(onContinue.mock.calls[0][0].reference.text).toContain("引用依据:保存的监测来源(saved-evidence)"); }); it("keeps unsupported content readable through its fallback and renders no executable nodes", () => { const next = structuredClone(snapshot); next.report.ui_blocks![0].block.version = "answer-ui@future"; next.report.ui_blocks![0].block.spec = { type: "iframe", src: "https://example.invalid" }; const { container } = render(); expect(screen.getByText("分析待核验。")).toBeVisible(); expect(container.querySelector("iframe")).toBeNull(); }); it("turns report form input into a versioned conversation draft", async () => { const next = structuredClone(snapshot); next.report.ui_blocks![0].block.spec = { root: "form", elements: { form: { type: "FollowUpForm", children: [], props: { title: "补充资料", description: "填写核验位置", fields: [{ name: "site", label: "位置", kind: "text", required: true }] }, } } }; const onContinue = vi.fn(); render(); fireEvent.change(screen.getByLabelText("位置(必填)"), { target: { value: "演练位置" } }); fireEvent.click(screen.getByRole("button", { name: "带入对话" })); expect(await screen.findByText("资料已带入对话,请确认后发送。")).toBeVisible(); expect(onContinue.mock.calls[0][0].reference.text).toContain("位置:演练位置"); expect(onContinue.mock.calls[0][0].context).toEqual({ report_revision: 3 }); }); });