conversation-session-remote-offline-icons.test.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { reloadElectronSessionPreservingBrowserProfile } from "#e2e/helpers/e2e-electron-reload";
  2. import {
  3. TID_SSH_DIALOG,
  4. TID_SETTINGS_SECTION_NAV,
  5. TID_TASK_SETTINGS_BUTTON,
  6. testId,
  7. } from "@zcode/shared/test-ids";
  8. import {
  9. clearAppData,
  10. seedSettings,
  11. clickTestIdByDom,
  12. pinE2ELocale,
  13. } from "#e2e/helpers/desktop-app";
  14. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  15. import { waitForRendererAfterColdRestart } from "#e2e/helpers/ssh-remote-lifecycle";
  16. const CASE_MARKER = "E2E_REMOTE_OFFLINE_ICONS";
  17. const SOURCE_ID = "b2d3aeee-9c83-4d03-b62b-40dbed84d389";
  18. describe(`${CASE_MARKER}: 离线设备连接按钮`, () => {
  19. after(async () => {
  20. await browser.electron.restoreAllMocks();
  21. await clearAppData();
  22. });
  23. it("RUI-SIMPLE-11 设置页已识别和 pending SSH/Docker 均有可访问连接按钮,键盘可进入对应向导", async function () {
  24. this.timeout(120_000);
  25. await prepareV4ConversationE2E({ skipProvider: true });
  26. await seedSettings({
  27. remoteStartupAutoReconnectEnabled: false,
  28. sourceServerDirectoryMigrationVersion: 1,
  29. sourceServers: [
  30. {
  31. sourceServerId: SOURCE_ID,
  32. displayName: "E2E known",
  33. installState: "installed",
  34. declaredWorkspaces: [],
  35. },
  36. ],
  37. sourceServerWorkspaceHistory: [],
  38. lastWorkspaceSession: [
  39. {
  40. kind: "remote",
  41. workspacePath: "/e2e/known",
  42. workspaceIdentity: `remote:server:${SOURCE_ID}:/e2e/known`,
  43. target: { kind: "ssh", host: "127.0.0.1", port: 1, username: "e2e" },
  44. lastOpenedAt: Date.now(),
  45. lastConnectionStatus: "failed",
  46. },
  47. {
  48. kind: "remote",
  49. workspacePath: "/e2e/ssh",
  50. workspaceIdentity: "remote:ssh:127.0.0.1:2:e2e:/e2e/ssh",
  51. target: {
  52. kind: "ssh",
  53. host: "127.0.0.1",
  54. port: 2,
  55. username: "e2e",
  56. sshConfigAlias: "E2E pending SSH",
  57. },
  58. lastOpenedAt: Date.now(),
  59. lastConnectionStatus: "failed",
  60. },
  61. {
  62. kind: "remote",
  63. workspacePath: "/e2e/docker",
  64. workspaceIdentity: "remote:docker:e2e-pending-docker:/e2e/docker",
  65. target: { kind: "docker", container: "e2e-pending-docker" },
  66. lastOpenedAt: Date.now(),
  67. lastConnectionStatus: "failed",
  68. },
  69. ],
  70. connectionProfiles: [
  71. {
  72. profileId: "297c6971-47a3-40ca-8767-678b50889922",
  73. sourceServerId: SOURCE_ID,
  74. displayName: "E2E known",
  75. transport: "ssh",
  76. createdAt: 1,
  77. lifecycleState: "active",
  78. target: { kind: "ssh", host: "127.0.0.1", port: 1, username: "e2e" },
  79. },
  80. {
  81. profileId: "d41c3adc-c998-4052-b2aa-04adf90beb5e",
  82. displayName: "E2E pending SSH",
  83. transport: "ssh",
  84. createdAt: 1,
  85. lifecycleState: "active",
  86. target: { kind: "ssh", host: "127.0.0.1", port: 2, username: "e2e" },
  87. },
  88. {
  89. profileId: "2c47f140-7116-4a1f-a7b6-098771cfe19d",
  90. displayName: "e2e-pending-docker",
  91. transport: "docker",
  92. createdAt: 1,
  93. lifecycleState: "active",
  94. target: { kind: "docker", container: "e2e-pending-docker" },
  95. },
  96. ],
  97. });
  98. await reloadElectronSessionPreservingBrowserProfile(browser);
  99. await waitForRendererAfterColdRestart(CASE_MARKER);
  100. // 首帧跟随宿主语言,mac runner 上是英文,按钮文案为 Connect;本 case 断言中文,须固定语言。
  101. await pinE2ELocale("zh-CN");
  102. await clickTestIdByDom(TID_TASK_SETTINGS_BUTTON, { timeout: 15_000 });
  103. await clickTestIdByDom(testId(TID_SETTINGS_SECTION_NAV, "remoteDevices"), { timeout: 15_000 });
  104. // 未连通记录现在默认折叠且用连接行展示,旧 case 按设备卡的 p 标题读取会漏掉它们。
  105. const unfinished = $("[data-unfinished-connections]");
  106. await unfinished.waitForDisplayed();
  107. expect(await unfinished.getAttribute("open")).toBeNull();
  108. await unfinished.$("summary").click();
  109. await browser.waitUntil(async () => (await readActions()).length === 3, {
  110. timeout: 30_000,
  111. timeoutMsg: `${CASE_MARKER}: 三条已保存连接未出现`,
  112. });
  113. const actions = await readActions();
  114. expect(actions.map((item) => item.name).sort()).toEqual(
  115. ["E2E known", "E2E pending SSH", "e2e-pending-docker"].sort(),
  116. );
  117. expect(actions.every((item) => item.label === "连接" && !item.disabled)).toBe(true);
  118. // 在同一轮观测中聚焦目标设备卡连接按钮,再发送真实键盘事件。
  119. await browser.waitUntil(
  120. async () => {
  121. const focused = await browser.execute(() => {
  122. const card = Array.from(
  123. document.querySelectorAll<HTMLElement>(
  124. '[data-testid="settings-page"] p, [data-testid="settings-page"] span',
  125. ),
  126. )
  127. .find((item) => item.textContent?.trim() === "E2E pending SSH")
  128. ?.closest("div.group\\/line, section");
  129. const button = Array.from(card?.querySelectorAll<HTMLButtonElement>("button") ?? []).find(
  130. (item) => item.innerText.trim() === "连接",
  131. );
  132. if (!button) return false;
  133. if (document.activeElement !== button) button.focus();
  134. return document.activeElement === button;
  135. });
  136. if (focused) await browser.keys("Enter");
  137. return browser.execute(
  138. (dialogTestId) => Boolean(document.querySelector(`[data-testid="${dialogTestId}"]`)),
  139. TID_SSH_DIALOG,
  140. );
  141. },
  142. {
  143. timeout: 20_000,
  144. interval: 1_000,
  145. timeoutMsg: `${CASE_MARKER}: 键盘没有触发既有 workspace 连接动作(弹窗未打开)`,
  146. },
  147. );
  148. });
  149. });
  150. function readActions() {
  151. return browser.execute(() =>
  152. ["E2E known", "E2E pending SSH", "e2e-pending-docker"].flatMap((name) => {
  153. // 设置页外层也包含所有标题,只取标题最近的设备卡,避免重复或点到其他设备。
  154. const row = Array.from(
  155. document.querySelectorAll<HTMLElement>(
  156. '[data-testid="settings-page"] p, [data-testid="settings-page"] span',
  157. ),
  158. )
  159. .find((item) => item.textContent?.trim() === name)
  160. ?.closest("div.group\\/line, section");
  161. const action = Array.from(row?.querySelectorAll<HTMLButtonElement>("button") ?? []).find(
  162. (item) => item.innerText.trim() === "连接",
  163. );
  164. return action ? [{ name, label: action.innerText.trim(), disabled: action.disabled }] : [];
  165. }),
  166. );
  167. }