settingsListHeaderActionSize.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { readFile } from "node:fs/promises";
  2. import { describe, expect, it } from "vitest";
  3. // Commands/Hooks/Subagents/Memory 的头部纯图标按钮已收进共享组件
  4. // SettingsResourceHeaderActions(icon-md);仍自带图标的页面沿用 icon-lg。
  5. const selfRenderedIconFiles = {
  6. "McpSettingsSection.tsx": 1,
  7. "PluginStorePage.tsx": 2,
  8. "PluginStoreListView.tsx": 1,
  9. "SkillsSection.tsx": 1,
  10. } as const;
  11. const delegatingSections = [
  12. "CommandsSection.tsx",
  13. "HooksSection.tsx",
  14. "MemorySettingsViewer.tsx",
  15. "SubagentsSection.tsx",
  16. ] as const;
  17. describe("settings list header actions", () => {
  18. it("纯图标按钮统一使用 outline,共享头部动作用 icon-md", async () => {
  19. for (const [fileName, expectedCount] of Object.entries(
  20. selfRenderedIconFiles,
  21. )) {
  22. const source = await readFile(
  23. new URL(`../src/settings/${fileName}`, import.meta.url),
  24. "utf8",
  25. );
  26. expect(
  27. source.match(/variant="outline"\s+size="icon-lg"/g),
  28. fileName,
  29. ).toHaveLength(expectedCount);
  30. }
  31. const shared = await readFile(
  32. new URL("../src/settings/SettingsResourceHeaderActions.tsx", import.meta.url),
  33. "utf8",
  34. );
  35. expect(shared.match(/variant="outline"\s+size="icon-md"/g)).toHaveLength(2);
  36. });
  37. it.each(delegatingSections)(
  38. "%s 头部图标按钮由共享组件渲染",
  39. async (fileName) => {
  40. const source = await readFile(
  41. new URL(`../src/settings/${fileName}`, import.meta.url),
  42. "utf8",
  43. );
  44. expect(source).toContain("<SettingsResourceHeaderActions");
  45. expect(source).not.toMatch(/size="icon-lg"/);
  46. },
  47. );
  48. it("插件列表右上角操作按钮使用统一的 8px 间距", async () => {
  49. const source = await readFile(
  50. new URL("../src/settings/PluginStorePage.tsx", import.meta.url),
  51. "utf8",
  52. );
  53. expect(source).toContain('className="flex shrink-0 items-center gap-2"');
  54. });
  55. });