pluginSourceLabel.test.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodePluginMarketplaceSummary } from "@zcode/shared";
  3. import {
  4. resolveMarketplaceDisplayName,
  5. resolvePluginSourceLabel,
  6. } from "../src/settings/pluginSourceLabel.js";
  7. const CLAUDE_CODE_PLUGINS = "Claude Code Plugins";
  8. function makeMarketplace(
  9. overrides: Partial<ZCodePluginMarketplaceSummary> = {},
  10. ): ZCodePluginMarketplaceSummary {
  11. return {
  12. id: "acme",
  13. name: "Acme Marketplace",
  14. source: { source: "github", repo: "acme/plugins" },
  15. pluginCount: 3,
  16. ...overrides,
  17. };
  18. }
  19. describe("resolveMarketplaceDisplayName", () => {
  20. it("maps the official marketplace id to the Claude Code Plugins label", () => {
  21. expect(
  22. resolveMarketplaceDisplayName("claude-plugins-official", [], CLAUDE_CODE_PLUGINS),
  23. ).toBe(CLAUDE_CODE_PLUGINS);
  24. });
  25. it("uses the overview name for known marketplaces", () => {
  26. expect(
  27. resolveMarketplaceDisplayName("acme", [makeMarketplace()], CLAUDE_CODE_PLUGINS),
  28. ).toBe("Acme Marketplace");
  29. });
  30. it("falls back to the raw id for unknown marketplaces", () => {
  31. expect(resolveMarketplaceDisplayName("mystery", [], CLAUDE_CODE_PLUGINS)).toBe("mystery");
  32. });
  33. });
  34. describe("resolvePluginSourceLabel", () => {
  35. const common = {
  36. marketplaces: [makeMarketplace()],
  37. builtinLabel: "Built-in",
  38. claudeCodePluginsLabel: CLAUDE_CODE_PLUGINS,
  39. formatFromMarketplace: (name: string) => `From ${name}`,
  40. };
  41. it("labels official plugins as built-in", () => {
  42. expect(
  43. resolvePluginSourceLabel({
  44. ...common,
  45. source: "official",
  46. marketplace: "zcode-plugins-official",
  47. }),
  48. ).toBe("Built-in");
  49. });
  50. it("labels inline plugins as built-in", () => {
  51. expect(
  52. resolvePluginSourceLabel({ ...common, source: "inline", marketplace: "inline" }),
  53. ).toBe("Built-in");
  54. });
  55. it("labels cache plugins as installed from their marketplace", () => {
  56. expect(
  57. resolvePluginSourceLabel({ ...common, source: "cache", marketplace: "acme" }),
  58. ).toBe("From Acme Marketplace");
  59. });
  60. it("uses the Claude Code Plugins label for official-marketplace installs", () => {
  61. expect(
  62. resolvePluginSourceLabel({
  63. ...common,
  64. source: "cache",
  65. marketplace: "claude-plugins-official",
  66. }),
  67. ).toBe(`From ${CLAUDE_CODE_PLUGINS}`);
  68. });
  69. });