conversation-session-remote-presentation-states.test.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { mkdir } from "node:fs/promises";
  2. import { resolve } from "node:path";
  3. import {
  4. TID_SETTINGS_BACK_BUTTON,
  5. TID_SETTINGS_PAGE,
  6. TID_TASK_SETTINGS_BUTTON,
  7. } from "@zcode/shared/test-ids";
  8. import { clearAppData, clickTestIdByDom, waitForWorkspaceApp } from "#e2e/helpers/desktop-app";
  9. import { prepareV4ConversationE2E } from "#e2e/helpers/v4-conversation";
  10. import { selectRemoteDeviceMenuItem } from "#e2e/helpers/remote-project-actions";
  11. import {
  12. clickLastEnabledSSHDialogButton,
  13. fillSSHPasswordSettings,
  14. openSSHRemoteDialog,
  15. readSSHRuntimeConfig,
  16. prepareSSHConnectionPage,
  17. selectSSHRemoteDirectory,
  18. waitForSSHDirectoryStep,
  19. waitForRemoteTab,
  20. } from "#e2e/helpers/ssh-remote-p0";
  21. const CASE_MARKER = "E2E_REMOTE_PRESENTATION_STATES";
  22. describe(`${CASE_MARKER}: 远程连接展示`, () => {
  23. after(async () => {
  24. await browser.electron.restoreAllMocks();
  25. await clearAppData();
  26. });
  27. it("RDUX-STATE 主动断开后设置和侧栏均显示中性未连接", async function () {
  28. this.timeout(15 * 60_000);
  29. const config = readSSHRuntimeConfig(CASE_MARKER);
  30. const path = config.workspacePaths[0];
  31. await prepareSSHConnectionPage(CASE_MARKER);
  32. await prepareV4ConversationE2E({ skipProvider: true });
  33. await openSSHRemoteDialog(CASE_MARKER);
  34. await fillSSHPasswordSettings(config);
  35. await clickLastEnabledSSHDialogButton(CASE_MARKER);
  36. await waitForSSHDirectoryStep(CASE_MARKER);
  37. await selectSSHRemoteDirectory(path, CASE_MARKER);
  38. await waitForWorkspaceApp(path, 120_000);
  39. const tab = await waitForRemoteTab({ caseMarker: CASE_MARKER, expectedPath: path });
  40. await browser.waitUntil(
  41. async () =>
  42. await browser.execute((identity) => {
  43. const row = [
  44. ...document.querySelectorAll<HTMLElement>("[data-project-workspace-identity]"),
  45. ].find((item) => item.dataset.projectWorkspaceIdentity === identity);
  46. return row?.dataset.connectionState === "online";
  47. }, tab.workspaceIdentity),
  48. { timeout: 20_000 },
  49. );
  50. await clickTestIdByDom(TID_TASK_SETTINGS_BUTTON);
  51. await $(`[data-testid="${TID_SETTINGS_PAGE}"]`).waitForDisplayed();
  52. await browser.execute(() => {
  53. const button = [...document.querySelectorAll<HTMLButtonElement>("button")].find((item) =>
  54. /^(远程设备|Remote devices)$/u.test(item.textContent?.trim() ?? ""),
  55. );
  56. if (!button) throw new Error("Remote devices navigation missing");
  57. button.click();
  58. });
  59. await $('[data-remote-connection-status="online"]').waitForDisplayed();
  60. // RDUX-13:断开在设备行「更多」菜单里。
  61. const onlineSourceId = await browser.execute(
  62. () =>
  63. document
  64. .querySelector('[data-remote-connection-status="online"]')
  65. ?.closest("[data-source-server-card]")
  66. ?.getAttribute("data-source-server-card") ?? null,
  67. );
  68. if (!onlineSourceId) throw new Error("Online device row missing");
  69. await selectRemoteDeviceMenuItem(onlineSourceId, ["断开", "Disconnect"], CASE_MARKER);
  70. const status = $('[data-remote-connection-status="offline"]');
  71. await status.waitForDisplayed({ timeout: 20_000 });
  72. expect(await status.getText()).toMatch(/未连接|Not connected/u);
  73. // 现行远程中性文字使用专用 token;继续验证非告警色,不能把旧 CSS 类名当成功能合同。
  74. expect(await status.getAttribute("class")).toContain("text-remote-foreground-muted");
  75. expect(await status.getAttribute("class")).not.toMatch(/warning|destructive/u);
  76. await clickTestIdByDom(TID_SETTINGS_BACK_BUTTON);
  77. await browser.waitUntil(
  78. async () =>
  79. await browser.execute((identity) => {
  80. const row = [
  81. ...document.querySelectorAll<HTMLElement>("[data-project-workspace-identity]"),
  82. ].find((item) => item.dataset.projectWorkspaceIdentity === identity);
  83. return (
  84. row?.dataset.connectionState === "offline" &&
  85. /离线|Offline/u.test(row.textContent ?? "") &&
  86. !row.querySelector('[data-remote-state-icon="cloud-x"]')
  87. );
  88. }, tab.workspaceIdentity),
  89. { timeout: 20_000 },
  90. );
  91. const artifactDir = resolve(
  92. process.env.ZCODE_E2E_ARTIFACT_DIR ?? ".e2e-artifacts/remote-presentation-states",
  93. );
  94. await mkdir(artifactDir, { recursive: true });
  95. for (const locale of ["zh-CN", "en-US"] as const) {
  96. await browser.execute((value) => {
  97. const actions = (
  98. window as Window & { __testActions?: { setLocale(value: "zh-CN" | "en-US"): void } }
  99. ).__testActions;
  100. if (!actions) throw new Error("Missing locale actions");
  101. actions.setLocale(value);
  102. }, locale);
  103. await browser.waitUntil(
  104. async () =>
  105. await browser.execute(
  106. (label) =>
  107. [
  108. ...document.querySelectorAll<HTMLElement>('[data-testid="virtual-project-toggle"]'),
  109. ].some((item) => item.textContent?.includes(label)),
  110. locale === "en-US" ? "Offline" : "离线",
  111. ),
  112. { timeout: 5000 },
  113. );
  114. for (const theme of ["light", "dark"]) {
  115. await browser.execute((value) => {
  116. const actions = (window as Window & { __testActions?: { setTheme(value: string): void } })
  117. .__testActions;
  118. if (!actions) throw new Error("Missing theme actions");
  119. actions.setTheme(value);
  120. }, theme);
  121. for (const width of [1400, 900]) {
  122. await browser.electron.execute((electron, nextWidth) => {
  123. electron.BrowserWindow.getAllWindows()
  124. .find((window) => !window.isDestroyed())
  125. ?.setSize(nextWidth, 900);
  126. }, width);
  127. await browser.executeAsync((done) =>
  128. requestAnimationFrame(() => requestAnimationFrame(() => done())),
  129. );
  130. await browser.saveScreenshot(
  131. resolve(artifactDir, `disconnected-${locale}-${theme}-${width}.png`),
  132. );
  133. }
  134. }
  135. }
  136. });
  137. });