pluginCreatorMentionIcon.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { renderToStaticMarkup } from "react-dom/server";
  4. import { describe, expect, it } from "vitest";
  5. import { PluginMentionOptionContent } from "@/mentions/components/PluginMentionOptionContent.js";
  6. import { decoratePromptMention } from "@/mentions/nodes/promptMentionDecoration.js";
  7. import { buildSessionPluginIconMap } from "@/v4/pluginReferenceIconProjection.js";
  8. import { ConversationUserInputContent } from "@/v4/ConversationUserInputContent.js";
  9. import { PluginReferenceIconProvider } from "@/v4/pluginReferenceIconContext.js";
  10. const pluginId = "plugin-creator@zcode-plugins-official";
  11. const entry = {
  12. pluginId,
  13. name: "plugin-creator",
  14. marketplace: "zcode-plugins-official",
  15. enabled: true,
  16. conflictingPluginIds: [],
  17. skillQualifiedNames: [],
  18. mcpServerNames: [],
  19. subagentNames: [],
  20. };
  21. describe("official creator mention artwork", () => {
  22. it("uses bundled artwork in the picker without a remote listing icon", () => {
  23. const html = renderToStaticMarkup(
  24. createElement(PluginMentionOptionContent, {
  25. item: {
  26. id: `plugin:${pluginId}`,
  27. category: "plugins",
  28. label: "插件创建器",
  29. value: pluginId,
  30. data: { pluginId },
  31. },
  32. }),
  33. );
  34. expect(html).toContain("plugin-creator.png");
  35. });
  36. it("decorates the composer chip by stable identity without changing its text", () => {
  37. const dom = document.createElement("span");
  38. dom.textContent = "插件创建器";
  39. decoratePromptMention(dom, "plugins", pluginId);
  40. expect(dom.style.getPropertyValue("--mention-image")).toContain("plugin-creator.png");
  41. expect(dom.textContent).toBe("插件创建器");
  42. decoratePromptMention(dom, "plugins", "plugin-creator@personal", { icon: "/untrusted.png" });
  43. expect(dom.style.getPropertyValue("--mention-image")).toBe("");
  44. expect(dom.style.getPropertyValue("--mention-mask")).not.toBe("");
  45. });
  46. it("renders sent chips only after the matching entry is in Session authority", () => {
  47. const text = `[@插件创建器](plugin://${pluginId})`;
  48. const render = (authority: "session" | "workspace") =>
  49. renderToStaticMarkup(
  50. createElement(
  51. PluginReferenceIconProvider,
  52. {
  53. value: {
  54. sessionId: "session",
  55. iconByPluginId: buildSessionPluginIconMap(authority, [entry]),
  56. },
  57. },
  58. createElement(ConversationUserInputContent, { text }),
  59. ),
  60. );
  61. expect(render("session")).toContain("plugin-creator.png");
  62. expect(render("workspace")).not.toContain("plugin-creator.png");
  63. expect(buildSessionPluginIconMap("session", []).has(pluginId)).toBe(false);
  64. });
  65. });