import { fireEvent, render, screen } from "@testing-library/react";
import { useState } from "react";
import { describe, expect, it, vi } from "vitest";
import { ThinkingReasoningShell } from "@/components/thread/activity/ThinkingReasoningShell";
function renderShell(expanded: boolean) {
return render(
,
);
}
describe("ThinkingReasoningShell", () => {
it.each([false, true])("renders the full activity list (active: %s)", (active) => {
render(
{Array.from({ length: 16 }, (_, index) => Activity {index + 1}
)}
);
const content = screen.getByTestId("agent-activity-content");
expect(content).not.toHaveClass("max-h-[180px]");
expect(content).not.toHaveClass("overflow-y-auto");
expect(screen.getByText("Activity 1")).toBeVisible();
expect(screen.getByText("Activity 16")).toBeVisible();
});
it("keeps the same header and content layout when live activity completes", () => {
const shell = (active: boolean) => (
A processing step
);
const view = render(shell(true));
const button = screen.getByRole("button", { name: "Working, Collapse activity details" });
const content = screen.getByTestId("agent-activity-content");
const headerClass = button.className;
const contentClass = content.className;
expect(button.querySelector("svg")).toHaveClass("lucide-activity");
expect(screen.getByText("Working")).toHaveAttribute("data-sheen-text", "Working");
expect(view.container.querySelector("[data-contextual-activity-guide]")).toBeInTheDocument();
view.rerender(shell(false));
expect(screen.getByRole("button", { name: "Worked, Collapse activity details" })).toBe(button);
expect(screen.getByText("Worked")).toHaveClass("text-muted-foreground");
expect(screen.getByText("Worked")).not.toHaveAttribute("data-sheen-text");
expect(button.className).toBe(headerClass);
expect(screen.getByTestId("agent-activity-content")).toBe(content);
expect(content.className).toBe(contentClass);
});
it("aligns the waiting status with the disclosure shown when details arrive", () => {
const shell = (hasDetails: boolean) => (
A processing step
);
const view = render(shell(false));
const status = screen.getByRole("status", { name: "Working" });
expect(status).toHaveClass("touch-target", "h-7", "px-1.5");
expect(status.querySelector("svg")).toHaveClass("lucide-activity");
expect(screen.getByText("Working")).toHaveAttribute("data-sheen-text", "Working");
expect(screen.queryByRole("button")).not.toBeInTheDocument();
view.rerender(shell(true));
expect(screen.getByRole("button", { name: "Working" })).toHaveClass(...status.classList);
expect(screen.getByText("Working")).toHaveAttribute("data-sheen-text", "Working");
});
it("mounts details on first expansion and preserves their state across folding", () => {
const mounted = vi.fn();
function Details() {
const [count, setCount] = useState(() => { mounted(); return 0; });
return ;
}
const shell = (expanded: boolean) => (
{}}>
);
const view = render(shell(false));
expect(mounted).toHaveBeenCalledTimes(0);
view.rerender(shell(true));
fireEvent.click(screen.getByText("Count 0"));
view.rerender(shell(false));
view.rerender(shell(true));
expect(screen.getByRole("button", { name: "Count 1" })).toBeVisible();
expect(mounted).toHaveBeenCalledTimes(1);
});
it("makes collapsed descendants inert as well as visually hidden", () => {
const { rerender } = renderShell(false);
const disclosure = screen.getByRole("button", { name: "Thought" });
const collapsible = disclosure.parentElement?.nextElementSibling;
expect(collapsible).toHaveAttribute("inert");
expect(collapsible).toHaveAttribute("aria-hidden", "true");
rerender(
,
);
const expandedCollapsible = disclosure.parentElement?.nextElementSibling;
expect(expandedCollapsible).not.toHaveAttribute("inert");
expect(expandedCollapsible).toHaveAttribute("aria-hidden", "false");
});
});