projectConnectionDiagnostics.test.ts 1.2 KB

1234567891011121314151617181920212223242526
  1. // @vitest-environment jsdom
  2. import { renderHook } from "@testing-library/react";
  3. import { expect, it } from "vitest";
  4. import { useProjectConnectionDiagnostics } from "@/project-sidebar/useProjectConnectionDiagnostics.js";
  5. import type { ProjectSidebarProps, RemoteProjectDirectory } from "@/project-sidebar/contract.js";
  6. it("keeps live errors scoped to the current Host", () => {
  7. const host = {
  8. id: "remote:server:one",
  9. membershipId: "first",
  10. connectionStatus: "offline",
  11. lastConnectionError: "SSH refused",
  12. } as RemoteProjectDirectory["hosts"][number];
  13. const props = {
  14. remoteWorkspaceErrorByWorkspaceKey: { "remote:server:two:/repo": "other host" },
  15. } as unknown as ProjectSidebarProps;
  16. const { result, rerender } = renderHook(
  17. (directory) => useProjectConnectionDiagnostics(directory, props),
  18. { initialProps: { hosts: [host], entries: [] } as RemoteProjectDirectory },
  19. );
  20. expect(result.current.get(host.id)?.error).toBe("SSH refused");
  21. rerender({ hosts: [{ ...host, connectionStatus: "online" }], entries: [] });
  22. expect(result.current.get(host.id)?.error).toBeUndefined();
  23. rerender({ hosts: [{ ...host, lastConnectionError: undefined }], entries: [] });
  24. expect(result.current.get(host.id)?.error).toBeUndefined();
  25. });