v4WorkbenchPaneActiveDim.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { V4_PRIMARY_PANE_ID } from "@/v4/paneLayoutStore.js";
  5. import {
  6. resolvePaneActiveSelectionSideChatSessionId,
  7. WorkbenchLeafPane,
  8. type WorkbenchShellBinding,
  9. } from "@/v4/WorkbenchPane.js";
  10. vi.mock("@/v4/SessionPane.js", async () => {
  11. const React = await import("react");
  12. return {
  13. SessionPane: (props: { onDropTargetControllerChange?: unknown }) =>
  14. React.createElement("div", {
  15. "data-testid": "mock-session-pane",
  16. "data-draft-drop-target": Boolean(props.onDropTargetControllerChange),
  17. }),
  18. };
  19. });
  20. vi.mock("@/v4/V4ConversationContext.js", async () => {
  21. const React = await import("react");
  22. return {
  23. V4PaneConversationProvider: ({ children }: { children: ReactNode }) =>
  24. React.createElement("div", { "data-testid": "mock-provider" }, children),
  25. };
  26. });
  27. function renderWorkbenchPane({
  28. focused,
  29. showFocusIndicator,
  30. sessionId = "sess-primary",
  31. }: {
  32. focused: boolean;
  33. showFocusIndicator: boolean;
  34. sessionId?: string | null;
  35. }): string {
  36. const shell = {
  37. workspacePath: "/repo",
  38. sessionId,
  39. onPrimaryDraftDropTargetControllerChange: vi.fn(),
  40. } as unknown as WorkbenchShellBinding;
  41. return renderToStaticMarkup(
  42. createElement(WorkbenchLeafPane, {
  43. paneId: V4_PRIMARY_PANE_ID,
  44. rect: { left: "0%", top: "0%", width: "100%", height: "100%" },
  45. focused,
  46. showFocusIndicator,
  47. canSplit: true,
  48. shellWorkspaceKey: "/repo",
  49. binding: null,
  50. shell,
  51. onFocusRequest: vi.fn(),
  52. onSplit: vi.fn(),
  53. onClosePane: vi.fn(),
  54. onConfirmRestoredSession: vi.fn(),
  55. onBindSession: vi.fn(),
  56. }),
  57. );
  58. }
  59. describe("WorkbenchLeafPane inactive visual state", () => {
  60. it("publishes the header drop target only while the primary pane is a draft", () => {
  61. const draft = renderWorkbenchPane({
  62. focused: true,
  63. showFocusIndicator: false,
  64. sessionId: null,
  65. });
  66. const session = renderWorkbenchPane({
  67. focused: true,
  68. showFocusIndicator: false,
  69. sessionId: "A",
  70. });
  71. expect(draft).toContain('data-draft-drop-target="true"');
  72. expect(session).toContain('data-draft-drop-target="false"');
  73. });
  74. it("dims only non-focused panes when the workbench has multiple panes", () => {
  75. const inactiveMarkup = renderWorkbenchPane({
  76. focused: false,
  77. showFocusIndicator: true,
  78. });
  79. const activeMarkup = renderWorkbenchPane({
  80. focused: true,
  81. showFocusIndicator: true,
  82. });
  83. const singlePaneMarkup = renderWorkbenchPane({
  84. focused: false,
  85. showFocusIndicator: false,
  86. });
  87. expect(inactiveMarkup).toContain('data-v4-pane-inactive-overlay="true"');
  88. expect(inactiveMarkup).toContain("pointer-events-none");
  89. expect(inactiveMarkup).toContain("z-30");
  90. expect(activeMarkup).not.toContain('data-v4-pane-inactive-overlay="true"');
  91. expect(singlePaneMarkup).not.toContain('data-v4-pane-inactive-overlay="true"');
  92. });
  93. });
  94. describe("resolvePaneActiveSelectionSideChatSessionId", () => {
  95. it("routes the active auxiliary child to a split pane that owns the shell active task", () => {
  96. expect(
  97. resolvePaneActiveSelectionSideChatSessionId("sess-split", "sess-split", "sess-side"),
  98. ).toBe("sess-side");
  99. });
  100. it("does not leak the active auxiliary child to another pane", () => {
  101. expect(
  102. resolvePaneActiveSelectionSideChatSessionId("sess-primary", "sess-split", "sess-side"),
  103. ).toBeNull();
  104. });
  105. });