feat: redesign persisted session summaries
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { server } from "../test/msw";
|
||||
@@ -73,3 +73,104 @@ test("a malformed document renders a fallback without taking down its siblings",
|
||||
expect(screen.getByText(/couldn't be displayed/i)).toBeInTheDocument();
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
test("renders the canonical summary order and formats human text as Markdown", async () => {
|
||||
server.resetHandlers(
|
||||
http.get("http://localhost:8787/sessions/s1/documents", () =>
|
||||
HttpResponse.json([
|
||||
{ phase: "—", key: "question", title: "Original question", format: "text", content: "Original **question**" },
|
||||
{ phase: "F7", key: "sql", title: "Final SQL", format: "sql", content: "SELECT 1" },
|
||||
{ phase: "finalize", key: "preview", title: "Data preview", format: "markdown", content: "| count |\n|---|\n| 42 |" },
|
||||
{ phase: "F3", key: "revised_question", title: "Revised question", format: "markdown", content: "# Domanda\n\nConta i pazienti **attivi**." },
|
||||
{ phase: "F3", key: "assumptions", title: "Assumptions", format: "markdown", content: "## Assunzioni\n\n- Solo adulti" },
|
||||
{ phase: "F8", key: "memories", title: "Memories", format: "memories", content: "[]" },
|
||||
{ phase: "F4", key: "schema_linking", title: "Schema linking", format: "schema-linking", content: '{"question":"q","candidates":[],"joins":[],"excluded":[],"open_questions":[]}' },
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
wrap(<SessionDocumentsPanel session={base} onClose={vi.fn()} onResume={vi.fn()} />);
|
||||
|
||||
const panel = await screen.findByRole("complementary", { name: /session summary/i });
|
||||
await within(panel).findByRole("heading", { name: "Original question", level: 3 });
|
||||
expect(within(panel).getAllByRole("heading", { level: 3 }).map((heading) => heading.textContent)).toEqual([
|
||||
"Original question",
|
||||
"Final SQL",
|
||||
"Data preview",
|
||||
"Revised question",
|
||||
"Assumptions",
|
||||
"Memories",
|
||||
"Schema linking",
|
||||
]);
|
||||
expect(screen.getByText("question").tagName).toBe("STRONG");
|
||||
expect(screen.getByText("attivi").tagName).toBe("STRONG");
|
||||
expect(screen.getByRole("heading", { name: "Domanda", level: 1 })).toBeInTheDocument();
|
||||
expect(screen.getByText("Solo adulti").closest("li")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders one approved-then-declined memory list with Markdown details", async () => {
|
||||
server.resetHandlers(
|
||||
http.get("http://localhost:8787/sessions/s1/documents", () =>
|
||||
HttpResponse.json([
|
||||
{
|
||||
phase: "F8",
|
||||
key: "memories",
|
||||
title: "Memories",
|
||||
format: "memories",
|
||||
content: JSON.stringify([
|
||||
{
|
||||
status: "approved",
|
||||
subject: "ablazione **valida**",
|
||||
detail: "Stato `completed`.",
|
||||
rationale: "*Confermato* dal reviewer.",
|
||||
},
|
||||
{
|
||||
status: "declined",
|
||||
subject: "paziente attivo",
|
||||
detail: "Usa `flag_attivo`.",
|
||||
rationale: "",
|
||||
},
|
||||
]),
|
||||
},
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
wrap(<SessionDocumentsPanel session={base} onClose={vi.fn()} onResume={vi.fn()} />);
|
||||
|
||||
const list = await screen.findByRole("list", { name: /memories/i });
|
||||
const items = within(list).getAllByRole("listitem");
|
||||
expect(items).toHaveLength(2);
|
||||
expect(items[0]).toHaveTextContent(/approved/i);
|
||||
expect(items[1]).toHaveTextContent(/declined/i);
|
||||
expect(within(items[0]).getByText("valida").tagName).toBe("STRONG");
|
||||
expect(within(items[0]).getByText("completed").tagName).toBe("CODE");
|
||||
expect(within(items[0]).getByText("Confermato").tagName).toBe("EM");
|
||||
expect(screen.queryByText(/memory promoted/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("never renders technical approval, promotion, or memory decisions", async () => {
|
||||
const lines = [
|
||||
{ type: "phase_approved", subject: "phase:1" },
|
||||
{ type: "table_approved", subject: "fact_a" },
|
||||
{ type: "table_promoted", subject: "fact_a" },
|
||||
{ type: "column_promoted", subject: "fact_a.id" },
|
||||
{ type: "memory_promoted", subject: "concetto" },
|
||||
{ type: "column_excluded", subject: "fact_a.note", detail: "Non **pertinente**" },
|
||||
].map((decision) => JSON.stringify(decision)).join("\n");
|
||||
server.resetHandlers(
|
||||
http.get("http://localhost:8787/sessions/s1/documents", () =>
|
||||
HttpResponse.json([
|
||||
{ phase: "—", key: "decisions", title: "Decisions", format: "decisions", content: lines },
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
wrap(<SessionDocumentsPanel session={base} onClose={vi.fn()} onResume={vi.fn()} />);
|
||||
|
||||
expect(await screen.findByText("column excluded")).toBeInTheDocument();
|
||||
expect(screen.getByText("pertinente").tagName).toBe("STRONG");
|
||||
for (const hidden of ["phase approved", "table approved", "table promoted", "column promoted", "memory promoted"]) {
|
||||
expect(screen.queryByText(hidden)).not.toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user