remoteConnectionFieldsAuthMethodLayout.test.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(locale: "zh-CN" | "en-US") {
  31. return renderToStaticMarkup(
  32. createElement(
  33. PlatformProvider,
  34. { platform },
  35. createElement(
  36. ZCodeIntlProvider,
  37. { initialLocale: locale },
  38. createElement(RemoteConnectionFields, {
  39. kind: "ssh",
  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 authentication method layout", () => {
  86. it("keeps SSH auth method options wide enough and non-wrapping for Chinese and English labels", () => {
  87. const zhHtml = renderRemoteConnectionFields("zh-CN");
  88. const enHtml = renderRemoteConnectionFields("en-US");
  89. for (const html of [zhHtml, enHtml]) {
  90. expect(html).toContain("sm:grid-cols-[minmax(0,1fr)_12rem]");
  91. expect(html).toContain("whitespace-nowrap");
  92. }
  93. });
  94. });