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

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