settingsPageConfig.test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { afterEach, describe, expect, it, vi } from "vitest";
  2. import enUS from "../src/i18n/locales/en-US.js";
  3. import zhCN from "../src/i18n/locales/zh-CN.js";
  4. import { isSettingsSectionAvailable } from "../src/settings/settingsPageConfig.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("only exposes remote device management on desktop", () => {
  22. expect(isSettingsSectionAvailable("remoteDevices", true)).toBe(true);
  23. expect(isSettingsSectionAvailable("remoteDevices", false)).toBe(false);
  24. expect(isSettingsSectionAvailable("general", false)).toBe(true);
  25. });
  26. it("按设置页分组与顺序展示公开分区", async () => {
  27. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  28. const { settingsSectionGroups, settingsSections } = createSettingsPageConfig({});
  29. expect(
  30. settingsSectionGroups.map((group) => ({
  31. id: group.id,
  32. sections: group.sections.map((section) => section.id),
  33. })),
  34. ).toEqual([
  35. {
  36. id: "basics",
  37. sections: [
  38. "general",
  39. "appearance",
  40. "modelProvider",
  41. "browser",
  42. "remoteDevices",
  43. "shortcuts",
  44. ],
  45. },
  46. {
  47. id: "agentCapabilities",
  48. sections: ["memory", "subagents", "plugin", "mcp", "skill", "commands", "hooks"],
  49. },
  50. { id: "dataAndStats", sections: ["usage", "archives"] },
  51. ]);
  52. expect(settingsSections.map((section) => section.id)).toEqual([
  53. "general",
  54. "appearance",
  55. "modelProvider",
  56. "memory",
  57. "subagents",
  58. "plugin",
  59. "mcp",
  60. "skill",
  61. "commands",
  62. "hooks",
  63. "browser",
  64. "remoteDevices",
  65. "shortcuts",
  66. "usage",
  67. "archives",
  68. ]);
  69. });
  70. it("Usage 分区文案和头像菜单使用统计入口保持一致", () => {
  71. expect(enUS["settings.usageTitle"]).toBe(enUS["sidebar.usage.plan.openStats"]);
  72. expect(enUS["settings.usage.sectionTitle"]).toBe(enUS["sidebar.usage.plan.openStats"]);
  73. expect(zhCN["settings.usageTitle"]).toBe(zhCN["sidebar.usage.plan.openStats"]);
  74. });
  75. it.each([
  76. ["macOS", { isMacDesktop: true }, true],
  77. ["Windows", { isWindowsDesktop: true }, true],
  78. ["Linux 桌面", { isDesktop: true }, true],
  79. ["Web", {}, false],
  80. ] as const)("%s 的电脑控制入口符合桌面平台边界", async (_name, options, expected) => {
  81. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  82. const { settingsSections } = createSettingsPageConfig(options);
  83. expect(settingsSections.some((section) => section.id === "computerUse")).toBe(expected);
  84. });
  85. it("桌面平台的电脑控制排在基础设置的浏览器之后", async () => {
  86. const { createSettingsPageConfig } = await loadSettingsPageConfig("test");
  87. const { settingsSectionGroups } = createSettingsPageConfig({ isMacDesktop: true });
  88. const basics = settingsSectionGroups.find((group) => group.id === "basics");
  89. expect(basics?.sections.map((section) => section.id)).toEqual([
  90. "general",
  91. "appearance",
  92. "modelProvider",
  93. "browser",
  94. "remoteDevices",
  95. "computerUse",
  96. "shortcuts",
  97. ]);
  98. expect(
  99. settingsSectionGroups
  100. .find((group) => group.id === "agentCapabilities")
  101. ?.sections.some((section) => section.id === "computerUse"),
  102. ).toBe(false);
  103. });
  104. it("不可见的电脑控制落点回退到 general", async () => {
  105. const { createSettingsPageConfig, resolveSettingsSectionForPlatform } =
  106. await loadSettingsPageConfig("test");
  107. const { settingsSections } = createSettingsPageConfig({});
  108. expect(resolveSettingsSectionForPlatform("computerUse", settingsSections, "general")).toBe(
  109. "general",
  110. );
  111. });
  112. });