remoteConnectionFieldsPlaceholder.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it, vi } from "vitest";
  4. import { PlatformProvider } from "@/hooks/usePlatform.js";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import { RemoteConnectionFields } from "@/RemoteConnectionFields.js";
  7. import type { IPlatformService } from "@zcode/shared";
  8. const platform: IPlatformService = {
  9. activateOrSetWorkspace: vi.fn(),
  10. cancelRemoteConnection: vi.fn(),
  11. connectRemote: vi.fn(),
  12. detectShell: vi.fn(),
  13. getDataBaseDir: vi.fn(),
  14. getDefaultShell: vi.fn(),
  15. getShells: vi.fn(),
  16. isDockerAvailable: vi.fn(),
  17. isWindowsDesktop: vi.fn(),
  18. listDockerContainers: vi.fn(),
  19. listSSHConfigAliases: vi.fn(),
  20. listWSLDistros: vi.fn(),
  21. log: vi.fn(),
  22. notifyRendererReady: vi.fn(),
  23. onOAuthCallback: vi.fn(),
  24. onRemoteConnectionLog: vi.fn(),
  25. openExternal: vi.fn(),
  26. registerOAuthState: vi.fn(),
  27. selectDirectory: vi.fn(),
  28. selectFile: vi.fn(),
  29. };
  30. function renderRemoteConnectionFields(kind: "ssh" | "docker") {
  31. return renderToStaticMarkup(
  32. createElement(
  33. PlatformProvider,
  34. { platform },
  35. createElement(
  36. ZCodeIntlProvider,
  37. { initialLocale: "zh-CN" },
  38. createElement(RemoteConnectionFields, {
  39. kind,
  40. host: "",
  41. port: "22",
  42. username: "",
  43. sshAuthMethod: "password",
  44. assetInstallMode: "local-download-upload",
  45. password: "",
  46. privateKeyPath: "",
  47. privateKeyPassphrase: "",
  48. wslDistro: "",
  49. wslDistros: [],
  50. dockerContainer: "",
  51. manualDockerContainer: "",
  52. serverUrl: "",
  53. serverName: "",
  54. serverToken: "",
  55. serverWorkspacePath: "",
  56. dockerContainers: [],
  57. dockerAvailable: null,
  58. sshConfigAliases: [],
  59. sshConfigAliasesLoading: false,
  60. sshConfigAliasesError: "",
  61. selectedSshConfigAlias: null,
  62. runtimeOptionsLoading: false,
  63. applySshConfigAlias: vi.fn(),
  64. clearSelectedSshConfigAlias: vi.fn(),
  65. setHost: vi.fn(),
  66. setPort: vi.fn(),
  67. setUsername: vi.fn(),
  68. setSshAuthMethod: vi.fn(),
  69. setAssetInstallMode: vi.fn(),
  70. setPassword: vi.fn(),
  71. setPrivateKeyPath: vi.fn(),
  72. setPrivateKeyPassphrase: vi.fn(),
  73. setWslDistro: vi.fn(),
  74. setDockerContainer: vi.fn(),
  75. setManualDockerContainer: vi.fn(),
  76. setServerUrl: vi.fn(),
  77. setServerName: vi.fn(),
  78. setServerToken: vi.fn(),
  79. setServerWorkspacePath: vi.fn(),
  80. }),
  81. ),
  82. ),
  83. );
  84. }
  85. describe("RemoteConnectionFields placeholder", () => {
  86. it("SSH 必填字段用输入提示承载示例,避免看起来像默认值", () => {
  87. const html = renderRemoteConnectionFields("ssh");
  88. expect(html).toContain('placeholder="输入主机地址或 IP,例如 192.168.1.100"');
  89. expect(html).toContain('placeholder="输入用户名,例如 root"');
  90. });
  91. it("Docker 容器选择器无可用容器时展示空态提示,并提供独立手动输入框", () => {
  92. const html = renderRemoteConnectionFields("docker");
  93. expect(html).toContain("未检测到运行中容器");
  94. expect(html).toContain('placeholder="输入容器名或 ID,例如 my-container"');
  95. expect(html).toContain(
  96. "如果运行中的容器列表不完整,可以手动输入容器名或 ID 连接。",
  97. );
  98. });
  99. });