Files
ThothII/frontend/src/shell/AppShell.session-mgmt.test.tsx
T

46 lines
2.1 KiB
TypeScript

import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { http, HttpResponse } from "msw";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { server } from "../test/msw";
import { AppShell } from "./AppShell";
function wrap() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(<QueryClientProvider client={client}><AppShell /></QueryClientProvider>);
}
const LIST = [
{ id: "s1", status: "open", question: "Attiva uno", summary: null, created_at: "2026-01-02T00:00:00Z", updated_at: null, author: null, name: null, group: "Aritmologia", archived: false },
{ id: "s2", status: "finalized", question: "Archiviata due", summary: null, created_at: "2026-01-01T00:00:00Z", updated_at: null, author: null, name: null, group: null, archived: true },
];
beforeEach(() => {
server.use(
http.get("http://localhost:8787/sessions", () => HttpResponse.json(LIST)),
http.get("http://localhost:8787/sessions/:id/documents", () => HttpResponse.json([
{ phase: "—", key: "question", title: "Domanda originale", format: "text", content: "Attiva uno" },
])),
http.post("http://localhost:8787/sessions/:id/archive", () => new HttpResponse(null, { status: 204 })),
);
});
test("active list shows group header and hides archived sessions", async () => {
wrap();
expect(await screen.findByText("Attiva uno")).toBeInTheDocument();
expect(screen.getByText("Aritmologia")).toBeInTheDocument(); // group header
expect(screen.queryByText("Archiviata due")).not.toBeInTheDocument(); // archived hidden
});
test("opening the panel shows the session documents", async () => {
wrap();
await userEvent.click(await screen.findByText("Attiva uno"));
expect(await screen.findByText("Domanda originale")).toBeInTheDocument();
});
test("Archive toggle reveals archived sessions", async () => {
wrap();
await userEvent.click(await screen.findByRole("button", { name: /archive/i }));
expect(await screen.findByText("Archiviata due")).toBeInTheDocument();
});