/** * @file ConversationView.notYet.test.tsx * @description A live pane's new session has no row until its first hook: * its 404 shows no "Session not found" (a replay still shows it) but says the * session has not started — the CLI may be asking in the terminal, e.g. to * trust the folder — offers the terminal, and tells the chat (`onNotStarted`). * @author Nguyễn Ngọc Trí Vĩ */ import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { ConversationView } from "../ConversationView"; const transcript = vi.hoisted(() => vi.fn(async () => { throw Object.assign(new Error("Session not found"), { code: "NOT_FOUND", status: 404 }); }) ); vi.mock("../../../lib/api", async (importOriginal) => { const actual = await importOriginal>(); return { ...actual, api: { sessions: { transcripts: vi.fn(async () => ({ transcripts: [] })), transcript } }, }; }); describe("ConversationView before a session's first hook", () => { it("shows no error for a live pane", async () => { render(); await waitFor(() => expect(transcript).toHaveBeenCalled()); await new Promise((r) => setTimeout(r, 0)); expect(screen.queryByText("Session not found")).toBeNull(); }); it("still reports it when not live", async () => { render(); expect(await screen.findByText("Session not found")).toBeTruthy(); }); it("says the session has not started and offers the terminal (a trust prompt)", async () => { const onOpenTerminal = vi.fn(); const onNotStarted = vi.fn(); render( ); expect(await screen.findByText("The session has not started yet.")).toBeTruthy(); expect(screen.queryByText("No conversation records found.")).toBeNull(); fireEvent.click(screen.getByText("Open terminal")); expect(onOpenTerminal).toHaveBeenCalled(); expect(onNotStarted).toHaveBeenLastCalledWith(true); }); });