pluginDetailHeaderLayout.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. import { resolveExamplePromptDocumentIcon } from "@/settings/PluginStoreDetailView.js";
  4. describe("Plugin detail header layout", () => {
  5. it("maps document examples to the bundled product icons", () => {
  6. expect(resolveExamplePromptDocumentIcon("把我的笔记整理成一份排版好的 Word 文档")).toBe(
  7. "documents",
  8. );
  9. expect(resolveExamplePromptDocumentIcon("把这份 PDF 里的表格提取成电子表格")).toBe(
  10. "pdf",
  11. );
  12. expect(resolveExamplePromptDocumentIcon("用这份 CSV 做一份带图表的 Excel 工作簿")).toBe(
  13. "spreadsheets",
  14. );
  15. expect(resolveExamplePromptDocumentIcon("Summarize this attachment")).toBe("documents");
  16. });
  17. it("keeps the name and primary actions in one row with description below", () => {
  18. const source = readFileSync(
  19. "packages/ui/src/settings/PluginStoreDetailView.tsx",
  20. "utf8",
  21. );
  22. expect(source).toContain('data-testid="plugin-store-title-actions"');
  23. expect(source).toContain('data-testid="plugin-store-description"');
  24. expect(source).toMatch(
  25. /data-testid="plugin-store-title-actions"[\s\S]*?<h1[\s\S]*?PluginStoreItemMenu[\s\S]*?plugin-store-try-now/,
  26. );
  27. expect(source).not.toContain("PluginStoreEnabledSwitch");
  28. expect(source.indexOf('data-testid="plugin-store-description"')).toBeGreaterThan(
  29. source.indexOf('data-testid="plugin-store-title-actions"'),
  30. );
  31. expect(source).toMatch(
  32. /PluginStoreItemMenu[\s\S]*?triggerVariant="outline"[\s\S]*?triggerSize="icon-lg"/,
  33. );
  34. const tryNowButton = source.match(
  35. /<Button[\s\S]*?data-testid="plugin-store-try-now"[\s\S]*?<\/Button>/,
  36. )?.[0];
  37. expect(tryNowButton).toContain('size="lg"');
  38. expect(tryNowButton).not.toContain('className="rounded-full"');
  39. expect(source).toMatch(/PluginStoreInstallButton[\s\S]*?size="lg"/);
  40. });
  41. });