webRemoteControlWorkspaceSync.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @vitest-environment jsdom
  2. import { cleanup, renderHook } from "@testing-library/react";
  3. import { afterEach, expect, it, vi } from "vitest";
  4. import { useWebRemoteControlWorkspaceSync } from "@/root/rootPlatformWorkspaceSync.js";
  5. import type { WindowTabState } from "@/store/tabStore.js";
  6. afterEach(cleanup);
  7. it("本地与远端并存时发送完整快照,远控未运行也不丢失本地目标,关闭tab发送删除", () => {
  8. const syncWebRemoteControlWorkspaces = vi.fn();
  9. const platform = { syncWebRemoteControlWorkspaces };
  10. const tabs: WindowTabState[] = [
  11. { id: "local", kind: "workspace", label: "Local", workspacePath: "/local" },
  12. {
  13. id: "remote",
  14. kind: "workspace",
  15. label: "Remote",
  16. workspacePath: "/remote",
  17. workspaceIdentity: "ssh://host/remote",
  18. remoteSessionId: "remote-1",
  19. },
  20. ];
  21. const { rerender } = renderHook(
  22. ({ ready, currentTabs }) =>
  23. useWebRemoteControlWorkspaceSync({
  24. platform,
  25. tabs: currentTabs,
  26. isDesktop: true,
  27. featureEnabled: true,
  28. hasCompletedFullTabRestore: ready,
  29. }),
  30. { initialProps: { ready: false, currentTabs: tabs } },
  31. );
  32. expect(syncWebRemoteControlWorkspaces).not.toHaveBeenCalled();
  33. rerender({ ready: true, currentTabs: tabs });
  34. expect(syncWebRemoteControlWorkspaces).toHaveBeenLastCalledWith([
  35. { workspacePath: "/local", label: "Local", kind: "local" },
  36. {
  37. workspacePath: "/remote",
  38. label: "Remote",
  39. kind: "remote",
  40. connectionState: "connected",
  41. workspaceIdentity: "ssh://host/remote",
  42. remoteSessionId: "remote-1",
  43. },
  44. ]);
  45. expect(syncWebRemoteControlWorkspaces).toHaveBeenCalledOnce();
  46. rerender({ ready: true, currentTabs: [] });
  47. expect(syncWebRemoteControlWorkspaces).toHaveBeenLastCalledWith([]);
  48. });