workflow-tool-summary.test.mjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 手动回归前置:dev Electron(9229)已打开包含 CreateWorkflow run 的会话。
  2. // 不发送模型请求、不改业务数据;复用当前会话验证真实 side pane 路由。
  3. import assert from "node:assert/strict";
  4. import test from "node:test";
  5. import { chromium } from "playwright-core";
  6. test("WFS01 workflow 普通摘要打开同一个 run side pane", async () => {
  7. const connection = await chromium.connectOverCDP(
  8. process.env.ZCODE_E2E_CDP_URL ?? "http://localhost:9229",
  9. );
  10. try {
  11. const page = connection
  12. .contexts()
  13. .flatMap((context) => context.pages())
  14. .find((page) => page.url().includes("localhost:"));
  15. assert.ok(page, "需要正在运行的 dev Electron 页面");
  16. const summary = page.getByTestId("workflow-tool-summary").first();
  17. await summary.waitFor({ state: "attached", timeout: 120000 });
  18. // 历史工具默认折叠:展开祖先的 Radix trigger 后再执行真实用户点击。
  19. await summary.evaluate((node) => {
  20. for (let parent = node.parentElement; parent; parent = parent.parentElement) {
  21. if (parent.id && parent.getAttribute("data-state") === "closed") {
  22. document.querySelector(`[aria-controls="${CSS.escape(parent.id)}"]`)?.click();
  23. }
  24. }
  25. });
  26. await summary.waitFor({ state: "visible", timeout: 10000 });
  27. const runId = await summary.getAttribute("data-workflow-run-id");
  28. assert.ok(runId);
  29. assert.equal(await summary.getByTestId("workflow-timeline-station").count(), 0);
  30. assert.match(await summary.innerText(), /Workflow.*\d/s);
  31. const trigger = summary.getByRole("button");
  32. const steps = summary.getByTestId("workflow-summary-steps");
  33. await page.mouse.move(0, 0);
  34. const idleColor = await steps.evaluate((node) => getComputedStyle(node).color);
  35. await trigger.hover();
  36. assert.notEqual(await steps.evaluate((node) => getComputedStyle(node).color), idleColor);
  37. await trigger.click();
  38. const pane = page
  39. .locator("div.flex.h-full[data-workflow-run-id]:not([data-testid])")
  40. .filter({ has: page.locator('[data-testid="workflow-run-graph-unavailable"], button') });
  41. await page.waitForFunction(
  42. (id) =>
  43. Array.from(
  44. document.querySelectorAll("div.flex.h-full[data-workflow-run-id]:not([data-testid])"),
  45. ).some((node) => node.getAttribute("data-workflow-run-id") === id),
  46. runId,
  47. );
  48. assert.ok((await pane.count()) > 0);
  49. await trigger.focus();
  50. await trigger.press("Enter");
  51. assert.equal(
  52. await page
  53. .locator("div.flex.h-full[data-workflow-run-id]:not([data-testid])")
  54. .evaluateAll(
  55. (nodes, id) =>
  56. nodes.filter((node) => node.getAttribute("data-workflow-run-id") === id).length,
  57. runId,
  58. ),
  59. 1,
  60. );
  61. } finally {
  62. await connection.close();
  63. }
  64. });