v4WorkbenchPaneActiveDim.test.ts 2.9 KB

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