pluginStoreAvatar.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { PluginStoreAvatar } from "../src/settings/PluginStoreAvatar.js";
  5. describe("PluginStoreAvatar", () => {
  6. it.each([
  7. ["documents", "documents.png"],
  8. ["pdf", "pdf.png"],
  9. ["presentations", "presentations.png"],
  10. ["spreadsheets", "spreadsheets.png"],
  11. ["image-search", "image-search.png"],
  12. ])("uses bundled artwork for the official %s plugin", (name, assetName) => {
  13. const staleIcon = "https://cdn.example.com/old-document-skills.png";
  14. const render = (id: string) =>
  15. renderToStaticMarkup(
  16. createElement(PluginStoreAvatar, {
  17. item: { id, name, listing: { icon: staleIcon } },
  18. }),
  19. );
  20. expect(render(`${name}@zcode-plugins-official`)).toContain(assetName);
  21. expect(render(`${name}@zcode-plugins-official`)).not.toContain(staleIcon);
  22. expect(render(`${name}@personal`)).toContain(staleIcon);
  23. });
  24. it("uses the bundled creator artwork only for the official plugin, including stale listings", () => {
  25. const icon = "https://cdn.example.com/old-skill-creator.png";
  26. const render = (id: string) =>
  27. renderToStaticMarkup(
  28. createElement(PluginStoreAvatar, {
  29. item: { id, name: "plugin-creator", listing: { icon } },
  30. }),
  31. );
  32. expect(render("plugin-creator@zcode-plugins-official")).toContain("plugin-creator.png");
  33. expect(render("plugin-creator@zcode-plugins-official")).not.toContain(icon);
  34. expect(render("plugin-creator@personal")).toContain(icon);
  35. });
  36. it("uses a neutral surface icon when listing icon is missing", () => {
  37. const html = renderToStaticMarkup(
  38. createElement(PluginStoreAvatar, {
  39. item: { name: "example-plugin" },
  40. className: "size-10",
  41. }),
  42. );
  43. expect(html).toContain("lucide-blocks");
  44. expect(html).not.toContain("lucide-puzzle");
  45. expect(html).toContain("rounded-xl");
  46. expect(html).toContain("bg-surface");
  47. expect(html).toContain("text-foreground-subtle");
  48. expect(html).not.toContain("rounded-full");
  49. expect(html).not.toContain("border-border");
  50. expect(html).not.toContain("bg-gradient-to-br");
  51. });
  52. it("keeps a trusted listing icon ahead of the fallback", () => {
  53. const html = renderToStaticMarkup(
  54. createElement(PluginStoreAvatar, {
  55. item: {
  56. name: "example-plugin",
  57. listing: { icon: "https://cdn.example.com/example.png" },
  58. },
  59. className: "size-10",
  60. }),
  61. );
  62. expect(html).toContain('src="https://cdn.example.com/example.png"');
  63. expect(html).toContain("bg-surface");
  64. expect(html).toContain("h-2/3");
  65. expect(html).not.toContain("dark:invert");
  66. expect(html).not.toContain("lucide-blocks");
  67. });
  68. });