taskGroupedView.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { describe, it, expect } from "vitest";
  2. import {
  3. taskGroupTitleMessageId,
  4. projectGroupedNodes,
  5. taskGroupKey,
  6. } from "@/project-sidebar/grouped-view.js";
  7. import type { ProjectTask, TaskGroupStructure } from "@/project-sidebar/contract.js";
  8. const task = (id: string, patch = {}): ProjectTask => ({
  9. taskId: id,
  10. hostId: "local",
  11. workspacePath: "/same",
  12. title: id,
  13. traceId: id,
  14. mode: "build",
  15. projectId: "project",
  16. pinned: false,
  17. archived: false,
  18. createdAt: 1,
  19. updatedAt: 2,
  20. ...patch,
  21. });
  22. describe("grouped projection", () => {
  23. it("joins exact identities, keeps empty groups, and hides pinned/archived without changing membership", () => {
  24. const a = task("same"),
  25. b = task("same", { hostId: "remote:server:s", workspaceIdentity: "remote:server:s:/same" });
  26. const hidden = task("hidden", { archived: true });
  27. const structure: TaskGroupStructure = {
  28. groups: [{ id: "g", title: "G", color: "blue", createdAt: 1, updatedAt: 1 }],
  29. members: [
  30. { groupId: "g", workspaceKey: "/same", taskId: "same", sortOrder: 1 },
  31. { groupId: "g", workspaceKey: "/same", taskId: "hidden", sortOrder: 0 },
  32. ],
  33. order: [],
  34. };
  35. const before = JSON.stringify(structure);
  36. const rows = projectGroupedNodes([a, b, hidden], structure, new Set());
  37. expect(rows.map((row) => row.key)).toEqual([
  38. "group:g",
  39. `task:${taskGroupKey(a)}`,
  40. `task:${taskGroupKey(b)}`,
  41. ]);
  42. expect(
  43. projectGroupedNodes([{ ...a, pinned: true }], structure, new Set()).map((r) => r.type),
  44. ).toEqual(["group", "empty"]);
  45. expect(projectGroupedNodes([a], structure, new Set(["g"])).map((r) => r.type)).toEqual([
  46. "group",
  47. ]);
  48. expect(JSON.stringify(structure)).toBe(before);
  49. });
  50. it("uses persisted order without promoting a running task or losing a new row", () => {
  51. const a = task("a"),
  52. b = task("b"),
  53. c = task("c");
  54. const rows = projectGroupedNodes(
  55. [c, b, a],
  56. {
  57. groups: [],
  58. members: [],
  59. order: [
  60. { type: "task", key: taskGroupKey(a), sortOrder: 0 },
  61. { type: "task", key: taskGroupKey(b), sortOrder: 1 },
  62. ],
  63. },
  64. new Set(),
  65. );
  66. expect(rows.map((r) => r.type === "task" && r.task.taskId)).toEqual(["a", "b", "c"]);
  67. });
  68. });
  69. it("localizes only untouched system group names", () => {
  70. expect(taskGroupTitleMessageId({ id: "custom", title: "cron" })).toBeUndefined();
  71. expect(taskGroupTitleMessageId({ id: "zcode-default-group-cron", title: "cron" })).toBe(
  72. "taskGroup.cron",
  73. );
  74. expect(taskGroupTitleMessageId({ id: "zcode-default-group-off-peak", title: "off-peak" })).toBe(
  75. "taskGroup.offPeak",
  76. );
  77. expect(
  78. taskGroupTitleMessageId({ id: "zcode-default-group-cron", title: "renamed" }),
  79. ).toBeUndefined();
  80. });