pluginStoreNavigation.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // @vitest-environment jsdom
  2. import { beforeEach, describe, expect, it, vi } from "vitest";
  3. import {
  4. addPluginStoreOpenListener,
  5. consumePluginStoreOpenTarget,
  6. requestPluginStoreOpen,
  7. } from "@/lib/pluginStoreNavigation.js";
  8. describe("plugin store navigation target", () => {
  9. beforeEach(() => {
  10. consumePluginStoreOpenTarget();
  11. });
  12. it("dispatches and preserves a one-shot target Plugin ID for the store page", () => {
  13. const listener = vi.fn();
  14. const dispose = addPluginStoreOpenListener(listener);
  15. requestPluginStoreOpen("document-skills@zcode-plugins-official");
  16. expect(listener).toHaveBeenCalledWith({
  17. pluginId: "document-skills@zcode-plugins-official",
  18. });
  19. expect(consumePluginStoreOpenTarget()).toEqual({
  20. pluginId: "document-skills@zcode-plugins-official",
  21. });
  22. expect(consumePluginStoreOpenTarget()).toBeNull();
  23. dispose();
  24. });
  25. it("normalizes an empty target to an ordinary store navigation", () => {
  26. requestPluginStoreOpen(" ");
  27. expect(consumePluginStoreOpenTarget()).toEqual({});
  28. });
  29. it("normalizes legacy Workspace return keys to the global User view", () => {
  30. const listener = vi.fn();
  31. const dispose = addPluginStoreOpenListener(listener);
  32. const first = "remote:ssh:host-a:22:user:/workspace";
  33. const second = "remote:ssh:host-b:22:user:/workspace";
  34. requestPluginStoreOpen(first);
  35. requestPluginStoreOpen(second);
  36. expect(listener.mock.calls.map(([target]) => target)).toEqual([
  37. { returnScopeKey: "user" },
  38. { returnScopeKey: "user" },
  39. ]);
  40. expect(consumePluginStoreOpenTarget()).toEqual({ returnScopeKey: "user" });
  41. dispose();
  42. });
  43. });
  44. it("carries a one-shot add-marketplace intent without changing legacy navigation", () => {
  45. requestPluginStoreOpen({ intent: "add-marketplace" });
  46. expect(consumePluginStoreOpenTarget()).toEqual({ intent: "add-marketplace" });
  47. expect(consumePluginStoreOpenTarget()).toBeNull();
  48. });