workflow-notification-link.test.mjs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // 独立真实 renderer 验证 hover/focus;不依赖当前会话,不覆盖宿主侧栏路由。
  2. import assert from "node:assert/strict";
  3. import test from "node:test";
  4. import { chromium } from "playwright-core";
  5. test("完成通知产物链接样式与点击", async () => {
  6. const browser = await chromium.launch({ channel: "chrome", headless: true });
  7. try {
  8. const page = await browser.newPage();
  9. page.on("pageerror", (error) => {
  10. process.stderr.write(String(error));
  11. });
  12. const targets = await (await fetch("http://localhost:9229/json/list")).json();
  13. const origin = new URL(targets.find((t) => t.type === "page").url).origin;
  14. await page.route("**/__workflow_hover", (route) =>
  15. route.fulfill({
  16. contentType: "text/html",
  17. body: `<div id="root"></div><script type="module">
  18. import RefreshRuntime from '/@react-refresh'; RefreshRuntime.injectIntoGlobalHook(window); window.$RefreshReg$=()=>{}; window.$RefreshSig$=()=>type=>type; window.__vite_plugin_react_preamble_installed__=true;
  19. await import('/@fs${process.cwd()}/packages/ui/test/fixtures/workflow-notification-link.fixture.tsx');
  20. </script>`,
  21. }),
  22. );
  23. for (const width of [1200, 390]) {
  24. await page.setViewportSize({ width, height: 800 });
  25. await page.goto(`${origin}/__workflow_hover`);
  26. const summary = page.locator(".group\\/tool-summary");
  27. await summary.waitFor();
  28. assert.equal(await page.getByTestId("sample-artifact").locator(":scope > img").count(), 1);
  29. assert.equal(await page.getByTestId("sample-artifact").locator(".wf-pill-tile").count(), 0);
  30. assert.match(
  31. await summary.innerText(),
  32. /Workflow completed\s*·\s*Desktop workflow\s*·\s*Desktop startup/s,
  33. );
  34. const link = summary.getByRole("button", { name: "Desktop startup" });
  35. assert.match(await link.locator("img").getAttribute("src"), /markdown/i);
  36. await link.hover();
  37. assert.equal(await link.evaluate((n) => getComputedStyle(n).textDecorationLine), "underline");
  38. assert.equal(
  39. await link.evaluate((n) => getComputedStyle(n).backgroundColor),
  40. "rgba(0, 0, 0, 0)",
  41. );
  42. await link.click();
  43. assert.equal(await page.locator("body").getAttribute("data-open"), "true");
  44. assert.equal(await summary.getAttribute("aria-expanded"), "false");
  45. await summary.click();
  46. const result = page.getByTestId("workflow-notification-result");
  47. const copy = result.getByRole("button", { name: "Copy code" });
  48. await copy.waitFor();
  49. await page.waitForFunction(() => {
  50. const n = document.querySelector('[data-testid="workflow-notification-result"] .max-h-80');
  51. return n && n.scrollHeight > n.clientHeight;
  52. });
  53. const before = await copy.boundingBox();
  54. await result.locator(".max-h-80").evaluate((n) => {
  55. n.scrollTop = 100;
  56. });
  57. assert.equal((await copy.boundingBox()).y, before.y);
  58. }
  59. } finally {
  60. await browser.close();
  61. }
  62. });