groupedLegacyInteraction.test.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { describe, expect, it } from "vitest";
  2. import type { ProjectTask, TaskGroupStructure } from "@/project-sidebar/contract.js";
  3. import { buildGroupedTaskView, groupedMoveCommand } from "@/project-sidebar/grouped/model.js";
  4. import {
  5. moveTaskToGroupStart,
  6. moveTaskToRootAroundGroup,
  7. moveGroupAroundTopLevelNode,
  8. moveTaskToTopByMenu,
  9. } from "@/project-sidebar/grouped/view.js";
  10. import { taskKey } from "@/project-sidebar/grouped/ids.js";
  11. import { groupTaskRef, taskGroupKey } from "@/project-sidebar/grouped-view.js";
  12. const task = (id: string, extra = {}): ProjectTask => ({
  13. taskId: id,
  14. workspacePath: "/workspace",
  15. hostId: "local",
  16. projectId: null,
  17. title: id,
  18. mode: "build",
  19. traceId: id,
  20. pinned: false,
  21. archived: false,
  22. createdAt: 1,
  23. updatedAt: 2,
  24. ...extra,
  25. });
  26. const a = task("a"),
  27. b = task("b"),
  28. hidden = task("hidden", { archived: true });
  29. const structure: TaskGroupStructure = {
  30. groups: [
  31. { id: "g", title: "Group", color: "blue", createdAt: 1, updatedAt: 1 },
  32. { id: "empty", title: "Empty", color: "gray", createdAt: 1, updatedAt: 1 },
  33. ],
  34. members: [
  35. { groupId: "g", workspaceKey: a.workspacePath, taskId: a.taskId, sortOrder: 0 },
  36. { groupId: "g", workspaceKey: hidden.workspacePath, taskId: hidden.taskId, sortOrder: 1 },
  37. ],
  38. order: [
  39. { type: "group", key: "g", sortOrder: 0 },
  40. { type: "task", key: taskGroupKey(b), sortOrder: 1 },
  41. { type: "group", key: "empty", sortOrder: 2 },
  42. ],
  43. };
  44. const origin = () => buildGroupedTaskView([a, b, hidden], structure);
  45. describe("GRP11:旧拖动语义只提交单节点,不回写可见列表", () => {
  46. it("拖进空组保持旧 preview,提交保留来源且不包含隐藏成员", () => {
  47. const view = origin();
  48. const preview = moveTaskToGroupStart(view, { activeTaskKey: taskKey(a), groupId: "empty" });
  49. expect(groupedMoveCommand(view, preview, { type: "task", task: groupTaskRef(a) })).toEqual({
  50. node: { type: "task", task: groupTaskRef(a) },
  51. sourceGroupId: "g",
  52. groupId: "empty",
  53. });
  54. expect(structure.members).toHaveLength(2);
  55. expect(view.nodes[0]).toMatchObject({ type: "group", tasks: [a] });
  56. });
  57. it("拖过折叠组保留旧顶层前后位置,不能误当成入组", () => {
  58. const view = origin();
  59. const preview = moveTaskToRootAroundGroup(view, {
  60. activeTaskKey: taskKey(a),
  61. groupId: "empty",
  62. position: "after",
  63. });
  64. expect(groupedMoveCommand(view, preview, { type: "task", task: groupTaskRef(a) })).toEqual({
  65. node: { type: "task", task: groupTaskRef(a) },
  66. sourceGroupId: "g",
  67. groupId: null,
  68. anchor: { node: { type: "group", groupId: "empty" }, side: "after" },
  69. });
  70. });
  71. it("组和顶层任务混排只移动当前组", () => {
  72. const view = origin();
  73. const preview = moveGroupAroundTopLevelNode(view, {
  74. activeGroupId: "empty",
  75. over: { type: "task", taskKey: taskKey(b) },
  76. position: "before",
  77. });
  78. expect(groupedMoveCommand(view, preview, { type: "group", groupId: "empty" })).toEqual({
  79. node: { type: "group", groupId: "empty" },
  80. sourceGroupId: null,
  81. groupId: null,
  82. anchor: { node: { type: "task", task: groupTaskRef(b) }, side: "before" },
  83. });
  84. });
  85. it("旧移到顶部只调整所在层级,不置顶、不改项目", () => {
  86. const view = origin();
  87. const preview = moveTaskToTopByMenu(view, b);
  88. expect(groupedMoveCommand(view, preview, { type: "task", task: groupTaskRef(b) })).toEqual({
  89. node: { type: "task", task: groupTaskRef(b) },
  90. sourceGroupId: null,
  91. groupId: null,
  92. anchor: { node: { type: "group", groupId: "g" }, side: "before" },
  93. });
  94. expect(b.pinned).toBe(false);
  95. expect(b.projectId).toBeNull();
  96. });
  97. it("取消、无移动和分屏接管不产生组织命令", () => {
  98. const view = origin();
  99. expect(groupedMoveCommand(view, view, { type: "task", task: groupTaskRef(a) })).toBeNull();
  100. });
  101. it("同路径同 taskId 的两个 Host 不串行", () => {
  102. const remote = task("a", {
  103. workspaceIdentity: "remote:server:other:/workspace",
  104. hostId: "remote:server:other",
  105. });
  106. const view = buildGroupedTaskView([a, remote], structure);
  107. const preview = moveTaskToGroupStart(view, { activeTaskKey: taskKey(remote), groupId: "g" });
  108. expect(
  109. groupedMoveCommand(view, preview, { type: "task", task: groupTaskRef(remote) }),
  110. ).toMatchObject({
  111. node: { task: { workspaceIdentity: remote.workspaceIdentity, hostId: remote.hostId } },
  112. sourceGroupId: null,
  113. groupId: "g",
  114. });
  115. });
  116. });