workspaceNavigationHistory.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. createTaskNavigationHistory,
  4. goBack,
  5. goForward,
  6. pushAutomationsNavEntry,
  7. pushPluginStoreNavEntry,
  8. pushNavEntry,
  9. removeTaskFromHistory,
  10. } from "@/lib/taskNavigationHistory.js";
  11. describe("workspace navigation history", () => {
  12. it("将插件市场作为独立 workspace 目标记录", () => {
  13. const history = pushPluginStoreNavEntry(
  14. createTaskNavigationHistory(),
  15. "/repo",
  16. "ssh://dev/repo",
  17. );
  18. expect(history.entries).toEqual([
  19. { kind: "plugin-store", workspacePath: "/repo", workspaceIdentity: "ssh://dev/repo" },
  20. ]);
  21. });
  22. it("将 Automations 作为独立目标记录,并支持返回会话后再次前进", () => {
  23. const taskHistory = pushNavEntry(
  24. createTaskNavigationHistory(),
  25. "/workspace",
  26. "task-a",
  27. "local:/workspace",
  28. );
  29. const automationsHistory = pushAutomationsNavEntry(
  30. taskHistory,
  31. "/workspace",
  32. "local:/workspace",
  33. "automation-a",
  34. "idle",
  35. );
  36. const back = goBack(automationsHistory);
  37. expect(back?.entry).toMatchObject({
  38. kind: "task",
  39. taskId: "task-a",
  40. workspaceIdentity: "local:/workspace",
  41. });
  42. const forward = back ? goForward(back.history) : null;
  43. expect(forward?.entry).toEqual({
  44. kind: "automations",
  45. workspacePath: "/workspace",
  46. workspaceIdentity: "local:/workspace",
  47. automationId: "automation-a",
  48. automationTab: "idle",
  49. });
  50. });
  51. it("将 Automations tab intent 纳入相邻去重和前进恢复", () => {
  52. const scheduled = pushAutomationsNavEntry(
  53. createTaskNavigationHistory(),
  54. "/workspace",
  55. );
  56. const idle = pushAutomationsNavEntry(
  57. scheduled,
  58. "/workspace",
  59. undefined,
  60. undefined,
  61. "idle",
  62. );
  63. expect(idle.entries).toEqual([
  64. { kind: "automations", workspacePath: "/workspace" },
  65. { kind: "automations", workspacePath: "/workspace", automationTab: "idle" },
  66. ]);
  67. expect(
  68. pushAutomationsNavEntry(idle, "/workspace", undefined, undefined, "idle"),
  69. ).toBe(idle);
  70. });
  71. it("回放同一 Automations 目标不会重复入栈,删除 task 也不会误删 Automations", () => {
  72. const taskHistory = pushNavEntry(
  73. createTaskNavigationHistory(),
  74. "/workspace",
  75. "task-a",
  76. );
  77. const automationsHistory = pushAutomationsNavEntry(
  78. taskHistory,
  79. "/workspace",
  80. undefined,
  81. "automation-a",
  82. );
  83. expect(
  84. pushAutomationsNavEntry(
  85. automationsHistory,
  86. "/workspace",
  87. undefined,
  88. "automation-a",
  89. ),
  90. ).toBe(automationsHistory);
  91. expect(removeTaskFromHistory(automationsHistory, "task-a")).toEqual({
  92. entries: [
  93. {
  94. kind: "automations",
  95. workspacePath: "/workspace",
  96. automationId: "automation-a",
  97. },
  98. ],
  99. cursor: 0,
  100. });
  101. });
  102. });