import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import type { AgentGUIAgentTarget } from "../types"; import { AgentGuiWorkbenchHeader } from "./header"; afterEach(cleanup); describe("AgentGuiWorkbenchHeader conversation identity", () => { it.each([false, true])( "hides conversation identity without a conversation when collapsed is %s", (isConversationRailCollapsed) => { render( Session-independent accessory} showConversationRailToggle={false} showWindowControls={false} onToggleConversationRail={vi.fn()} /> ); expect(screen.queryByText("Leaked agent")).toBeNull(); expect(screen.queryByText("Leaked conversation")).toBeNull(); expect(screen.queryByText("Leaked rich conversation")).toBeNull(); expect(screen.queryByTestId("agent-gui-window-detail-title")).toBeNull(); expect( document.querySelector( '[data-testid^="agent-gui-window-detail-title-icon"]' ) ).toBeNull(); expect( document.querySelector('[data-testid^="agent-gui-window-session-icon"]') ).toBeNull(); expect(screen.getByText("Session-independent accessory")).toBeTruthy(); } ); it("owns tool-sidebar layout independently from the native window shell", () => { const { container } = render( Host-owned tools, isSidebarOpen: true, layoutWidthPx: 432 }} onToggleConversationRail={vi.fn()} /> ); const header = container.querySelector( "[data-agent-gui-workbench-header]" ); expect(header).toHaveAttribute( "data-agent-gui-workbench-header-tool-sidebar", "true" ); expect( header?.style.getPropertyValue("--agent-gui-tool-sidebar-layout-width") ).toBe("432px"); expect(screen.getByText("Host-owned tools")).toBeTruthy(); }); it.each([false, true])( "lazily renders exact Host target information for the session icon when collapsed is %s", async (isConversationRailCollapsed) => { const onHeaderPointerDown = vi.fn(); const conversationAgentTarget: AgentGUIAgentTarget = { agentTargetId: "agent:shared", iconUrl: "shared-agent.png", label: "Shared Codex", provider: "codex", ref: { kind: "shared", provider: "codex" }, targetId: "shared:codex" }; const renderAgentTargetInfo = vi.fn(({ surface, target }) => (
{`${surface}:${target.agentTargetId}`}
)); render( ); expect(renderAgentTargetInfo).not.toHaveBeenCalled(); const trigger = screen.getByRole("img", { name: "Shared Codex" }); fireEvent.focus(trigger); const focusTooltip = await screen.findByRole("tooltip"); expect(focusTooltip).toHaveTextContent("workbench-header:agent:shared"); expect(trigger).toHaveAttribute("aria-describedby", focusTooltip.id); expect(trigger).toHaveAttribute("tabindex", "0"); fireEvent.keyDown(document, { key: "Escape" }); expect(screen.queryByRole("tooltip")).toBeNull(); fireEvent.blur(trigger); fireEvent.pointerDown(trigger); expect(onHeaderPointerDown).not.toHaveBeenCalled(); fireEvent.pointerUp(trigger); fireEvent.pointerMove(trigger, { pointerType: "mouse" }); expect(await screen.findByRole("tooltip")).toHaveTextContent( "workbench-header:agent:shared" ); expect(renderAgentTargetInfo).toHaveBeenLastCalledWith({ surface: "workbench-header", target: conversationAgentTarget }); } ); it("does not add interactive icon chrome without a Host renderer", () => { render( ); expect(screen.queryByLabelText("Local Codex")).toBeNull(); expect( screen.getByTestId("agent-gui-window-detail-title-icon") ).toBeInTheDocument(); }); });