37 lines
1.9 KiB
TypeScript
37 lines
1.9 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { NavSessions } from "./NavSessions";
|
|
import type { SessionSummary } from "../api/types";
|
|
|
|
const SESSIONS: SessionSummary[] = [
|
|
{ id: "s1", status: "open", question: "Come va?", summary: null, created_at: "2026-01-01T00:00:00Z", updated_at: null, author: null, name: null, group: null, archived: false },
|
|
{ id: "s2", status: "closed", question: "Seconda domanda", summary: "r", created_at: "2026-01-02T00:00:00Z", updated_at: null, author: null, name: "Etichetta", group: null, archived: false },
|
|
];
|
|
|
|
test("lists sessions and shows name when present", () => {
|
|
render(<NavSessions sessions={SESSIONS} activeSessionId={null} onOpenPanel={vi.fn()} menuFor={() => null} />);
|
|
expect(screen.getByText("Come va?")).toBeInTheDocument();
|
|
expect(screen.getByText("Etichetta")).toBeInTheDocument(); // name overrides question
|
|
});
|
|
|
|
test("clicking a row opens the panel (does not resume)", async () => {
|
|
const onOpenPanel = vi.fn();
|
|
render(<NavSessions sessions={SESSIONS} activeSessionId={null} onOpenPanel={onOpenPanel} menuFor={() => null} />);
|
|
await userEvent.click(screen.getByText("Come va?"));
|
|
expect(onOpenPanel).toHaveBeenCalledWith("s1");
|
|
});
|
|
|
|
test("active session is highlighted", () => {
|
|
render(<NavSessions sessions={SESSIONS} activeSessionId="s2" onOpenPanel={vi.fn()} menuFor={() => null} />);
|
|
expect(screen.getByTestId("session-item-s2")).toHaveAttribute("data-active", "true");
|
|
});
|
|
|
|
test("pressing Enter on a focused row opens the panel", async () => {
|
|
const onOpenPanel = vi.fn();
|
|
render(<NavSessions sessions={SESSIONS} activeSessionId={null} onOpenPanel={onOpenPanel} menuFor={() => null} />);
|
|
const row = screen.getByTestId("session-item-s1");
|
|
row.focus();
|
|
await userEvent.keyboard("{Enter}");
|
|
expect(onOpenPanel).toHaveBeenCalledWith("s1");
|
|
});
|