settingsPageConfig.test.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { afterEach, describe, expect, it, vi } from "vitest";
  2. import { BarChart3, Blocks, Cable, Package, WandSparkles } from "lucide-react";
  3. import enUS from "../src/i18n/locales/en-US.js";
  4. import zhCN from "../src/i18n/locales/zh-CN.js";
  5. async function loadSettingsPageConfig(env: "test" | "production") {
  6. vi.resetModules();
  7. vi.doMock("@zcode/shared", async () => {
  8. const actual = await vi.importActual<typeof import("@zcode/shared")>("@zcode/shared");
  9. return {
  10. ...actual,
  11. ZCODE_ENV: env,
  12. };
  13. });
  14. return import("../src/settings/settingsPageConfig.js");
  15. }
  16. afterEach(() => {
  17. vi.resetModules();
  18. vi.unstubAllGlobals();
  19. });
  20. describe("settingsPageConfig", () => {
  21. it("按设置页心智顺序展示 test 分区", async () => {
  22. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  23. const { settingsSectionGroups, settingsSections } = createSettingsPageConfig({});
  24. expect(
  25. settingsSectionGroups.map((group) => ({
  26. id: group.id,
  27. sections: group.sections.map((section) => section.id),
  28. })),
  29. ).toEqual([
  30. {
  31. id: "basics",
  32. sections: ["general", "appearance", "modelProvider", "browser", "shortcuts"],
  33. },
  34. {
  35. id: "agentCapabilities",
  36. sections: ["memory", "subagents", "plugin", "mcp", "skill", "commands", "hooks"],
  37. },
  38. {
  39. id: "dataAndStats",
  40. sections: ["usage"],
  41. },
  42. ]);
  43. expect(settingsSections.map((section) => section.id)).toEqual([
  44. "general",
  45. "appearance",
  46. "modelProvider",
  47. "memory",
  48. "subagents",
  49. "plugin",
  50. "mcp",
  51. "skill",
  52. "commands",
  53. "hooks",
  54. "browser",
  55. "shortcuts",
  56. "usage",
  57. ]);
  58. });
  59. it("按设置页心智顺序展示 production 分区并保留 usage", async () => {
  60. const { createSettingsPageConfig } = await loadSettingsPageConfig("production");
  61. const { settingsSections } = createSettingsPageConfig({});
  62. expect(settingsSections.map((section) => section.id)).toEqual([
  63. "general",
  64. "appearance",
  65. "modelProvider",
  66. "memory",
  67. "subagents",
  68. "plugin",
  69. "mcp",
  70. "skill",
  71. "commands",
  72. "hooks",
  73. "browser",
  74. "shortcuts",
  75. "usage",
  76. ]);
  77. });
  78. it("Plugins 内容标题不再配置 beta 徽标", async () => {
  79. const { SETTINGS_SECTIONS } = await loadSettingsPageConfig("test");
  80. const pluginsSection = SETTINGS_SECTIONS.find((section) => section.id === "plugin");
  81. expect(pluginsSection?.titleBadgeId).toBeUndefined();
  82. });
  83. it("Models 与 Plugins 菜单使用统一资源图标", async () => {
  84. const { SETTINGS_SECTIONS } = await loadSettingsPageConfig("test");
  85. expect(SETTINGS_SECTIONS.find((section) => section.id === "modelProvider")?.icon).toBe(Package);
  86. expect(SETTINGS_SECTIONS.find((section) => section.id === "plugin")?.icon).toBe(Blocks);
  87. expect(SETTINGS_SECTIONS.find((section) => section.id === "mcp")?.icon).toBe(Cable);
  88. expect(SETTINGS_SECTIONS.find((section) => section.id === "skill")?.icon).toBe(WandSparkles);
  89. });
  90. it("Usage 分区文案和头像菜单使用统计入口保持一致", async () => {
  91. const { SETTINGS_SECTIONS } = await loadSettingsPageConfig("test");
  92. const usageSection = SETTINGS_SECTIONS.find((section) => section.id === "usage");
  93. expect(usageSection?.icon).toBe(BarChart3);
  94. expect(enUS["settings.usageTitle"]).toBe(enUS["sidebar.usage.plan.openStats"]);
  95. expect(enUS["settings.usage.sectionTitle"]).toBe(enUS["sidebar.usage.plan.openStats"]);
  96. expect(zhCN["settings.usageTitle"]).toBe(zhCN["sidebar.usage.plan.openStats"]);
  97. });
  98. it("侧栏分组标题同时提供中英文文案", () => {
  99. expect(enUS["settings.sidebar.group.basics"]).toBe("Basics");
  100. expect(enUS["settings.sidebar.group.agentCapabilities"]).toBe("Agent capabilities");
  101. expect(enUS["settings.sidebar.group.dataAndStats"]).toBe("Data and statistics");
  102. expect(zhCN["settings.sidebar.group.basics"]).toBe("基础设置");
  103. expect(zhCN["settings.sidebar.group.agentCapabilities"]).toBe("Agent 能力");
  104. expect(zhCN["settings.sidebar.group.dataAndStats"]).toBe("数据与统计");
  105. });
  106. it.each([
  107. ["macOS", { isMacDesktop: true }, true],
  108. ["Windows", { isWindowsDesktop: true }, true],
  109. ["Linux 桌面", { isDesktop: true }, true],
  110. ["Web", {}, false],
  111. ] as const)("%s 的电脑控制入口符合桌面平台边界", async (_name, options, expected) => {
  112. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  113. const { settingsSections } = createSettingsPageConfig(options);
  114. expect(settingsSections.some((section) => section.id === "computerUse")).toBe(expected);
  115. });
  116. it("桌面平台的电脑控制排在基础设置的浏览器之后", async () => {
  117. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  118. const { settingsSectionGroups } = createSettingsPageConfig({ isMacDesktop: true });
  119. const basics = settingsSectionGroups.find((group) => group.id === "basics");
  120. expect(basics?.sections.map((section) => section.id)).toEqual([
  121. "general",
  122. "appearance",
  123. "modelProvider",
  124. "browser",
  125. "computerUse",
  126. "shortcuts",
  127. ]);
  128. expect(
  129. settingsSectionGroups
  130. .find((group) => group.id === "agentCapabilities")
  131. ?.sections.some((section) => section.id === "computerUse"),
  132. ).toBe(false);
  133. });
  134. it("不可见的电脑控制落点回退到 general", async () => {
  135. const { createSettingsPageConfig, resolveSettingsSectionForPlatform } =
  136. await loadSettingsPageConfig("test");
  137. const { settingsSections } = createSettingsPageConfig({});
  138. expect(resolveSettingsSectionForPlatform("computerUse", settingsSections, "general")).toBe(
  139. "general",
  140. );
  141. });
  142. });