// @vitest-environment jsdom import { renderToStaticMarkup } from "react-dom/server"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { MemoryRouter } from "react-router-dom"; import { describe, expect, it, vi } from "vitest"; import { AgentContextualSidebar } from "./AgentContextualSidebar"; import { queryKeys } from "@/lib/queryKeys"; vi.mock("@/context/CompanyContext", () => ({ useCompany: () => ({ selectedCompanyId: "company-1" }), })); vi.mock("./ContextualSidebarFrame", () => ({ ContextualSidebarFrame: ({ title, showHeader, className, children, }: { title: string; showHeader?: boolean; className?: string; children: React.ReactNode; }) => ( ), })); vi.mock("./SidebarNavItem", () => ({ SidebarNavItem: ({ to, label }: { to: string; label: string }) => {label}, })); vi.mock("@/plugins/slots", () => ({ usePluginSlots: () => ({ slots: [{ pluginKey: "test.plugin", id: "insights", displayName: "Insights" }] }) })); describe("AgentContextualSidebar", () => { it.each([false, true])("keeps Channels available for default email regardless of the chat setting (%s)", (enabled) => { const client = new QueryClient(); client.setQueryData(queryKeys.instance.experimentalSettings, { enableChatConnectors: enabled }); const markup = renderToStaticMarkup( ); expect(markup).toContain("Insights"); expect(markup).toContain("plugin%3Atest.plugin%3Ainsights"); expect(markup.includes('href="/agents/agent/channels"')).toBe(true); expect(markup).toContain('href="/agents/agent/tools"'); client.clear(); }); it("renders local definition/runtime/governance links and scoped Audit links", () => { const queryClient = new QueryClient(); const markup = renderToStaticMarkup( , ); expect(markup).toContain("Codex Coder"); expect(markup).toContain('data-show-header="false"'); expect(markup).toContain("border-r border-border bg-background"); expect(markup).toContain('data-slot="contextual-sidebar-nav"'); expect(markup).toContain('href="/agents/codexcoder/overview"'); expect(markup).toContain('href="/agents/codexcoder/permissions"'); expect(markup).toContain('href="/agents/codexcoder/api-keys"'); expect(markup).toContain('href="/activity?mode=agents&agentId=agent-1"'); expect(markup).toContain('href="/activity/runs?agentId=agent-1"'); expect(markup).toContain("Harness / Runtime"); expect(markup).toContain("Permissions / Trust"); }); });