remoteConnectionDialogContentLayout.test.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { renderToStaticMarkup } from "react-dom/server";
  4. import { describe, expect, it, vi } from "vitest";
  5. const capturedRemoteSyncDialogProps = vi.hoisted(() => [] as Array<Record<string, unknown>>);
  6. vi.mock("@/i18n/IntlProvider.js", () => ({
  7. useZCodeIntl: () => ({
  8. intl: {
  9. formatMessage: ({ id }: { id: string }) => id,
  10. },
  11. }),
  12. }));
  13. vi.mock("@/DirectoryBrowser.js", () => ({
  14. DirectoryBrowser: () => createElement("div", { "data-testid": "directory-browser" }),
  15. }));
  16. vi.mock("@/RemoteConnectionFields.js", () => ({
  17. RemoteConnectionFields: () => createElement("div", { "data-testid": "remote-connection-fields" }),
  18. }));
  19. vi.mock("@/settings/RemoteSyncActions.js", () => ({
  20. RemoteSyncDialogs: (props: Record<string, unknown>) => {
  21. capturedRemoteSyncDialogProps.push(props);
  22. return createElement("div", { "data-testid": "remote-sync-dialogs" });
  23. },
  24. RemoteSyncDropdownButton: () =>
  25. createElement("button", { type: "button" }, "settings.remoteSync.open"),
  26. shouldShowRemoteSyncActions: ({
  27. remoteSessionId,
  28. remoteTarget,
  29. }: {
  30. remoteSessionId?: string | null;
  31. remoteTarget?: { kind: string } | null;
  32. }) => Boolean(remoteSessionId?.trim() && ["ssh", "wsl"].includes(remoteTarget?.kind ?? "")),
  33. }));
  34. import {
  35. getRecentRemoteWorkspaceHistory,
  36. RemoteConnectionDirectoryStep,
  37. } from "@/RemoteConnectionDialogContent.js";
  38. import { buildAvailableKinds } from "@/hooks/useRemoteConnectionForm.js";
  39. describe("RemoteConnectionDialogContent layout", () => {
  40. it("shows the most recently opened directories first", () => {
  41. expect(
  42. getRecentRemoteWorkspaceHistory([
  43. {
  44. workspacePath: "/old",
  45. profileId: "p",
  46. sourceServerId: "s",
  47. lastOpenedAt: 1,
  48. },
  49. {
  50. workspacePath: "/new",
  51. profileId: "p",
  52. sourceServerId: "s",
  53. lastOpenedAt: 3,
  54. },
  55. {
  56. workspacePath: "/middle",
  57. profileId: "p",
  58. sourceServerId: "s",
  59. lastOpenedAt: 2,
  60. },
  61. ]).map((entry) => entry.workspacePath),
  62. ).toEqual(["/new", "/middle", "/old"]);
  63. });
  64. it("filters hidden directories out of the recent list", () => {
  65. expect(
  66. getRecentRemoteWorkspaceHistory([
  67. {
  68. workspacePath: "/home/dev/.zcode",
  69. profileId: "p",
  70. sourceServerId: "s",
  71. lastOpenedAt: 9,
  72. },
  73. {
  74. workspacePath: "/home/dev/work",
  75. profileId: "p",
  76. sourceServerId: "s",
  77. lastOpenedAt: 1,
  78. },
  79. ]).map((entry) => entry.workspacePath),
  80. ).toEqual(["/home/dev/work"]);
  81. });
  82. it("filters the Source conversation backing path out of recent directories", () => {
  83. expect(
  84. getRecentRemoteWorkspaceHistory(
  85. [
  86. {
  87. workspacePath: "/remote/.zcode/workspace/default",
  88. sourceServerId: "source-1",
  89. profileId: "p",
  90. lastOpenedAt: 3,
  91. },
  92. {
  93. workspacePath: "/remote/project",
  94. sourceServerId: "source-1",
  95. profileId: "p",
  96. lastOpenedAt: 2,
  97. },
  98. ],
  99. {
  100. "source-1": {
  101. workspacePath: "/remote/.zcode/workspace/default",
  102. lastResolvedAt: 4,
  103. },
  104. },
  105. ).map((entry) => entry.workspacePath),
  106. ).toEqual(["/remote/project"]);
  107. });
  108. it("renders full quick-open paths", () => {
  109. const html = renderToStaticMarkup(
  110. createElement(RemoteConnectionDirectoryStep, {
  111. services: {} as never,
  112. selecting: false,
  113. quickOpenPaths: ["/home/dev/work/api"],
  114. deviceName: "dev",
  115. onRenameDevice: vi.fn(),
  116. onSelect: vi.fn(),
  117. onBack: vi.fn(),
  118. onCancel: vi.fn(),
  119. }),
  120. );
  121. expect(html).toContain("/home/dev/work/api");
  122. expect(html).toContain("remote.recentDirectories");
  123. });
  124. it("shows Server between SSH and Windows-only kinds in local development", () => {
  125. expect(
  126. buildAvailableKinds({
  127. isWindowsDesktop: true,
  128. isLocalDevelopmentRuntime: true,
  129. }),
  130. ).toEqual(["ssh", "server", "wsl", "docker"]);
  131. });
  132. it("hides Server from production-mode packaged runtimes", () => {
  133. expect(
  134. buildAvailableKinds({
  135. isWindowsDesktop: true,
  136. isLocalDevelopmentRuntime: false,
  137. }),
  138. ).toEqual(["ssh", "wsl", "docker"]);
  139. expect(
  140. buildAvailableKinds({
  141. isWindowsDesktop: false,
  142. isLocalDevelopmentRuntime: false,
  143. }),
  144. ).toEqual(["ssh", "docker"]);
  145. });
  146. it("shows progress feedback while finalizing a selected remote directory", () => {
  147. const html = renderToStaticMarkup(
  148. createElement(RemoteConnectionDirectoryStep, {
  149. services: {} as never,
  150. selecting: true,
  151. onSelect: vi.fn(),
  152. onBack: vi.fn(),
  153. onCancel: vi.fn(),
  154. }),
  155. );
  156. expect(html).toContain("common.loading");
  157. expect(html).toContain("animate-spin");
  158. });
  159. it("passes the local workspace path to MCP sync from the directory step", () => {
  160. capturedRemoteSyncDialogProps.length = 0;
  161. renderToStaticMarkup(
  162. createElement(RemoteConnectionDirectoryStep, {
  163. services: {} as never,
  164. remoteTarget: {
  165. kind: "ssh",
  166. host: "localhost",
  167. port: 2223,
  168. username: "root",
  169. },
  170. localWorkspacePath: "/Users/alice/project",
  171. localMcpSyncService: {} as never,
  172. remoteMcpSyncService: {} as never,
  173. onSelect: vi.fn(),
  174. onBack: vi.fn(),
  175. onCancel: vi.fn(),
  176. }),
  177. );
  178. expect(capturedRemoteSyncDialogProps[0]?.mcpLocalWorkspacePath).toBe("/Users/alice/project");
  179. });
  180. });