groupedOffPeakSystemGroup.test.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // D48-A:闲时侧栏分组收敛为 tasks-index 真实系统分组后的 UI 契约。
  2. // 纯逻辑走 group-title 单测;组件接线沿用仓库惯例做源码断言。
  3. import { readFileSync } from "node:fs";
  4. import { resolve } from "node:path";
  5. import { describe, expect, it } from "vitest";
  6. import {
  7. CRON_DEFAULT_GROUP_ID,
  8. OFF_PEAK_DEFAULT_GROUP_ID,
  9. } from "@zcode/shared";
  10. import { getTaskGroupDisplayTitle } from "@/workspace-grouped-tasks/group-title.js";
  11. import enUS from "@/i18n/locales/en-US.js";
  12. import zhCN from "@/i18n/locales/zh-CN.js";
  13. function readSource(relativePath: string): string {
  14. return readFileSync(resolve(process.cwd(), relativePath), "utf8");
  15. }
  16. describe("off-peak 系统分组 id 与标题", () => {
  17. it("shared 常量与 cron 并列且互不相同", () => {
  18. expect(OFF_PEAK_DEFAULT_GROUP_ID).toBe("zcode-default-group-off-peak");
  19. expect(OFF_PEAK_DEFAULT_GROUP_ID).not.toBe(CRON_DEFAULT_GROUP_ID);
  20. });
  21. it("getTaskGroupDisplayTitle 本地化两个系统分组并透传普通分组标题", () => {
  22. const titles = { cron: "定时任务", offPeak: "闲时任务" };
  23. expect(
  24. getTaskGroupDisplayTitle({ id: CRON_DEFAULT_GROUP_ID, title: "cron" }, titles),
  25. ).toBe("定时任务");
  26. expect(
  27. getTaskGroupDisplayTitle(
  28. { id: OFF_PEAK_DEFAULT_GROUP_ID, title: "off-peak" },
  29. titles,
  30. ),
  31. ).toBe("闲时任务");
  32. expect(
  33. getTaskGroupDisplayTitle({ id: "custom", title: "My Group" }, titles),
  34. ).toBe("My Group");
  35. });
  36. it("侧栏组标题的 i18n key 在两个语言包都存在", () => {
  37. expect(enUS["offPeak.sidebar.groupTitle"]).toBe("Idle-time tasks");
  38. expect(zhCN["offPeak.sidebar.groupTitle"]).toBeTruthy();
  39. });
  40. });
  41. describe("grouped UI 收敛接线(源码断言)", () => {
  42. it("GroupItem 用 isSystemGroup 统一裁剪改名/解散,标题走本地化", () => {
  43. const source = readSource(
  44. "packages/ui/src/workspace-grouped-tasks/group-item.tsx",
  45. );
  46. expect(source).toContain("OFF_PEAK_DEFAULT_GROUP_ID");
  47. expect(source).toContain("const isSystemGroup = isCronGroup || isOffPeakGroup;");
  48. expect(source).not.toContain("{isCronGroup ? null : (");
  49. expect(source.match(/\{isSystemGroup \? null : \(/g)).toHaveLength(2);
  50. expect(source).toContain('offPeak: intl.formatMessage({ id: "offPeak.sidebar.groupTitle" })');
  51. });
  52. it("sticky header 对系统分组裁剪解散项(修掉 cron 存量缺口)", () => {
  53. const source = readSource(
  54. "packages/ui/src/workspace-grouped-tasks/sticky-group-header.tsx",
  55. );
  56. expect(source).toContain("OFF_PEAK_DEFAULT_GROUP_ID");
  57. expect(source).toContain("isSystemGroup ? null : (");
  58. });
  59. it("Section 把闲时组头「+」路由到 Automations,且投影去重已退役", () => {
  60. const source = readSource("packages/ui/src/WorkspaceGroupedTasksSection.tsx");
  61. expect(source).toContain("node.group.id === OFF_PEAK_DEFAULT_GROUP_ID");
  62. expect(source).toContain("onOpenAutomations?.()");
  63. expect(source).not.toContain("filterGroupedTaskViewForOffPeakSessions");
  64. expect(source).not.toContain("useOffPeakTaskStore");
  65. expect(source).not.toContain("excludeOffPeakSessions");
  66. });
  67. it("拖拽浮层与 sticky header 的标题同样本地化闲时组", () => {
  68. for (const relativePath of [
  69. "packages/ui/src/workspace-grouped-tasks/group-drag-overlay.tsx",
  70. "packages/ui/src/workspace-grouped-tasks/sticky-group-header.tsx",
  71. ]) {
  72. expect(readSource(relativePath)).toContain(
  73. 'offPeak: intl.formatMessage({ id: "offPeak.sidebar.groupTitle" })',
  74. );
  75. }
  76. });
  77. });