workspaceSidebarDrag.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { readSourceText } from "./readSourceText.js";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. import type { WorkspaceTabState } from "@/store/tabStore.js";
  5. import {
  6. resolveWorkspaceDragGlobalIndices,
  7. resolveWorkspaceDragExpanded,
  8. resolveWorkspaceDragSiblingDisplacement,
  9. workspaceVerticalListSortingStrategy,
  10. } from "@/lib/workspaceSidebarDrag.js";
  11. function tab(id: string, purpose?: "conversation"): WorkspaceTabState {
  12. return {
  13. id,
  14. kind: "workspace",
  15. label: id,
  16. workspacePath: `/${id}`,
  17. ...(purpose ? { workspacePurpose: purpose } : {}),
  18. };
  19. }
  20. describe("workspace sidebar drag", () => {
  21. it("moves siblings by the collapsed row height instead of expanded height", () => {
  22. expect(
  23. resolveWorkspaceDragSiblingDisplacement({
  24. activeIndex: 1,
  25. index: 0,
  26. itemGap: 8,
  27. overIndex: 0,
  28. }),
  29. ).toBe(40);
  30. expect(
  31. resolveWorkspaceDragSiblingDisplacement({
  32. activeIndex: 0,
  33. index: 1,
  34. itemGap: 8,
  35. overIndex: 1,
  36. }),
  37. ).toBe(-40);
  38. const transform = workspaceVerticalListSortingStrategy({
  39. activeIndex: 1,
  40. activeNodeRect: null,
  41. index: 0,
  42. overIndex: 0,
  43. rects: [
  44. { top: 280, bottom: 508, left: 8, right: 337, width: 329, height: 228 },
  45. { top: 516, bottom: 744, left: 8, right: 337, width: 329, height: 228 },
  46. ],
  47. });
  48. expect(transform).toMatchObject({ y: 40, scaleX: 1, scaleY: 1 });
  49. });
  50. it("uses the requested workspace preview sizing", () => {
  51. const workspaceSource = readSourceText(
  52. resolve(process.cwd(), "packages/ui/src/WorkspaceSidebar.tsx"),
  53. "utf8",
  54. );
  55. const workspacePreviewSizing =
  56. "h-8 px-2.5 gap-2 [&_svg]:pointer-events-none [&_svg]:size-3.5 [&_svg]:shrink-0";
  57. expect(workspaceSource).toContain("border-border bg-background");
  58. expect(workspaceSource).toContain("text-ui-base text-foreground shadow-lg");
  59. expect(workspaceSource).toContain("cursor-grabbing");
  60. expect(workspaceSource).toContain(workspacePreviewSizing);
  61. });
  62. it("keeps native workbench dragging enabled inside project rows", () => {
  63. const workspaceItemSource = readSourceText(
  64. resolve(process.cwd(), "packages/ui/src/WorkspaceSidebarItem.tsx"),
  65. "utf8",
  66. );
  67. const taskListItemSource = readSourceText(
  68. resolve(process.cwd(), "packages/ui/src/TaskListItem.tsx"),
  69. "utf8",
  70. );
  71. expect(workspaceItemSource).not.toContain("allowWorkbenchDrag");
  72. expect(taskListItemSource).not.toContain("allowWorkbenchDrag");
  73. expect(taskListItemSource).toContain(
  74. "const canDragToWorkbench =\n !workspaceActionsDisabled",
  75. );
  76. });
  77. it("temporarily collapses only the expanded active workspace", () => {
  78. expect(
  79. resolveWorkspaceDragExpanded({
  80. activeDragId: "a",
  81. expanded: true,
  82. tabId: "a",
  83. }),
  84. ).toBe(false);
  85. expect(
  86. resolveWorkspaceDragExpanded({
  87. activeDragId: "a",
  88. expanded: true,
  89. tabId: "b",
  90. }),
  91. ).toBe(true);
  92. expect(
  93. resolveWorkspaceDragExpanded({
  94. activeDragId: "a",
  95. expanded: false,
  96. tabId: "a",
  97. }),
  98. ).toBe(false);
  99. });
  100. it("maps visible project order back to global workspace indices", () => {
  101. const conversation = tab("conversation", "conversation");
  102. const projectA = tab("a");
  103. const projectB = tab("b");
  104. expect(
  105. resolveWorkspaceDragGlobalIndices({
  106. activeId: "b",
  107. overId: "a",
  108. projectTabs: [projectA, projectB],
  109. workspaceTabs: [conversation, projectA, projectB],
  110. }),
  111. ).toEqual({ fromIndex: 2, toIndex: 1 });
  112. });
  113. });