workspaceShellRemoteMobileLayout.test.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { V4ChatPaneProps } from "@/v4/V4ChatPane.js";
  5. import { V4_PRIMARY_PANE_ID } from "@/v4/paneLayoutStore.js";
  6. import { useWorkbenchGroupStore } from "@/v4/workbenchGroupStore.js";
  7. vi.mock("@/app-shell/AnimatedSidePanePanel.js", () => ({
  8. AnimatedSidePanePanel: ({
  9. isVisible,
  10. mobileOverlay,
  11. mobileStacked,
  12. }: {
  13. isVisible?: boolean;
  14. mobileOverlay?: boolean;
  15. mobileStacked?: boolean;
  16. }) =>
  17. createElement("div", {
  18. "data-mobile-overlay": mobileOverlay ? "true" : "false",
  19. "data-mobile-stacked": mobileStacked ? "true" : "false",
  20. "data-panel-visible": isVisible ? "true" : "false",
  21. "data-testid": "side-pane-panel",
  22. }),
  23. }));
  24. vi.mock("@/app-shell/AnimatedTerminalPanel.js", () => ({
  25. AnimatedTerminalPanel: () => createElement("div", { "data-testid": "terminal-panel" }),
  26. }));
  27. vi.mock("@/app-shell/useAnimatedResizablePanel.js", () => ({
  28. useAnimatedResizablePanel: ({ open }: { open: boolean }) => ({
  29. isVisible: open,
  30. panelElementRef: { current: null },
  31. panelRef: { current: null },
  32. }),
  33. }));
  34. vi.mock("@/settings/AutomationsSection.js", () => ({
  35. AUTOMATIONS_TOAST_ANCHOR_ID: "automations-main-toast-anchor",
  36. AutomationsSection: () => createElement("div", { "data-testid": "automations-section" }),
  37. }));
  38. const capturedChatPaneProps: V4ChatPaneProps[] = [];
  39. vi.mock("@/v4/V4ChatPane.js", () => ({
  40. V4ChatPane: (props: V4ChatPaneProps) => {
  41. capturedChatPaneProps.push(props);
  42. return createElement("div", { "data-testid": "v4-chat-pane" });
  43. },
  44. }));
  45. // M5⑤:桌面主区改由分屏宿主承载(props 形状与 V4ChatPane 相同的超集),
  46. // 布局测试同样打桩——分屏行为在 v4PaneLayoutStore 单测与 v4-split e2e 覆盖。
  47. vi.mock("@/v4/V4WorkspaceChatArea.js", () => ({
  48. V4WorkspaceChatArea: (props: V4ChatPaneProps) => {
  49. capturedChatPaneProps.push(props);
  50. return createElement("div", { "data-testid": "v4-chat-pane" });
  51. },
  52. }));
  53. vi.mock("@/BotsDialog.js", () => ({
  54. BotsDialog: () => createElement("div", { "data-testid": "bots-dialog" }),
  55. }));
  56. vi.mock("@/components/ui/resizable.js", () => ({
  57. ResizableHandle: ({ className }: { className?: string }) =>
  58. createElement("div", {
  59. className,
  60. "data-testid": "resizable-handle",
  61. }),
  62. ResizablePanel: ({
  63. children,
  64. className,
  65. "data-state": dataState,
  66. disabled,
  67. id,
  68. minSize,
  69. }: {
  70. children: ReactNode;
  71. className?: string;
  72. "data-state"?: string;
  73. disabled?: boolean;
  74. id: string;
  75. minSize?: string;
  76. }) =>
  77. createElement(
  78. "section",
  79. {
  80. className,
  81. "data-disabled": disabled ? "true" : "false",
  82. "data-min-size": minSize,
  83. "data-panel-id": id,
  84. "data-state": dataState,
  85. },
  86. children,
  87. ),
  88. ResizablePanelGroup: ({
  89. children,
  90. className,
  91. layoutId,
  92. panelIds,
  93. style,
  94. }: {
  95. children: ReactNode;
  96. className?: string;
  97. layoutId: string;
  98. panelIds?: string[];
  99. style?: Record<string, string>;
  100. }) =>
  101. createElement(
  102. "div",
  103. {
  104. className,
  105. "data-layout-id": layoutId,
  106. "data-panel-ids": panelIds?.join(","),
  107. style,
  108. },
  109. children,
  110. ),
  111. }));
  112. vi.mock("@/components/ui/dropdown-menu.js", () => ({
  113. DropdownMenu: ({ children }: { children: ReactNode }) =>
  114. createElement("div", { "data-testid": "dropdown-menu" }, children),
  115. DropdownMenuContent: ({ children }: { children: ReactNode }) =>
  116. createElement("div", { "data-testid": "dropdown-menu-content" }, children),
  117. DropdownMenuItem: ({ children }: { children: ReactNode }) =>
  118. createElement("button", { "data-testid": "dropdown-menu-item" }, children),
  119. DropdownMenuTrigger: ({ children }: { children: ReactNode }) => children,
  120. }));
  121. vi.mock("@/ControlHintTooltip.js", () => ({
  122. ControlHintTooltip: ({ children }: { children: ReactNode }) => children,
  123. }));
  124. vi.mock("@/DesktopTopOverlay.js", () => ({
  125. DesktopTopOverlay: () => createElement("div", { "data-testid": "desktop-top-overlay" }),
  126. }));
  127. vi.mock("@/DesktopWindowFrame.js", () => ({
  128. DesktopWindowFrame: ({ children }: { children: ReactNode }) =>
  129. createElement("div", { "data-testid": "desktop-window-frame" }, children),
  130. }));
  131. vi.mock("@/i18n/IntlProvider.js", () => ({
  132. useZCodeIntl: () => ({
  133. intl: {
  134. formatMessage: ({ id }: { id: string }) => id,
  135. },
  136. }),
  137. }));
  138. vi.mock("@/feedback/feedbackStore.js", () => ({
  139. useFeedbackStore: (
  140. selector: (state: { openFeatureRequest: () => void; openSubmit: () => void }) => unknown,
  141. ) =>
  142. selector({
  143. openFeatureRequest: vi.fn(),
  144. openSubmit: vi.fn(),
  145. }),
  146. }));
  147. vi.mock("@/hooks/usePlatform.js", () => ({
  148. usePlatform: () => ({
  149. openCommunity: vi.fn(async () => {}),
  150. openExternal: vi.fn(),
  151. }),
  152. }));
  153. vi.mock("@/hooks/useWorkspaceServices.js", () => ({
  154. useBaseWorkspaceServices: () => ({}),
  155. }));
  156. vi.mock("@/store/TabStoreProvider.js", () => ({
  157. useTabStoreApi: () => ({
  158. getState: () => ({
  159. activateTabByPath: vi.fn(() => true),
  160. addTab: vi.fn(),
  161. }),
  162. }),
  163. }));
  164. vi.mock("@/WorkspaceHeader.js", () => ({
  165. WorkspaceHeader: ({ variant }: { variant?: string }) =>
  166. createElement("header", {
  167. "data-testid": "workspace-header",
  168. "data-workspace-header-variant": variant,
  169. }),
  170. }));
  171. vi.mock("@/WindowsCaptionMenuButton.js", () => ({
  172. WindowsCaptionMenuButton: ({ triggerPresentation }: { triggerPresentation?: string }) =>
  173. createElement("button", {
  174. "data-testid": "windows-caption-menu",
  175. "data-trigger-presentation": triggerPresentation ?? "header",
  176. }),
  177. }));
  178. vi.mock("@/WebRemoteControlMobileShell.js", () => ({
  179. WebRemoteControlMobileShell: ({
  180. chatContent,
  181. chatOverlay,
  182. isSidePaneOpen,
  183. renderChatHeader,
  184. sidePaneContent,
  185. }: {
  186. chatContent?: ReactNode;
  187. chatOverlay?: ReactNode;
  188. isSidePaneOpen?: boolean;
  189. renderChatHeader?: () => ReactNode;
  190. sidePaneContent?: ReactNode;
  191. }) =>
  192. createElement(
  193. "div",
  194. {
  195. "data-mobile-side-pane-open": isSidePaneOpen ? "true" : "false",
  196. "data-testid": "web-remote-mobile-shell",
  197. },
  198. renderChatHeader?.(),
  199. createElement("div", { "data-testid": "mobile-chat-content" }, chatContent),
  200. chatOverlay
  201. ? createElement("div", { "data-testid": "mobile-chat-overlay-prop" }, chatOverlay)
  202. : null,
  203. sidePaneContent
  204. ? createElement("div", { "data-testid": "mobile-side-pane-overlay" }, sidePaneContent)
  205. : null,
  206. ),
  207. }));
  208. const capturedWorkspaceSidebarProps = vi.hoisted(() => ({
  209. props: [] as Array<{
  210. onSelectTask: (
  211. targetWorkspacePath: string,
  212. taskId: string,
  213. targetWorkspaceIdentity?: string,
  214. ) => void;
  215. }>,
  216. }));
  217. vi.mock("@/WorkspaceSidebar.js", () => ({
  218. WorkspaceSidebar: (props: (typeof capturedWorkspaceSidebarProps.props)[number]) => {
  219. capturedWorkspaceSidebarProps.props.push(props);
  220. return createElement("aside", { "data-testid": "workspace-sidebar" });
  221. },
  222. }));
  223. function createWorkspaceShellProps() {
  224. return {
  225. activeGitSourceId: "unstaged" as const,
  226. activeSessionId: null,
  227. activeTaskChangeSummary: null,
  228. activeTaskId: null,
  229. activeTaskProvider: null,
  230. activeTaskTitle: "",
  231. activeTraceId: null,
  232. allowOpenWorkspace: false,
  233. allowRemoteWorkspace: false,
  234. appLogoUrl: "",
  235. browserNavigationRequest: null,
  236. browserRestoreUrls: {},
  237. canGoBack: false,
  238. canGoForward: false,
  239. canTaskNavBack: false,
  240. canTaskNavForward: false,
  241. gitState: {
  242. datasets: {
  243. staged: { sections: [] },
  244. unstaged: { sections: [] },
  245. },
  246. summary: {
  247. isGitAvailable: false,
  248. isRepository: false,
  249. },
  250. },
  251. goBackShortcutLabel: "",
  252. goForwardShortcutLabel: "",
  253. handleActivateSidePaneTab: vi.fn(),
  254. handleBrowserNavigationRequestHandled: vi.fn(),
  255. handleBrowserPageMetadataChange: vi.fn(),
  256. handleBrowserUrlChange: vi.fn(),
  257. handleCloseCodeViewer: vi.fn(),
  258. handleCloseGit: vi.fn(),
  259. handleOpenBrowserTab: vi.fn(),
  260. handleOpenBrowserUrl: vi.fn(),
  261. handleOpenCodeViewer: vi.fn(),
  262. handleRefreshGit: vi.fn(),
  263. handleReloadSession: vi.fn(async () => {}),
  264. handleReorderSidePaneTab: vi.fn(),
  265. handleOpenAutomations: vi.fn(),
  266. handleSelectTask: vi.fn(),
  267. handleStartDraftInWorkspace: vi.fn(),
  268. handleTaskNavBack: vi.fn(),
  269. handleTaskNavForward: vi.fn(),
  270. handleToggleBrowser: vi.fn(),
  271. handleToggleGit: vi.fn(),
  272. handleToggleSidePane: vi.fn(),
  273. handleToggleSidebar: vi.fn(),
  274. handleToggleTerminal: vi.fn(),
  275. onOpenAutomationConsumed: vi.fn(),
  276. onWorkspaceMainViewChange: vi.fn(),
  277. openAutomationId: null,
  278. workspaceMainView: "chat" as const,
  279. headerGitChangeSummary: null,
  280. isBrowserOpen: false,
  281. isDesktop: false,
  282. isGitOpen: false,
  283. isMacDesktop: false,
  284. isMacFullscreen: false,
  285. isSidePaneOpen: false,
  286. isSidebarVisible: true,
  287. isTerminalOpen: false,
  288. isWindowsDesktop: false,
  289. newTaskShortcutLabel: "",
  290. onCancelRemoteProject: vi.fn(async () => {}),
  291. onConnectRemote: vi.fn(async () => ""),
  292. onCreateTask: vi.fn(),
  293. onLogin: vi.fn(),
  294. onLogout: vi.fn(),
  295. onOpenWorkspace: vi.fn(),
  296. onReconnectRemoteWorkspace: vi.fn(async () => {}),
  297. onSelectRemoteProject: vi.fn(async () => {}),
  298. platform: {},
  299. projectName: "project",
  300. providerConfigFile: {
  301. exists: false,
  302. loading: false,
  303. path: null,
  304. },
  305. reconnectingRemoteWorkspaceKeys: [],
  306. reloadSessionDisabled: false,
  307. reloadSessionPending: false,
  308. remoteWorkspaceErrorByWorkspaceKey: {},
  309. remoteWorkspaceSessions: [],
  310. resolvedActiveTaskMeta: null,
  311. services: {},
  312. setGitSelectedSourceId: vi.fn(),
  313. setIsTerminalOpen: vi.fn(),
  314. shellPanelIds: ["sidebar", "content"],
  315. sidePaneState: null,
  316. sidebarContainerRef: { current: null },
  317. taskNativeSessionLogFile: {
  318. exists: false,
  319. loading: false,
  320. path: null,
  321. provider: null,
  322. },
  323. taskSessionFile: {
  324. path: null,
  325. },
  326. testMessages: null,
  327. theme: "light" as const,
  328. toggleSidebarShortcutLabel: "",
  329. toggleSidePaneShortcutLabel: "",
  330. updateReadyVersion: null,
  331. user: null,
  332. webRemoteControlWorkspaceSwitcher: undefined,
  333. workspaceAbsPath: "/tmp/project",
  334. workspaceRemoteSessionId: undefined,
  335. workspaceShellZCodeState: {
  336. activeTaskId: null,
  337. modelSwitchPending: false,
  338. modelSwitchStage: null,
  339. optimisticTaskListByTaskId: {},
  340. selectedProvider: "codex",
  341. taskError: null,
  342. taskStatus: "notReady",
  343. workspaceInit: {
  344. attempts: 0,
  345. error: null,
  346. status: "idle",
  347. },
  348. },
  349. workspaceTabs: [],
  350. };
  351. }
  352. async function renderWorkspaceShell(
  353. overrides: Partial<ReturnType<typeof createWorkspaceShellProps>> = {},
  354. ) {
  355. const { WorkspaceShellLayout } = await import("@/app-shell/WorkspaceShellLayout.js");
  356. return renderToStaticMarkup(
  357. createElement(WorkspaceShellLayout, {
  358. ...createWorkspaceShellProps(),
  359. ...overrides,
  360. } as Parameters<typeof WorkspaceShellLayout>[0]),
  361. );
  362. }
  363. describe("WorkspaceShellLayout Web remote control mobile layout", () => {
  364. // Bugfix: 这些断言只覆盖远控导航纯计算逻辑,直接导入小模块,避免全量并发单测时拉起整页组件。
  365. it("resolves draggable navigation heights and collapse thresholds", async () => {
  366. const {
  367. getDefaultWebRemoteNavigationHeightPx,
  368. resolveWebRemoteNavigationDragState,
  369. resolveWebRemoteNavigationToggleState,
  370. } = await import("@/app-shell/webRemoteNavigationLayout.js");
  371. expect(getDefaultWebRemoteNavigationHeightPx(800)).toBe(352);
  372. expect(getDefaultWebRemoteNavigationHeightPx(600)).toBe(252);
  373. expect(
  374. resolveWebRemoteNavigationDragState({
  375. heightPx: 18,
  376. viewportHeight: 800,
  377. }),
  378. ).toEqual({ heightPx: 0, isCollapsed: true });
  379. expect(
  380. resolveWebRemoteNavigationDragState({
  381. heightPx: 320,
  382. viewportHeight: 800,
  383. }),
  384. ).toEqual({ heightPx: 320, isCollapsed: false });
  385. expect(
  386. resolveWebRemoteNavigationDragState({
  387. heightPx: 720,
  388. viewportHeight: 800,
  389. }),
  390. ).toEqual({ heightPx: 584, isCollapsed: false });
  391. expect(
  392. resolveWebRemoteNavigationToggleState({
  393. currentHeightPx: 280,
  394. isCollapsed: false,
  395. viewportHeight: 800,
  396. }),
  397. ).toEqual({ heightPx: 0, isCollapsed: true });
  398. expect(
  399. resolveWebRemoteNavigationToggleState({
  400. currentHeightPx: 0,
  401. isCollapsed: true,
  402. viewportHeight: 800,
  403. }),
  404. ).toEqual({ heightPx: 352, isCollapsed: false });
  405. });
  406. it("keeps sidebar panel ids stable while still marking collapsed mobile layout", async () => {
  407. const { getActiveWorkspaceShellPanelIds, shouldRenderWebRemoteNavigationPanel } =
  408. await import("@/app-shell/webRemoteNavigationLayout.js");
  409. expect(
  410. shouldRenderWebRemoteNavigationPanel({
  411. isCollapsed: true,
  412. isMobileViewport: true,
  413. isWebRemoteControlShell: true,
  414. }),
  415. ).toBe(false);
  416. expect(
  417. shouldRenderWebRemoteNavigationPanel({
  418. isCollapsed: true,
  419. isMobileViewport: false,
  420. isWebRemoteControlShell: true,
  421. }),
  422. ).toBe(true);
  423. expect(
  424. shouldRenderWebRemoteNavigationPanel({
  425. isCollapsed: true,
  426. isMobileViewport: true,
  427. isWebRemoteControlShell: false,
  428. }),
  429. ).toBe(true);
  430. expect(getActiveWorkspaceShellPanelIds(["sidebar", "content"], false)).toEqual([
  431. "sidebar",
  432. "content",
  433. ]);
  434. expect(getActiveWorkspaceShellPanelIds(["sidebar", "content"], true)).toEqual([
  435. "sidebar",
  436. "content",
  437. ]);
  438. });
  439. // Bugfix: 该断言需要 SSR 整个 WorkspaceShellLayout,full suite 并发时首次组件导入可能超过 5s。
  440. // 纯计算逻辑已拆到 webRemoteNavigationLayout,这里只给剩余整页渲染用例留局部余量。
  441. it("keeps the hidden sidebar mounted without an outer resizable panel target", async () => {
  442. const html = await renderWorkspaceShell({ isSidebarVisible: false });
  443. expect(html).toContain('id="sidebar"');
  444. expect(html).toContain("--workspace-sidebar-panel-width:0px");
  445. expect(html).not.toContain('data-panel-id="sidebar"');
  446. expect(html).not.toContain('data-layout-id="workspace-shell-layout"');
  447. }, 15_000);
  448. it("keeps the desktop Browser Guest host mounted and collapsed on the Automations main view", async () => {
  449. const html = await renderWorkspaceShell({
  450. isDesktop: true,
  451. isSidePaneOpen: true,
  452. sidePaneState: {
  453. activeTabId: "browser-use:iab-tab:automation",
  454. tabs: [
  455. {
  456. id: "browser-use:iab-tab:automation",
  457. sessionId: "automation-session",
  458. tabId: "iab-tab:automation",
  459. type: "browser-use",
  460. workspaceKey: "/tmp/project",
  461. },
  462. ],
  463. } as never,
  464. workspaceMainView: "automations",
  465. });
  466. expect(html).toContain('id="automations-main-toast-anchor"');
  467. expect(html).toContain('data-layout-id="workspace-body-layout"');
  468. expect(html).toContain('data-panel-id="conversation-column"');
  469. expect(html.match(/data-testid="side-pane-panel"/gu)).toHaveLength(1);
  470. expect(html).toContain('data-panel-visible="false"');
  471. const chatHtml = await renderWorkspaceShell({
  472. isDesktop: true,
  473. isSidePaneOpen: true,
  474. workspaceMainView: "chat",
  475. });
  476. expect(chatHtml.match(/data-testid="side-pane-panel"/gu)).toHaveLength(1);
  477. expect(chatHtml).toContain('data-panel-visible="true"');
  478. }, 15_000);
  479. it("adds mobile stacking classes only for Web remote control mode", async () => {
  480. const html = await renderWorkspaceShell({
  481. webRemoteControlWorkspaceSwitcher: {
  482. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  483. switchWorkspace: vi.fn(async () => {}),
  484. },
  485. });
  486. expect(html).toContain("max-md:!flex-col");
  487. expect(html).toContain("max-md:!flex-1");
  488. expect(html).not.toContain("max-md:data-[state=collapsed]");
  489. expect(html).not.toContain('data-layout-id="workspace-shell-layout"');
  490. expect(html).toContain("max-md:!w-full");
  491. expect(html).not.toContain('data-web-remote-navigation-toggle="true"');
  492. expect(html).toContain('data-web-remote-navigation-resize-handle="true"');
  493. expect(html).toContain("--web-remote-navigation-height:352px");
  494. expect(html).toContain("max-md:!h-[var(--web-remote-navigation-height)]");
  495. expect(html).toContain('aria-controls="web-remote-control-navigation-panel"');
  496. expect(html).toContain("webRemoteControl.collapseNavigation");
  497. expect(html).not.toContain("webRemoteControl.navigationPanel");
  498. expect(html).not.toContain("max-md:!h-10");
  499. expect(html).toContain('data-mobile-stacked="true"');
  500. });
  501. it("keeps remote sidebar selection out of hidden workbench group context", async () => {
  502. capturedWorkspaceSidebarProps.props = [];
  503. useWorkbenchGroupStore.getState().configureClientMode("desktop-continuous");
  504. useWorkbenchGroupStore.getState().resetWorkbenchGroups();
  505. useWorkbenchGroupStore.getState().splitSessionIntoGroup(
  506. V4_PRIMARY_PANE_ID,
  507. "right",
  508. {
  509. workspaceScope: { workspacePath: "/workspace-b" },
  510. sessionId: "secondary-session",
  511. },
  512. {
  513. workspaceScope: { workspacePath: "/tmp/project" },
  514. sessionId: "main-session",
  515. },
  516. );
  517. const groupId = useWorkbenchGroupStore.getState().activeGroupId;
  518. const handleSelectTask = vi.fn();
  519. await renderWorkspaceShell({
  520. activeTaskId: "main-session",
  521. handleSelectTask,
  522. webRemoteControlWorkspaceSwitcher: {
  523. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  524. switchWorkspace: vi.fn(async () => {}),
  525. },
  526. });
  527. const onSelectTask = capturedWorkspaceSidebarProps.props.at(-1)?.onSelectTask;
  528. expect(onSelectTask).toBeTypeOf("function");
  529. onSelectTask?.("/tmp/project", "main-session");
  530. expect(handleSelectTask).toHaveBeenCalledWith("/tmp/project", "main-session", undefined);
  531. expect(useWorkbenchGroupStore.getState().groups[groupId!]?.focusedPaneId).toBe("pane-1");
  532. useWorkbenchGroupStore.getState().resetWorkbenchGroups();
  533. });
  534. it("renders the dedicated mobile task shell on Web remote control mobile viewports", async () => {
  535. vi.stubGlobal("window", {
  536. innerHeight: 800,
  537. matchMedia: vi.fn(() => ({
  538. addEventListener: vi.fn(),
  539. addListener: vi.fn(),
  540. matches: true,
  541. removeEventListener: vi.fn(),
  542. removeListener: vi.fn(),
  543. })),
  544. sessionStorage: {
  545. getItem: vi.fn(() => null),
  546. removeItem: vi.fn(),
  547. setItem: vi.fn(),
  548. },
  549. });
  550. const html = await renderWorkspaceShell({
  551. webRemoteControlWorkspaceSwitcher: {
  552. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  553. switchWorkspace: vi.fn(async () => {}),
  554. },
  555. });
  556. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  557. expect(html).not.toContain('data-testid="workspace-sidebar"');
  558. vi.unstubAllGlobals();
  559. });
  560. it("keeps mobile remote chat content in a flex height chain", async () => {
  561. vi.stubGlobal("window", {
  562. innerHeight: 800,
  563. matchMedia: vi.fn(() => ({
  564. addEventListener: vi.fn(),
  565. addListener: vi.fn(),
  566. matches: true,
  567. removeEventListener: vi.fn(),
  568. removeListener: vi.fn(),
  569. })),
  570. sessionStorage: {
  571. getItem: vi.fn(() => null),
  572. removeItem: vi.fn(),
  573. setItem: vi.fn(),
  574. },
  575. });
  576. const html = await renderWorkspaceShell({
  577. activeTaskId: null,
  578. initialWebRemoteControlMobileNavigationIntent: "chat",
  579. webRemoteControlWorkspaceSwitcher: {
  580. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  581. switchWorkspace: vi.fn(async () => {}),
  582. },
  583. workspaceShellZCodeState: {
  584. ...createWorkspaceShellProps().workspaceShellZCodeState,
  585. activeTaskId: null,
  586. },
  587. });
  588. expect(html).toContain("relative flex h-full min-h-0 min-w-0 flex-1 flex-col");
  589. expect(html).not.toContain('class="relative h-full min-h-0"');
  590. vi.unstubAllGlobals();
  591. });
  592. it("passes workspace identity to mobile V4ChatPane for remote workspaces", async () => {
  593. capturedChatPaneProps.length = 0;
  594. vi.stubGlobal("window", {
  595. innerHeight: 800,
  596. matchMedia: vi.fn(() => ({
  597. addEventListener: vi.fn(),
  598. addListener: vi.fn(),
  599. matches: true,
  600. removeEventListener: vi.fn(),
  601. removeListener: vi.fn(),
  602. })),
  603. sessionStorage: {
  604. getItem: vi.fn(() => null),
  605. removeItem: vi.fn(),
  606. setItem: vi.fn(),
  607. },
  608. });
  609. const workspaceIdentity = "remote:ssh:dev:22:root:/root";
  610. await renderWorkspaceShell({
  611. webRemoteControlWorkspaceSwitcher: {
  612. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  613. switchWorkspace: vi.fn(async () => {}),
  614. },
  615. workspaceIdentity,
  616. workspaceRemoteSessionId: "remote-session-1",
  617. });
  618. expect(capturedChatPaneProps[0]?.workspaceIdentity).toBe(workspaceIdentity);
  619. vi.unstubAllGlobals();
  620. });
  621. it("exposes plan-detail opening from the mobile remote chat", async () => {
  622. capturedChatPaneProps.length = 0;
  623. const handleOpenPlanDetail = vi.fn();
  624. vi.stubGlobal("window", {
  625. innerHeight: 800,
  626. matchMedia: vi.fn(() => ({
  627. addEventListener: vi.fn(),
  628. addListener: vi.fn(),
  629. matches: true,
  630. removeEventListener: vi.fn(),
  631. removeListener: vi.fn(),
  632. })),
  633. sessionStorage: {
  634. getItem: vi.fn(() => null),
  635. removeItem: vi.fn(),
  636. setItem: vi.fn(),
  637. },
  638. });
  639. await renderWorkspaceShell({
  640. activeTaskId: "task-with-plan",
  641. handleOpenPlanDetail,
  642. initialWebRemoteControlMobileNavigationIntent: "chat",
  643. webRemoteControlWorkspaceSwitcher: {
  644. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  645. switchWorkspace: vi.fn(async () => {}),
  646. },
  647. });
  648. expect(capturedChatPaneProps[0]?.onOpenPlanDetail).toBe(handleOpenPlanDetail);
  649. vi.unstubAllGlobals();
  650. });
  651. it("passes side pane content as a right-side overlay into the dedicated mobile chat shell", async () => {
  652. vi.stubGlobal("window", {
  653. innerHeight: 800,
  654. matchMedia: vi.fn(() => ({
  655. addEventListener: vi.fn(),
  656. addListener: vi.fn(),
  657. matches: true,
  658. removeEventListener: vi.fn(),
  659. removeListener: vi.fn(),
  660. })),
  661. sessionStorage: {
  662. getItem: vi.fn(() => null),
  663. removeItem: vi.fn(),
  664. setItem: vi.fn(),
  665. },
  666. });
  667. const html = await renderWorkspaceShell({
  668. isSidePaneOpen: true,
  669. sidePaneState: {
  670. activeTabId: "git",
  671. tabs: [{ id: "git", type: "git" }],
  672. },
  673. webRemoteControlWorkspaceSwitcher: {
  674. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  675. switchWorkspace: vi.fn(async () => {}),
  676. },
  677. });
  678. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  679. expect(html).toContain('data-mobile-side-pane-open="true"');
  680. expect(html).toContain('data-testid="mobile-side-pane-overlay"');
  681. expect(html).toContain('data-testid="side-pane-panel"');
  682. expect(html).toContain('data-mobile-overlay="true"');
  683. expect(html).toContain('data-panel-visible="true"');
  684. vi.unstubAllGlobals();
  685. });
  686. it("routes mobile task find through the shell overlay instead of chat content", async () => {
  687. vi.stubGlobal("window", {
  688. innerHeight: 800,
  689. matchMedia: vi.fn(() => ({
  690. addEventListener: vi.fn(),
  691. addListener: vi.fn(),
  692. matches: true,
  693. removeEventListener: vi.fn(),
  694. removeListener: vi.fn(),
  695. })),
  696. sessionStorage: {
  697. getItem: vi.fn(() => null),
  698. removeItem: vi.fn(),
  699. setItem: vi.fn(),
  700. },
  701. });
  702. const html = await renderWorkspaceShell({
  703. initialWebRemoteControlMobileNavigationIntent: "chat",
  704. isSidePaneOpen: true,
  705. taskFindDialogProps: {
  706. open: true,
  707. placement: "chat",
  708. focusRequestId: 1,
  709. conversationMatchCount: 1,
  710. conversationMatchIndex: 0,
  711. fileChangeMatchCount: 1,
  712. fileChangeMatchIndex: 0,
  713. onOpenChange: vi.fn(),
  714. onConversationFindChange: vi.fn(),
  715. onConversationFindNavigate: vi.fn(),
  716. onFileChangeFindChange: vi.fn(),
  717. onFileChangeFindNavigate: vi.fn(),
  718. onOpenFileChanges: vi.fn(),
  719. },
  720. webRemoteControlWorkspaceSwitcher: {
  721. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  722. switchWorkspace: vi.fn(async () => {}),
  723. },
  724. });
  725. const chatContentStart = html.indexOf('data-testid="mobile-chat-content"');
  726. const chatOverlayStart = html.indexOf('data-testid="mobile-chat-overlay-prop"');
  727. expect(chatOverlayStart).toBeGreaterThan(chatContentStart);
  728. expect(html.slice(chatContentStart, chatOverlayStart)).not.toContain(
  729. 'placeholder="quickPick.find.placeholder.conversation"',
  730. );
  731. expect(html.slice(chatOverlayStart)).toContain(
  732. 'placeholder="quickPick.find.placeholder.conversation"',
  733. );
  734. vi.unstubAllGlobals();
  735. });
  736. it("keeps the default desktop shell layout classes unchanged", async () => {
  737. const html = await renderWorkspaceShell();
  738. expect(html).not.toContain("max-md:!flex-col");
  739. expect(html).not.toContain("max-md:[&amp;&gt;[data-panel][id=sidebar]]:!h-[min(42dvh,22rem)]");
  740. expect(html).toContain('data-mobile-stacked="false"');
  741. });
  742. it("renders the draft workspace header while a new task draft is active", async () => {
  743. const html = await renderWorkspaceShell({
  744. activeTaskId: null,
  745. isDesktop: true,
  746. workspaceShellZCodeState: {
  747. ...createWorkspaceShellProps().workspaceShellZCodeState,
  748. activeTaskId: null,
  749. },
  750. });
  751. expect(html).toContain('data-testid="workspace-header"');
  752. expect(html).toContain('data-workspace-header-variant="draft"');
  753. expect(html).toContain("<header");
  754. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  755. expect(html).not.toContain("absolute inset-x-0 top-0 z-10 h-10 [app-region:drag]");
  756. });
  757. it("does not render the draft drag region on web", async () => {
  758. const html = await renderWorkspaceShell({
  759. activeTaskId: null,
  760. isDesktop: false,
  761. workspaceShellZCodeState: {
  762. ...createWorkspaceShellProps().workspaceShellZCodeState,
  763. activeTaskId: null,
  764. },
  765. });
  766. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  767. expect(html).not.toContain('data-testid="terminal-toggle"');
  768. });
  769. it("uses the draft workspace header within Windows chrome", async () => {
  770. const html = await renderWorkspaceShell({
  771. activeTaskId: null,
  772. isDesktop: true,
  773. isMacDesktop: false,
  774. isWindowsDesktop: true,
  775. workspaceShellZCodeState: {
  776. ...createWorkspaceShellProps().workspaceShellZCodeState,
  777. activeTaskId: null,
  778. },
  779. });
  780. expect(html).toContain('data-workspace-header-variant="draft"');
  781. expect(html).not.toContain('data-testid="linux-window-controls"');
  782. });
  783. it("uses the draft workspace header within Linux chrome", async () => {
  784. const html = await renderWorkspaceShell({
  785. activeTaskId: null,
  786. isDesktop: true,
  787. isMacDesktop: false,
  788. isWindowsDesktop: false,
  789. workspaceShellZCodeState: {
  790. ...createWorkspaceShellProps().workspaceShellZCodeState,
  791. activeTaskId: null,
  792. },
  793. });
  794. expect(html).toContain('data-workspace-header-variant="draft"');
  795. expect(html).not.toContain('data-testid="linux-window-controls"');
  796. expect(html).toContain("rounded-xl");
  797. });
  798. it("renders the workspace header again after the draft is promoted to a task", async () => {
  799. const html = await renderWorkspaceShell({
  800. activeTaskId: "task-1",
  801. activeTaskTitle: "Task 1",
  802. workspaceShellZCodeState: {
  803. ...createWorkspaceShellProps().workspaceShellZCodeState,
  804. activeTaskId: "task-1",
  805. },
  806. });
  807. expect(html).toContain('data-testid="workspace-header"');
  808. expect(html).toContain('data-workspace-header-variant="task"');
  809. expect(html).not.toContain('data-testid="new-task-draft-drag-region"');
  810. });
  811. it("does not inject the workspace header into mobile remote chat while a new task draft is active", async () => {
  812. vi.stubGlobal("window", {
  813. innerHeight: 800,
  814. matchMedia: vi.fn(() => ({
  815. addEventListener: vi.fn(),
  816. addListener: vi.fn(),
  817. matches: true,
  818. removeEventListener: vi.fn(),
  819. removeListener: vi.fn(),
  820. })),
  821. sessionStorage: {
  822. getItem: vi.fn(() => null),
  823. removeItem: vi.fn(),
  824. setItem: vi.fn(),
  825. },
  826. });
  827. const html = await renderWorkspaceShell({
  828. activeTaskId: null,
  829. initialWebRemoteControlMobileNavigationIntent: "chat",
  830. webRemoteControlWorkspaceSwitcher: {
  831. listWorkspaces: vi.fn(async () => ({ workspaces: [] })),
  832. switchWorkspace: vi.fn(async () => {}),
  833. },
  834. workspaceShellZCodeState: {
  835. ...createWorkspaceShellProps().workspaceShellZCodeState,
  836. activeTaskId: null,
  837. },
  838. });
  839. expect(html).toContain('data-testid="web-remote-mobile-shell"');
  840. expect(html).not.toContain('data-testid="workspace-header"');
  841. vi.unstubAllGlobals();
  842. });
  843. it("removes the legacy Linux floating chrome", async () => {
  844. const html = await renderWorkspaceShell({ isDesktop: true, isMacDesktop: false, isWindowsDesktop: false });
  845. expect(html).not.toContain('data-testid="linux-window-controls"');
  846. expect(html).not.toContain("w-[120px]");
  847. expect(html).toContain("rounded-xl");
  848. });
  849. });
  850. it.each([
  851. { isDesktop: true, isMacDesktop: true },
  852. { isDesktop: true, isWindowsDesktop: true },
  853. { isDesktop: true, isMacDesktop: false, isWindowsDesktop: false },
  854. ])("keeps desktop panel outer padding consistent: %j", async (platform) => {
  855. const html = await renderWorkspaceShell(platform);
  856. expect(html).toMatch(/id="content"[^>]*p-1 pl-0 pt-0/);
  857. expect(html).toContain('class="h-1 w-full [app-region:drag]"');
  858. });
  859. it("places the workspace header inside the independent conversation frame", async () => {
  860. const html = await renderWorkspaceShell({ isDesktop: true, isMacDesktop: true });
  861. expect(html).toContain('data-workspace-conversation-frame="true"');
  862. expect(html.indexOf('data-panel-id="conversation-column"')).toBeLessThan(html.indexOf('data-testid="workspace-header"'));
  863. expect(html.indexOf('data-workspace-conversation-frame="true"')).toBeLessThan(html.indexOf('data-testid="workspace-header"'));
  864. });