import { render, screen } from "@testing-library/react";
import { ArtifactView } from "./ArtifactView";
vi.mock("./mermaid", () => ({
renderMermaid: vi.fn().mockResolvedValue(''),
}));
vi.mock("./highlight", () => ({
highlightSql: vi.fn().mockResolvedValue('
SQL
'),
}));
test("sql artifact renders the SQL text", async () => {
render();
expect(screen.getByText("SELECT 1")).toBeInTheDocument();
await screen.findByTestId("hl");
});
test("sql artifact accepts a { content } wrapper", async () => {
render();
expect(screen.getByText("SELECT 7")).toBeInTheDocument();
await screen.findByTestId("hl");
});
test("an empty artifact shows an explicit fallback instead of a blank panel", () => {
render();
expect(screen.getByText("No artifact content available.")).toBeInTheDocument();
});
test("cte_plan renders an ordered list of names", () => {
render();
expect(screen.getByText("a_cte")).toBeInTheDocument();
expect(screen.getByText("b_cte")).toBeInTheDocument();
});
test("question renders markdown headings", () => {
render();
expect(screen.getByText("Domanda")).toBeInTheDocument();
});
test("unknown object kind renders as formatted sections, never raw JSON", () => {
render(
,
);
// Humanized section labels, values as text/bullets — and NO raw JSON braces.
expect(screen.getByText("Recap")).toBeInTheDocument();
expect(screen.getByText("Chiarimenti risolti")).toBeInTheDocument();
expect(screen.getByText("finestra_temporale — 5 anni")).toBeInTheDocument();
expect(screen.queryByText(/"recap"/)).not.toBeInTheDocument();
});
test("schema_linking renders the schema viewer", async () => {
render(
,
);
expect(await screen.findByTestId("mm")).toBeInTheDocument();
});
test("cte_plan v2 dispatches to CtePlanViewer", () => {
render(
,
);
expect(screen.getByText("Filtriamo prima i pazienti idonei.")).toBeInTheDocument();
expect(screen.getByText("CTE 1/1")).toBeInTheDocument();
});
test("cte_plan v1 (legacy names list) still renders via the legacy path", () => {
render();
expect(screen.getByText("a_cte")).toBeInTheDocument();
expect(screen.getByText("b_cte")).toBeInTheDocument();
});
test("cte_result v2 dispatches to CteResultViewer", async () => {
render(
,
);
await screen.findByTestId("hl");
expect(screen.getByText("CTE 1/1")).toBeInTheDocument();
});
test("cte_result v1 (bare sql string) still renders via toSqlBlocks legacy path", async () => {
render();
await screen.findByTestId("hl");
expect(screen.queryByText("CTE")).not.toBeInTheDocument();
});
test("phase v2 dispatches to PhaseSummaryViewer", () => {
render(
,
);
expect(screen.getByText("F5 — sintesi")).toBeInTheDocument();
expect(screen.getByText("Riassunto della fase.")).toBeInTheDocument();
});
test("phase v2 tolerates the malformed open question from the latest session", () => {
render(
,
);
expect(
screen.getByText("Verificare se la condizione temporale è troppo restrittiva"),
).toBeInTheDocument();
});
test("phase v1 (no schema_version) still renders via legacy markdown/structured path", () => {
render(
,
);
expect(screen.getByText("Recap")).toBeInTheDocument();
expect(screen.getByText("Chiarimenti risolti")).toBeInTheDocument();
});