import { INVESTIGATION_DEV_NETWORK } from "../utils/investigation-dev-network"; import { parseInvestigationDevJsonl } from "../utils/investigation-dev-preview"; import { cleanup, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterEach, describe, expect, it, vi } from "vitest"; import "@/test/radix-select-test-setup"; import { createInvestigationDevCase } from "../utils/investigation-dev-cases"; import { InvestigationDevTools } from "./investigation-dev-tools"; afterEach(cleanup); describe("investigation Dev case selection", () => { it("previews a loaded case in one click without an investigation or separate validation step", async () => { const user = userEvent.setup(); const onPreview = vi.fn(); render( createInvestigationDevCase(id)} onPreview={onPreview} onClear={vi.fn()} /> ); const cases = screen.getByRole("combobox", { name: "JSONL 测试案例" }); expect(cases).toBeEnabled(); await user.click(cases); await user.click(screen.getByRole("option", { name: "候选管段对比" })); expect((screen.getByLabelText("调查展示 JSONL") as HTMLTextAreaElement).value).toContain( INVESTIGATION_DEV_NETWORK.pipeIds[0] ); const execute = screen.getByRole("button", { name: "执行本地预览" }); expect(execute).toBeEnabled(); await user.click(execute); expect(onPreview).toHaveBeenCalledWith( expect.objectContaining({ commands: [] }), expect.any(String) ); expect(onPreview).toHaveBeenCalledWith( parseInvestigationDevJsonl(createInvestigationDevCase("candidates_table")), "候选管段对比" ); expect(screen.getByRole("status")).toHaveTextContent("本地预览完成"); expect(screen.queryByText("合成候选管段对比")).not.toBeInTheDocument(); await user.click(screen.getByRole("button", { name: "载入合成样例" })); expect(cases).toHaveTextContent("候选管段对比"); expect(screen.queryByRole("status")).not.toBeInTheDocument(); }); it("previews data without a map but waits before executing map commands", async () => { const user = userEvent.setup(); const onPreview = vi.fn(); render( ); const input = screen.getByLabelText("调查展示 JSONL"); await user.click(input); await user.paste(createInvestigationDevCase("data_only")); await user.click(screen.getByRole("button", { name: "校验 JSONL" })); const execute = screen.getByRole("button", { name: "执行本地预览" }); expect(execute).toBeEnabled(); await user.click(execute); expect(onPreview).toHaveBeenCalledWith( expect.objectContaining({ commands: [] }), expect.any(String) ); await user.clear(input); await user.paste(createInvestigationDevCase("impact_area")); await user.click(screen.getByRole("button", { name: "校验 JSONL" })); expect(execute).toBeEnabled(); await user.click(execute); expect(screen.getByRole("alert")).toHaveTextContent("地图尚未就绪"); expect(onPreview).toHaveBeenCalledTimes(1); }); it.each(["invalid_json", "invalid_command", "invalid_chart"] as const)( "validates %s on execute and never runs a partial batch", async (id) => { const user = userEvent.setup(); const onPreview = vi.fn(); render( createInvestigationDevCase(caseId)} onPreview={onPreview} onClear={vi.fn()} /> ); const input = screen.getByLabelText("调查展示 JSONL"); await user.click(input); await user.paste(createInvestigationDevCase(id)); const execute = screen.getByRole("button", { name: "执行本地预览" }); expect(execute).toBeEnabled(); await user.click(execute); expect(screen.getByRole("alert")).toHaveTextContent( id === "invalid_json" ? "第 2 行" : "第 1 行" ); expect(onPreview).not.toHaveBeenCalled(); expect(screen.queryByRole("region", { name: "JSONL 本地预览" })).not.toBeInTheDocument(); await user.clear(input); await user.paste(createInvestigationDevCase("data_only")); await user.click(execute); expect(onPreview).toHaveBeenCalledWith( expect.objectContaining({ commands: [] }), expect.any(String) ); expect(screen.queryByRole("alert")).not.toBeInTheDocument(); } ); });