From df5d3e9679b3c8866dde4a6bf41a158bd491db83 Mon Sep 17 00:00:00 2001 From: ComputelessComputer <63365510+ComputelessComputer@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:18:18 +0900 Subject: [PATCH] Make left sidebar resizable Wrap the desktop left sidebar in a persistent resizable panel and cover expanded/collapsed layout states with tests. --- apps/desktop/src/main/body.test.tsx | 205 +++++++++++++++++++++ apps/desktop/src/main/body.tsx | 127 ++++++++++--- apps/desktop/src/shared/main/body.test.tsx | 10 +- apps/desktop/src/sidebar/index.tsx | 2 +- 4 files changed, 311 insertions(+), 33 deletions(-) create mode 100644 apps/desktop/src/main/body.test.tsx 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" ? ( +