settingsBackButtonContract.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { readFile } from "node:fs/promises";
  2. import { describe, expect, it } from "vitest";
  3. import enUS from "../src/i18n/locales/en-US.js";
  4. import zhCN from "../src/i18n/locales/zh-CN.js";
  5. const secondarySurfaces = [
  6. "CommandsSection.tsx",
  7. "HookForm.tsx",
  8. "MemorySettingsViewer.tsx",
  9. "SubagentsSection.tsx",
  10. "McpSettingsSection.tsx",
  11. "PluginStoreDetailView.tsx",
  12. ] as const;
  13. const secondaryBackMessageIds = [
  14. "settings.plugins.store.back",
  15. "settings.commands.backToList",
  16. "settings.hooks.backToList",
  17. "settings.subagents.backToList",
  18. "settings.mcp.form.backToList",
  19. ] as const;
  20. describe("settings secondary navigation", () => {
  21. it("二级设置页由标题栏面包屑导航,不再渲染页内返回按钮", async () => {
  22. for (const fileName of secondarySurfaces) {
  23. const source = await readFile(
  24. new URL(`../src/settings/${fileName}`, import.meta.url),
  25. "utf8",
  26. );
  27. expect(source, fileName).not.toContain("<SettingsBackButton");
  28. }
  29. });
  30. it("自动化、闲时任务、模型购买与升级返回入口保持独立", async () => {
  31. const automation = await readFile(
  32. new URL("../src/settings/AutomationEditView.tsx", import.meta.url),
  33. "utf8",
  34. );
  35. const offPeak = await readFile(
  36. new URL("../src/settings/OffPeakEditView.tsx", import.meta.url),
  37. "utf8",
  38. );
  39. // 原生购买面板已下线(购买走 webview 弹窗),返回入口契约只保留闲时任务与升级按钮。
  40. const upgrade = await readFile(
  41. new URL(
  42. "../src/settings/model-provider-section/CodingPlanStatusActions.tsx",
  43. import.meta.url,
  44. ),
  45. "utf8",
  46. );
  47. expect(automation).not.toContain("SettingsBackButton");
  48. expect(offPeak).not.toContain("SettingsBackButton");
  49. expect(upgrade).not.toContain("SettingsBackButton");
  50. });
  51. it("所有二级设置页返回文案不附带业务对象", () => {
  52. for (const messageId of secondaryBackMessageIds) {
  53. expect(zhCN[messageId], messageId).toBe("返回");
  54. expect(enUS[messageId], messageId).toBe("Back");
  55. }
  56. });
  57. });