pluginStoreTryPrompt.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { describe, expect, it } from "vitest";
  2. import type { StorePluginItem } from "@/settings/pluginStoreListing.js";
  3. import {
  4. buildPluginStoreTryMention,
  5. buildPluginStoreTryPrompt,
  6. } from "@/settings/pluginStoreTryPrompt.js";
  7. function pluginItem(overrides: Partial<StorePluginItem> = {}): StorePluginItem {
  8. return {
  9. id: "demo-plugin@demo-market",
  10. name: "demo-plugin",
  11. marketplace: "demo-market",
  12. installed: true,
  13. restorable: false,
  14. orphaned: false,
  15. listing: {
  16. displayName: "Demo [Plugin]",
  17. displayNameI18n: { "zh-CN": "演示插件" },
  18. icon: "https://cdn.example.com/demo-plugin.png",
  19. },
  20. ...overrides,
  21. };
  22. }
  23. describe("Plugin Store try prompt", () => {
  24. it("prefills only the shared canonical Plugin reference for Try now", () => {
  25. expect(
  26. buildPluginStoreTryPrompt({
  27. item: pluginItem(),
  28. locale: "en-US",
  29. prompt: "",
  30. }),
  31. ).toBe("[@Demo \\[Plugin\\]](plugin://demo-plugin@demo-market)");
  32. });
  33. it("prefills the shared canonical Plugin reference before the example prompt", () => {
  34. expect(
  35. buildPluginStoreTryPrompt({
  36. item: pluginItem(),
  37. locale: "en-US",
  38. prompt: " Summarize this workspace. ",
  39. }),
  40. ).toBe(
  41. "[@Demo \\[Plugin\\]](plugin://demo-plugin@demo-market) Summarize this workspace.",
  42. );
  43. });
  44. it("uses the localized display label without changing the stable destination", () => {
  45. expect(
  46. buildPluginStoreTryPrompt({
  47. item: pluginItem(),
  48. locale: "zh-CN",
  49. prompt: "帮我检查配置",
  50. }),
  51. ).toBe(
  52. "[@演示插件](plugin://demo-plugin@demo-market) 帮我检查配置",
  53. );
  54. });
  55. it("builds the same structured Plugin mention used by the @ picker", () => {
  56. expect(
  57. buildPluginStoreTryMention({
  58. item: pluginItem(),
  59. locale: "zh-CN",
  60. }),
  61. ).toEqual({
  62. id: "plugin:demo-plugin@demo-market",
  63. category: "plugins",
  64. label: "演示插件",
  65. value: "demo-plugin@demo-market",
  66. markdown: "[@演示插件](plugin://demo-plugin@demo-market)",
  67. data: {
  68. pluginId: "demo-plugin@demo-market",
  69. icon: "https://cdn.example.com/demo-plugin.png",
  70. },
  71. });
  72. });
  73. });