diff --git a/apps/desktop/src/main/body.test.tsx b/apps/desktop/src/main/body.test.tsx new file mode 100644 index 0000000000..8b53a1c0f8 --- /dev/null +++ b/apps/desktop/src/main/body.test.tsx @@ -0,0 +1,205 @@ +import { act, cleanup, render, screen } from "@testing-library/react"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ + currentTab: { + active: true, + pinned: false, + slotId: "slot-home", + type: "empty", + } as ({ type: string } & Record) | null, + leftsidebar: { + expanded: true, + toggleExpanded: vi.fn(), + }, + onPanelLayout: null as null | ((sizes: number[]) => void), +})); + +vi.mock("@hypr/ui/components/ui/resizable", () => ({ + ResizablePanelGroup: ({ + autoSaveId, + children, + className, + direction, + onLayout, + }: { + autoSaveId?: string; + children: React.ReactNode; + className?: string; + direction: string; + onLayout?: (sizes: number[]) => void; + }) => { + mocks.onPanelLayout = onLayout ?? null; + + return ( +
+ {children} +
+ ); + }, + ResizablePanel: ({ + children, + className, + defaultSize, + maxSize, + minSize, + style, + }: { + children: React.ReactNode; + className?: string; + defaultSize?: number; + maxSize?: number; + minSize?: number; + style?: React.CSSProperties; + }) => ( +
+ {children} +
+ ), + ResizableHandle: ({ className }: { className?: string }) => ( +
+ ), +})); + +vi.mock("~/contexts/shell", () => ({ + useShell: () => ({ + leftsidebar: mocks.leftsidebar, + }), +})); + +vi.mock("~/store/zustand/tabs", () => ({ + uniqueIdfromTab: (tab: { type: string }) => tab.type, + useTabs: ( + selector: (state: { currentTab: typeof mocks.currentTab }) => unknown, + ) => selector({ currentTab: mocks.currentTab }), +})); + +vi.mock("./shell-sidebar", () => ({ + ClassicMainSidebar: () => + mocks.leftsidebar.expanded && mocks.currentTab?.type !== "onboarding" ? ( +