pluginStoreInstalledStripTooltip.test.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { createElement, type ReactNode } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import type { PluginStoreActions } from "../src/settings/PluginStoreCard.js";
  5. import type { StorePluginItem } from "../src/settings/pluginStoreListing.js";
  6. vi.mock("@/ControlHintTooltip.js", () => ({
  7. ControlHintTooltip: ({ children, title }: { children: ReactNode; title: string }) =>
  8. createElement("span", { "data-tooltip-title": title }, children),
  9. }));
  10. vi.mock("@/i18n/IntlProvider.js", () => ({
  11. useZCodeIntl: () => ({
  12. locale: "en-US",
  13. intl: {
  14. formatMessage: ({ id }: { id: string }) => id,
  15. },
  16. }),
  17. }));
  18. const actions: PluginStoreActions = {
  19. onOpenDetail: () => {},
  20. onInstall: () => {},
  21. onUninstall: () => {},
  22. onSetEnabled: () => {},
  23. onUpdate: () => {},
  24. operationId: null,
  25. togglingPluginId: null,
  26. };
  27. describe("PluginStoreListView installed strip", () => {
  28. it("shows each installed plugin display name through the standard tooltip", async () => {
  29. const item: StorePluginItem = {
  30. id: "example-plugin@zcode-plugins-official",
  31. name: "example-plugin",
  32. marketplace: "zcode-plugins-official",
  33. installed: true,
  34. restorable: false,
  35. orphaned: false,
  36. listing: { displayName: "Example Plugin", category: "developer-tools" },
  37. info: {
  38. id: "example-plugin@zcode-plugins-official",
  39. name: "example-plugin",
  40. marketplace: "zcode-plugins-official",
  41. enabled: false,
  42. source: "official",
  43. skillRootCount: 0,
  44. commandRootCount: 0,
  45. mcpServerNames: [],
  46. rootPath: "/builtin/example-plugin",
  47. },
  48. };
  49. const { PluginStoreListView } = await import("../src/settings/PluginStoreListView.js");
  50. const html = renderToStaticMarkup(
  51. createElement(PluginStoreListView, {
  52. items: [item],
  53. marketplaces: [],
  54. actions,
  55. loading: false,
  56. query: "",
  57. onQueryChange: () => {},
  58. segment: "public",
  59. onSegmentChange: () => {},
  60. onOpenManage: () => {},
  61. }),
  62. );
  63. expect(html).toContain('data-tooltip-title="Example Plugin"');
  64. expect(html).toContain('aria-label="Example Plugin"');
  65. const installedItemStart = html.indexOf('data-testid="plugin-store-installed-item"');
  66. const installedItemEnd = html.indexOf("</button>", installedItemStart);
  67. expect(html.slice(installedItemStart, installedItemEnd)).not.toContain("opacity-50");
  68. expect(html).toContain("py-4 first:pt-0 last:pb-0");
  69. expect(html).toContain("h-px bg-surface");
  70. });
  71. });