// @vitest-environment jsdom import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { Layout } from "./Layout"; import { Layout as ProductionLayout } from "./Layout.production"; import { existsSync, readFileSync } from "node:fs"; import { act as reactAct } from "react"; import type { ReactNode } from "react"; const classicWorkspace = vi.hoisted(() => ({ enabled: true })); vi.mock("./Sidebar.production", async () => await import("./Sidebar")); vi.mock("./CompanySettingsSidebar.production", async () => await import("./CompanySettingsSidebar")); vi.mock("./AppsSidebar.production", async () => await import("./AppsSidebar")); vi.mock("./AppConnectionSidebar.production", async () => await import("./AppConnectionSidebar")); vi.mock("./BreadcrumbBar.production", async () => await import("./BreadcrumbBar")); vi.mock("./SidebarAccountMenu.production", async () => await import("./SidebarAccountMenu")); vi.mock("@/hooks/useCoordinatorWorkspaceEnabled", () => ({ useCoordinatorWorkspaceEnabled: () => ({ enabled: !classicWorkspace.enabled, loaded: true, userId: "viewer" }), })); const browserTimeZoneSync = vi.hoisted(() => vi.fn()); vi.mock("@/hooks/useBrowserTimeZoneSync", () => ({ useBrowserTimeZoneSync: browserTimeZoneSync })); const mockDesignSandbox = vi.hoisted(() => ({ enabled: false })); vi.mock("@/context/DesignSandboxContext", () => ({ useDesignSandbox: () => mockDesignSandbox.enabled })); vi.mock("./DesignSandboxSidebar", () => ({ DesignSandboxSidebar: () =>
Proposed sidebar
})); const mockHealthApi = vi.hoisted(() => ({ get: vi.fn(), })); const mockInstanceSettingsApi = vi.hoisted(() => ({ getGeneral: vi.fn(), getExperimental: vi.fn(), })); const mockNavigate = vi.hoisted(() => vi.fn()); const mockSetSelectedCompanyId = vi.hoisted(() => vi.fn()); const mockSetSidebarOpen = vi.hoisted(() => vi.fn()); const mockCompanyState = vi.hoisted(() => ({ companies: [{ id: "company-1", issuePrefix: "PAP", name: "Paperclip" }], selectedCompany: { id: "company-1", issuePrefix: "PAP", name: "Paperclip" }, selectedCompanyId: "company-1", })); const mockPluginSlots = vi.hoisted(() => ({ slots: [] as Array>, })); const mockUsePluginSlots = vi.hoisted(() => vi.fn()); const mockPluginSlotContexts = vi.hoisted( () => [] as Array>, ); const mockSidebarState = vi.hoisted(() => ({ sidebarOpen: true, isMobile: false, })); const mockPanelState = vi.hoisted(() => ({ visible: false, showsArtifact: false, content: null as ReactNode, setVisible: vi.fn() })); let currentPathname = "/PAP/dashboard"; vi.mock("@/lib/router", () => ({ Outlet: () =>
Outlet content
, useLocation: () => ({ pathname: currentPathname, search: "", hash: "", state: null, }), useNavigate: () => mockNavigate, useNavigationType: () => "PUSH", useParams: () => { const [firstSegment, secondSegment, entityId] = currentPathname .split("/") .filter(Boolean); return { companyPrefix: firstSegment ?? "PAP", pluginRoutePath: secondSegment, agentId: secondSegment === "agents" ? entityId : undefined, routineId: secondSegment === "routines" ? entityId : undefined, }; }, })); vi.mock("./Sidebar", () => ({ Sidebar: ({ contentHeaderControls }: { contentHeaderControls?: boolean }) => (
Main company nav
), })); vi.mock("./CompanySettingsSidebar", () => ({ CompanySettingsSidebar: () =>
Company settings sidebar
, })); vi.mock("./AppsSidebar", () => ({ AppsSidebar: () =>
Apps sidebar
, AppsMobileNav: () => , })); vi.mock("./AgentContextualSidebar", () => ({ AgentContextualSidebar: ({ agentRef }: { agentRef: string }) => (
Agent sidebar {agentRef}
), })); vi.mock("./SkillsContextualSidebar", () => ({ SkillsContextualSidebar: () =>
Skills sidebar
, })); vi.mock("./AppConnectionSidebar", () => ({ AppDetailSidebar: ( props: | { kind: "connection"; connectionId: string } | { kind: "application"; applicationId: string }, ) => (
{props.kind === "connection" ? `App detail sidebar connection ${props.connectionId}` : `App detail sidebar application ${props.applicationId}`}
), })); vi.mock("./BreadcrumbBar", () => ({ BreadcrumbBar: ({ toolbarAction }: { toolbarAction?: ReactNode }) =>
Breadcrumbs{toolbarAction}
, })); vi.mock("./AgentConversationsSidebar", () => ({ AgentConversationsSidebar: ({ compact }: { compact?: boolean }) => compact ? :