v4WorkspaceStatusPanelWiring.test.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 {
  5. GitRepositorySummary,
  6. ZCodeTaskChangeSummary,
  7. } from "@zcode/shared";
  8. import { V4ChatPane } from "@/v4/V4ChatPane.js";
  9. import { V4_PRIMARY_PANE_ID } from "@/v4/paneLayoutStore.js";
  10. import type { WorkbenchShellBinding } from "@/v4/WorkbenchPane.js";
  11. import { WorkbenchLeafPane } from "@/v4/WorkbenchPane.js";
  12. const sessionPaneCapture = vi.hoisted(() => ({
  13. props: [] as Array<Record<string, unknown>>,
  14. }));
  15. vi.mock("@/v4/SessionPane.js", async () => {
  16. const React = await import("react");
  17. return {
  18. SessionPane: (props: Record<string, unknown>) => {
  19. sessionPaneCapture.props.push(props);
  20. return React.createElement("div", {
  21. "data-testid": "mock-session-pane",
  22. });
  23. },
  24. };
  25. });
  26. vi.mock("@/v4/V4ConversationContext.js", async () => {
  27. const React = await import("react");
  28. return {
  29. V4ConversationProvider: ({ children }: { children: ReactNode }) =>
  30. React.createElement("div", { "data-testid": "mock-workspace-provider" }, children),
  31. V4PaneConversationProvider: ({ children }: { children: ReactNode }) =>
  32. React.createElement("div", { "data-testid": "mock-provider" }, children),
  33. };
  34. });
  35. function gitSummary(
  36. overrides: Partial<GitRepositorySummary> = {},
  37. ): GitRepositorySummary {
  38. return {
  39. workspacePath: "/repo",
  40. repoRoot: "/repo",
  41. workspaceInRepoPath: "",
  42. autoRefreshWatchPaths: [],
  43. branchName: "main",
  44. trackingBranchName: "origin/main",
  45. headRefType: "branch",
  46. ahead: 0,
  47. behind: 0,
  48. isDirty: true,
  49. isGitAvailable: true,
  50. isRepository: true,
  51. ...overrides,
  52. };
  53. }
  54. describe("v4 workspace status panel wiring", () => {
  55. it("passes shell git status props from the primary workbench pane to SessionPane", () => {
  56. sessionPaneCapture.props = [];
  57. const git = gitSummary();
  58. const activeTaskChangeSummary = {
  59. changedFiles: [],
  60. } as unknown as ZCodeTaskChangeSummary;
  61. const onRefreshGit = vi.fn();
  62. const onOpenGitReview = vi.fn();
  63. const onSummaryPanelVariantOverrideChange = vi.fn();
  64. const shell = {
  65. workspacePath: "/repo",
  66. workspaceIdentity: "local:/repo",
  67. sessionId: "sess-primary",
  68. gitSummary: git,
  69. gitDirtyFileCount: 2,
  70. gitWorktreeReviewSourceId: "unstaged",
  71. gitWorktreeChangeSummary: { added: 12, removed: 3 },
  72. activeTaskChangeSummary,
  73. summaryPanelVariantOverride: null,
  74. onSummaryPanelVariantOverrideChange,
  75. onRefreshGit,
  76. onOpenGitReview,
  77. } as unknown as WorkbenchShellBinding;
  78. renderToStaticMarkup(
  79. createElement(WorkbenchLeafPane, {
  80. paneId: V4_PRIMARY_PANE_ID,
  81. rect: { left: "0%", top: "0%", width: "100%", height: "100%" },
  82. focused: true,
  83. showFocusIndicator: false,
  84. canSplit: true,
  85. shellWorkspaceKey: "local:/repo",
  86. binding: null,
  87. shell,
  88. onFocusRequest: vi.fn(),
  89. onSplit: vi.fn(),
  90. onClosePane: vi.fn(),
  91. onBindSession: vi.fn(),
  92. }),
  93. );
  94. expect(sessionPaneCapture.props).toHaveLength(1);
  95. expect(sessionPaneCapture.props[0]).toMatchObject({
  96. gitSummary: git,
  97. gitDirtyFileCount: 2,
  98. gitWorktreeReviewSourceId: "unstaged",
  99. gitWorktreeChangeSummary: { added: 12, removed: 3 },
  100. activeTaskChangeSummary,
  101. summaryPanelVariantOverride: null,
  102. onSummaryPanelVariantOverrideChange,
  103. onRefreshGit,
  104. onOpenGitReview,
  105. });
  106. });
  107. it("passes the ordinary Git review action through the single-pane workspace path", () => {
  108. sessionPaneCapture.props = [];
  109. const onOpenGitReview = vi.fn();
  110. renderToStaticMarkup(
  111. createElement(V4ChatPane, {
  112. workspacePath: "/repo",
  113. sessionId: "sess-primary",
  114. gitWorktreeReviewSourceId: "staged",
  115. onOpenGitReview,
  116. }),
  117. );
  118. expect(sessionPaneCapture.props).toHaveLength(1);
  119. expect(sessionPaneCapture.props[0]).toMatchObject({
  120. gitWorktreeReviewSourceId: "staged",
  121. onOpenGitReview,
  122. });
  123. });
  124. it("passes plan-detail opening through the single-pane workspace path", () => {
  125. sessionPaneCapture.props = [];
  126. const onOpenPlanDetail = vi.fn();
  127. renderToStaticMarkup(
  128. createElement(V4ChatPane, {
  129. workspacePath: "/repo",
  130. sessionId: "sess-primary",
  131. onOpenPlanDetail,
  132. }),
  133. );
  134. expect(sessionPaneCapture.props).toHaveLength(1);
  135. expect(sessionPaneCapture.props[0]).toMatchObject({
  136. onOpenPlanDetail,
  137. });
  138. });
  139. it("passes read-only workbench bindings to SessionPane", () => {
  140. sessionPaneCapture.props = [];
  141. const shell = {
  142. workspacePath: "/repo",
  143. workspaceIdentity: "local:/repo",
  144. sessionId: "sess-primary",
  145. } as unknown as WorkbenchShellBinding;
  146. renderToStaticMarkup(
  147. createElement(WorkbenchLeafPane, {
  148. paneId: "pane-1",
  149. rect: { left: "50%", top: "0%", width: "50%", height: "100%" },
  150. focused: true,
  151. showFocusIndicator: true,
  152. canSplit: true,
  153. shellWorkspaceKey: "local:/repo",
  154. binding: {
  155. readOnly: true,
  156. sessionId: "sess-child",
  157. workspaceScope: {
  158. workspaceIdentity: "local:/repo",
  159. workspacePath: "/repo",
  160. },
  161. },
  162. shell,
  163. onFocusRequest: vi.fn(),
  164. onSplit: vi.fn(),
  165. onClosePane: vi.fn(),
  166. onBindSession: vi.fn(),
  167. }),
  168. );
  169. expect(sessionPaneCapture.props).toHaveLength(1);
  170. expect(sessionPaneCapture.props[0]).toMatchObject({
  171. readOnly: true,
  172. sessionId: "sess-child",
  173. });
  174. });
  175. });