settingsFrameContentLayout.test.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { readSourceText } from "./readSourceText.js";
  2. import { describe, expect, it } from "vitest";
  3. function readSource(relativePath: string): string {
  4. return readSourceText(new URL(relativePath, import.meta.url), "utf8");
  5. }
  6. const settingsPagePartsSource = readSource("../src/settings/SettingsPageParts.tsx");
  7. const settingsPageSource = readSource("../src/SettingsPage.tsx");
  8. const automationsSectionSource = readSource("../src/settings/AutomationsSection.tsx");
  9. const automationEditViewSource = readSource("../src/settings/AutomationEditView.tsx");
  10. const offPeakEditViewSource = readSource("../src/settings/OffPeakEditView.tsx");
  11. const workspaceShellSource = readSource("../src/app-shell/WorkspaceShellLayout.tsx");
  12. const automationsBreadcrumbFrameSource = readSource(
  13. "../src/settings/AutomationsMainBreadcrumbFrame.tsx",
  14. );
  15. describe("settings frame content layout", () => {
  16. it("shares one frame-aligned content column across Settings and Automations views", () => {
  17. expect(settingsPagePartsSource).toContain(
  18. '"mx-auto w-full max-w-4xl px-4 pb-8 pt-0 lg:px-8 lg:pb-10"',
  19. );
  20. for (const source of [
  21. settingsPageSource,
  22. automationsSectionSource,
  23. automationEditViewSource,
  24. offPeakEditViewSource,
  25. ]) {
  26. expect(source).toContain("SETTINGS_FRAME_CONTENT_CLASSNAME");
  27. }
  28. for (const source of [
  29. automationsSectionSource,
  30. automationEditViewSource,
  31. offPeakEditViewSource,
  32. ]) {
  33. expect(source).not.toContain("max-w-[866px]");
  34. }
  35. });
  36. it("keeps Model Provider settings on the shared 4xl content column", () => {
  37. expect(settingsPageSource).not.toContain('activeSection === "modelProvider" && "max-w-6xl"');
  38. });
  39. it("keeps the remote Automations shell frame with drag and scroll responsibilities", () => {
  40. expect(workspaceShellSource).toContain(
  41. 'className="mx-auto flex w-full max-w-5xl flex-col px-4 py-4 md:px-6 md:py-6"',
  42. );
  43. expect(automationsBreadcrumbFrameSource).toContain(
  44. 'data-testid="automations-main-drag-region"',
  45. );
  46. expect(workspaceShellSource).toContain(
  47. "min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]",
  48. );
  49. });
  50. it("limits the independent plugin marketplace to the 4xl content width", () => {
  51. expect(
  52. workspaceShellSource.match(
  53. /className="mx-auto flex w-full max-w-4xl flex-col px-4 py-4 md:px-6 md:py-6"[\s\S]{0,120}<PluginStorePage/g,
  54. ),
  55. ).toHaveLength(2);
  56. });
  57. it("returns to chat before creating a task from plugin detail prompts", () => {
  58. const pluginStoreUsages = workspaceShellSource.match(
  59. /<PluginStorePage[\s\S]{0,500}?onCreateTask=\{handleCreateTaskInChat\}/g,
  60. );
  61. // Desktop 与窄屏 Shell 都必须使用包含 showChatMainView 的包装回调。
  62. expect(pluginStoreUsages).toHaveLength(2);
  63. expect(workspaceShellSource).not.toMatch(
  64. /<PluginStorePage[\s\S]{0,500}?onCreateTask=\{onCreateTask\}/,
  65. );
  66. });
  67. it("renders the read-only Settings breadcrumb inside the caption drag region", () => {
  68. expect(settingsPageSource).toMatch(
  69. /min-w-0 flex-1 \[app-region:drag\][\s\S]*?<SettingsHeaderBreadcrumb/,
  70. );
  71. expect(settingsPageSource).toContain(
  72. "settingsBreadcrumbItems[0]?.label === settingsBreadcrumbSectionLabel",
  73. );
  74. expect(settingsPageSource).toContain("hasVisibleSettingsBreadcrumb");
  75. expect(settingsPageSource).toContain(
  76. 'const showActiveSectionTitle =\n !hasVisibleSettingsBreadcrumb ||\n (activeSection === "plugin" && pluginNavigationOrigin === "plugin-store")',
  77. );
  78. expect(settingsPageSource).toMatch(/showActiveSectionTitle[\s\S]*?<h2/);
  79. });
  80. it("remounts capability routes when Settings navigation is selected", () => {
  81. expect(settingsPageSource).toContain("settingsSectionNavigationVersion");
  82. expect(settingsPageSource).toContain("setSettingsSectionNavigationVersion");
  83. expect(settingsPageSource).toContain("key={`plugin:${settingsSectionNavigationVersion}`}");
  84. expect(settingsPageSource).toContain("key={`mcp:${settingsSectionNavigationVersion}`}");
  85. expect(settingsPageSource).toContain("key={`skill:${settingsSectionNavigationVersion}`}");
  86. });
  87. it("only exposes the Project Memory viewer from the desktop host", () => {
  88. expect(settingsPageSource).toContain("projectMemoryViewerAvailable={Boolean(isDesktop)}");
  89. expect(settingsPageSource).not.toContain("projectMemoryViewerAvailable={!isWebRemoteControl}");
  90. });
  91. it("pins the Project Memory viewer subtree to the local base host", () => {
  92. expect(settingsPageSource).toMatch(
  93. /<ServiceProvider services=\{localHostServices\}>[\s\S]*?<MemorySettingsSection[\s\S]*?<\/ServiceProvider>/,
  94. );
  95. });
  96. it("lets Project Memory share the Settings main scroll chain like Plugins", () => {
  97. expect(settingsPageSource).toContain("grid-rows-[minmax(0,1fr)]");
  98. expect(settingsPageSource).toContain(
  99. 'className="min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]"',
  100. );
  101. expect(settingsPageSource).not.toContain("usesContainedMemoryViewerLayout");
  102. });
  103. });