sessionPluginReferenceIconProvider.test.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @vitest-environment jsdom
  2. import { render, screen } from "@testing-library/react";
  3. import { beforeEach, describe, expect, it, vi } from "vitest";
  4. import { SessionPluginReferenceIconBoundary } from "@/v4/SessionPluginReferenceIconProvider.js";
  5. const usePluginReferenceCatalog = vi.fn(() => ({
  6. authority: "session" as const,
  7. entries: [],
  8. error: null,
  9. loading: false,
  10. }));
  11. vi.mock("@/hooks/usePluginReferenceCatalog.js", () => ({
  12. usePluginReferenceCatalog,
  13. }));
  14. describe("SessionPluginReferenceIconBoundary", () => {
  15. beforeEach(() => {
  16. vi.clearAllMocks();
  17. });
  18. it("does not mount the catalog hook until a matching Session contains Plugin references", () => {
  19. const { rerender } = render(
  20. <SessionPluginReferenceIconBoundary
  21. enabled={false}
  22. remoteSessionId="remote-a"
  23. sessionId="session-a"
  24. workspaceIdentity="ssh://host/workspace"
  25. workspacePath="/workspace"
  26. >
  27. <span>timeline</span>
  28. </SessionPluginReferenceIconBoundary>,
  29. );
  30. expect(screen.getByText("timeline")).toBeTruthy();
  31. expect(usePluginReferenceCatalog).not.toHaveBeenCalled();
  32. rerender(
  33. <SessionPluginReferenceIconBoundary
  34. enabled
  35. remoteSessionId="remote-a"
  36. sessionId="session-a"
  37. workspaceIdentity="ssh://host/workspace"
  38. workspacePath="/workspace"
  39. >
  40. <span>timeline</span>
  41. </SessionPluginReferenceIconBoundary>,
  42. );
  43. expect(usePluginReferenceCatalog).toHaveBeenCalledWith(
  44. "/workspace",
  45. "ssh://host/workspace",
  46. "session-a",
  47. true,
  48. {
  49. dedupeSessionRequest: true,
  50. preferredRemoteSessionId: "remote-a",
  51. suppressErrorLog: true,
  52. },
  53. );
  54. });
  55. });