import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, vi } from "vitest";
import { useSessionStore } from "../store/sessionStore";
import { ModelActivityPanel } from "./ModelActivityPanel";
beforeEach(() => useSessionStore.getState().resetSession());
test("renders the streamed model transcript", () => {
useSessionStore.getState().applyEvent({ type: "text_delta", text: "Promoting table dim_patient." });
render();
expect(screen.getByText(/Promoting table dim_patient/)).toBeInTheDocument();
});
test("close button calls onClose", async () => {
const onClose = vi.fn();
render();
await userEvent.click(screen.getByRole("button", { name: /close/i }));
expect(onClose).toHaveBeenCalled();
});
const EIGHT = ["line-01", "line-02", "line-03", "line-04", "line-05", "line-06", "line-07", "line-08"].join("\n");
test("collapsed shows only the last 5 lines of the model-stream tail", () => {
useSessionStore.getState().applyEvent({ type: "text_delta", text: EIGHT });
render();
expect(screen.getByText("line-08")).toBeInTheDocument();
expect(screen.getByText("line-04")).toBeInTheDocument();
expect(screen.queryByText("line-03")).not.toBeInTheDocument();
expect(screen.queryByText("line-01")).not.toBeInTheDocument();
});
test("expanding reveals the full stream", async () => {
useSessionStore.getState().applyEvent({ type: "text_delta", text: EIGHT });
render();
await userEvent.click(screen.getByRole("button", { name: /show more/i }));
expect(screen.getByText("line-01")).toBeInTheDocument();
});