settingsBreadcrumbCoverage.test.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { readSourceText } from "./readSourceText.js";
  2. import { describe, expect, it } from "vitest";
  3. function readSettingsSection(name: string): string {
  4. return readSourceText(new URL(`../src/settings/${name}.tsx`, import.meta.url), "utf8");
  5. }
  6. describe("Settings breadcrumb coverage", () => {
  7. it.each([
  8. "PluginStorePage",
  9. "PluginsSection",
  10. "SubagentsSection",
  11. "McpSettingsSection",
  12. "CommandsSection",
  13. "HooksSection",
  14. ])("projects page-level navigation from %s", (section) => {
  15. const source = readSettingsSection(section);
  16. expect(source).toContain("SettingsBreadcrumbReporter");
  17. expect(source).toContain("onSectionSelect");
  18. });
  19. it("projects automation edit navigation from the views that own dirty-state back handling", () => {
  20. for (const section of ["AutomationEditView", "OffPeakEditView"]) {
  21. const source = readSettingsSection(section);
  22. expect(source).toContain("SettingsBreadcrumbReporter");
  23. expect(source).toContain("onSectionSelect");
  24. }
  25. });
  26. it("uses the localized plugin display name for plugin detail breadcrumbs", () => {
  27. const source = readSettingsSection("PluginStorePage");
  28. expect(source).toContain("resolveItemDisplayName(detailItem, locale)");
  29. expect(source).not.toContain("[{ label: detailItem.name }]");
  30. });
  31. it("owns the plugin marketplace page title after moving outside Settings", () => {
  32. const source = readSettingsSection("PluginStorePage");
  33. expect(source).toContain('data-testid="plugin-store-title"');
  34. expect(source).toContain('id: "workspace.openPluginsSettings"');
  35. expect(source).toContain("text-2xl font-semibold tracking-tight text-foreground lg:text-3xl");
  36. });
  37. it("uses the plugin settings title after navigating from the marketplace", () => {
  38. const source = readSettingsSection("PluginsSection");
  39. expect(source).toContain('id: "settings.plugins.title"');
  40. expect(source).not.toContain('id: "settings.plugins.store.manageInstalled"');
  41. });
  42. it("keeps the installed plugins level in marketplace plugin details", () => {
  43. const source = readSettingsSection("PluginsSection");
  44. expect(source).toMatch(
  45. /mode === "plugin" &&[\s\S]*?showMarketplaceBreadcrumb &&[\s\S]*?!pluginDetailOpen/,
  46. );
  47. expect(source).toContain("showMarketplaceBreadcrumb\n ? [");
  48. expect(source).toContain("{ label: pluginsBreadcrumbLabel, onSelect: closeDetail }");
  49. expect(source).toContain(
  50. "onSectionSelect={showMarketplaceBreadcrumb ? onOpenPluginStore : closeDetail}",
  51. );
  52. });
  53. it("keeps the plugins level for marketplace MCP create and edit views", () => {
  54. const pluginsSource = readSettingsSection("PluginsSection");
  55. const mcpSource = readSettingsSection("McpSettingsSection");
  56. expect(pluginsSource).toMatch(/!pluginDetailOpen &&[\s\S]*?!mcpEditorOpen/);
  57. expect(mcpSource).toContain("showMarketplaceBreadcrumb");
  58. expect(mcpSource).toContain("{ label: pluginsBreadcrumbLabel, onSelect: closeFormView }");
  59. });
  60. it("keeps the plugins level for marketplace skill details", () => {
  61. const pluginsSource = readSettingsSection("PluginsSection");
  62. const skillsSource = readSettingsSection("SkillsSection");
  63. expect(pluginsSource).toContain("onDetailOpenChange={setSkillDetailOpen}");
  64. expect(pluginsSource).toContain('reportDetailBreadcrumb={mode === "plugin"}');
  65. expect(skillsSource).toContain("showMarketplaceBreadcrumb");
  66. expect(skillsSource).toContain("reportDetailBreadcrumb && detailSkill");
  67. expect(skillsSource).toContain("{ label: detailSkill.name }");
  68. });
  69. it.each([
  70. // Memory 分区在 workspace 作用域重构(08d53bd114)后不再承载页面级导航。
  71. "MemorySettingsSection",
  72. "BrowserSettingsSection",
  73. "ModelProviderSection",
  74. "UsageStatsSection",
  75. ])("does not promote dialog or flat state from %s", (section) => {
  76. expect(readSettingsSection(section)).not.toContain("SettingsBreadcrumbReporter");
  77. });
  78. });