v4WorkspaceDraftDragDrop.test.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
  4. import {
  5. INITIAL_PANE_LAYOUT,
  6. V4_PRIMARY_PANE_ID,
  7. leafPaneIds,
  8. usePaneLayoutStore,
  9. } from "@/v4/paneLayoutStore.js";
  10. import { useWorkbenchGroupStore } from "@/v4/workbenchGroupStore.js";
  11. import type { WorkbenchLeafPaneProps } from "@/v4/WorkbenchPane.js";
  12. import { V4WorkspaceChatArea } from "@/v4/V4WorkspaceChatArea.js";
  13. const leafPaneCapture = vi.hoisted(() => ({
  14. props: [] as WorkbenchLeafPaneProps[],
  15. }));
  16. vi.mock("@/v4/WorkbenchPane.js", async () => {
  17. const React = await import("react");
  18. return {
  19. WorkbenchLeafPane: (props: WorkbenchLeafPaneProps) => {
  20. leafPaneCapture.props.push(props);
  21. return React.createElement("div", {
  22. "data-pane-id": props.paneId,
  23. });
  24. },
  25. };
  26. });
  27. vi.mock("@/v4/WorkbenchSplitDivider.js", async () => {
  28. const React = await import("react");
  29. return {
  30. WorkbenchSplitDivider: () => React.createElement("div", { "data-testid": "mock-divider" }),
  31. };
  32. });
  33. function resetWorkbenchState(): void {
  34. usePaneLayoutStore.setState({
  35. root: INITIAL_PANE_LAYOUT.root,
  36. panes: INITIAL_PANE_LAYOUT.panes,
  37. focusedPaneId: INITIAL_PANE_LAYOUT.focusedPaneId,
  38. });
  39. useWorkbenchGroupStore.getState().resetWorkbenchGroups();
  40. leafPaneCapture.props = [];
  41. }
  42. describe("V4WorkspaceChatArea split entries", () => {
  43. beforeEach(resetWorkbenchState);
  44. afterEach(resetWorkbenchState);
  45. // 拆分入口已整体下线(docs/v4-split-pane-workbench.md):pane 不再接收拖放分屏与拆分回调,
  46. // 既有布局仍只负责渲染、聚焦与关闭。
  47. it("does not hand split or drop callbacks to leaf panes", () => {
  48. renderToStaticMarkup(
  49. createElement(V4WorkspaceChatArea, {
  50. sessionId: null,
  51. workspacePath: "/workspace",
  52. isDesktop: true,
  53. }),
  54. );
  55. const primaryPane = leafPaneCapture.props[0];
  56. expect(primaryPane?.paneId).toBe(V4_PRIMARY_PANE_ID);
  57. expect("canDropSession" in primaryPane!).toBe(false);
  58. expect("onDropSession" in primaryPane!).toBe(false);
  59. expect("onSplit" in primaryPane!).toBe(false);
  60. expect("canSplit" in primaryPane!).toBe(false);
  61. expect(leafPaneIds(usePaneLayoutStore.getState().root)).toEqual([V4_PRIMARY_PANE_ID]);
  62. });
  63. });