workflow-prelaunch.test.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // 单独运行:node --test <此文件>;前置为 dev Vite/Electron 已启动(默认 CDP 9229)。
  2. // 独立页面挂真实 renderer,验证上方摘要交互;不声称覆盖 CLI 审批传输。
  3. import assert from "node:assert/strict";
  4. import test from "node:test";
  5. import { fileURLToPath } from "node:url";
  6. import { chromium } from "playwright-core";
  7. test("WFS02 编写无内容,待确认可展开;桌面深色与手机浅色", async () => {
  8. const targets = await (
  9. await fetch(`${process.env.ZCODE_E2E_CDP_URL ?? "http://localhost:9229"}/json/list`)
  10. ).json();
  11. const app = targets.find((target) => target.type === "page" && target.url.includes("localhost:"));
  12. assert.ok(app);
  13. const origin = new URL(app.url).origin;
  14. const connection = await chromium.launch({ headless: true, channel: "chrome" });
  15. const context = await connection.newContext();
  16. let page;
  17. try {
  18. const fixture = fileURLToPath(
  19. new URL("../../../../../../ui/test/fixtures/workflow-prelaunch.fixture.tsx", import.meta.url),
  20. );
  21. page = await context.newPage();
  22. await page.route("**/__workflow_prelaunch_smoke", (route) =>
  23. route.fulfill({
  24. contentType: "text/html",
  25. body: `<div id="root"></div><script type="module">import RefreshRuntime from '/@react-refresh'; RefreshRuntime.injectIntoGlobalHook(window); window.$RefreshReg$=()=>{}; window.$RefreshSig$=()=>type=>type; window.__vite_plugin_react_preamble_installed__=true; await import('/@fs/${fixture}');</script>`,
  26. }),
  27. );
  28. for (const width of [1200, 390]) {
  29. await page.setViewportSize({ width, height: 800 });
  30. await page.emulateMedia({ colorScheme: width === 1200 ? "dark" : "light" });
  31. await page.goto(`${origin}/__workflow_prelaunch_smoke`);
  32. const summary = page.locator(".group\\/tool-summary");
  33. await summary.waitFor();
  34. assert.match(await summary.innerText(), /Writing workflow/);
  35. assert.equal(await summary.getAttribute("role"), null);
  36. assert.equal(await page.locator("pre").count(), 0);
  37. await page.getByTestId("advance-state").click();
  38. assert.match(await summary.innerText(), /Awaiting workflow confirmation/);
  39. assert.equal(await summary.locator(".font-mono").count(), 0);
  40. assert.equal(
  41. await summary.locator(".tool-summary-kind-label.animated-gradient-text").count(),
  42. 1,
  43. );
  44. assert.equal(await summary.getAttribute("aria-expanded"), "false");
  45. await summary.press("Enter");
  46. await page.locator("pre").first().waitFor();
  47. const code = page.getByTestId("workflow-script-codeblock");
  48. assert.equal(await code.getByRole("button", { name: "Copy code" }).count(), 1);
  49. // 高亮正文异步挂载,等待布局完成后再验证限高滚动。
  50. await page.waitForFunction(() => {
  51. const node = document.querySelector('[data-testid="workflow-script-codeblock"] .max-h-80');
  52. return node && node.clientHeight > 0 && node.scrollHeight > node.clientHeight;
  53. });
  54. assert.ok(
  55. await code
  56. .locator(".max-h-80")
  57. .evaluate((node) => node.clientHeight <= 320 && node.scrollHeight > node.clientHeight),
  58. );
  59. const copy = code.getByRole("button", { name: "Copy code" });
  60. const before = await copy.boundingBox();
  61. await code.locator(".max-h-80").evaluate((node) => {
  62. node.scrollTop = 100;
  63. });
  64. assert.equal((await copy.boundingBox()).y, before.y);
  65. assert.equal(await summary.getAttribute("aria-expanded"), "true");
  66. await summary.click();
  67. assert.equal(await summary.getAttribute("aria-expanded"), "false");
  68. }
  69. } finally {
  70. await page?.close();
  71. await context.close();
  72. await connection.close();
  73. }
  74. });