Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/browser/canvas_creation.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import assert from "node:assert/strict";

/** Create a node through the same tool and type picker used on the canvas. */
export async function addCanvasNode(page, label) {
const toolbar = page.getByRole("toolbar", { name: /^(Canvas creation tools|画布创作工具)$/ });
await toolbar.getByRole("button", { name: /^(Add node|添加节点)$/ }).click();
const menu = page.getByRole("menu", { name: /^(New node|新建节点)$/ });
await menu.getByRole("menuitem", { name: label, exact: true }).click();
}
export async function clickBlankCanvas(page) {
const pane = page.locator(".react-flow__pane");
const point = await pane.evaluate((element) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里刚拿到 pane 就只取一次点;分栏或覆盖层还在收尾时,25 个点可能暂时都点不到,测试会立即断言失败。建议在有界超时内重算可点击点,并在实际点击前再确认一次命中的是 pane,而不是改成固定等待。

const bounds = element.getBoundingClientRect();
for (const row of [0.7, 0.5, 0.3, 0.85, 0.15]) {
for (const column of [0.75, 0.5, 0.25, 0.9, 0.1]) {
const x = bounds.left + bounds.width * column;
const y = bounds.top + bounds.height * row;
if (document.elementFromPoint(x, y) === element) return { x, y };
}
}
return null;
});
assert.ok(point, "A blank point must be visible on the canvas");
await page.mouse.click(point.x, point.y);
}
5 changes: 2 additions & 3 deletions tests/browser/canvas_notifications.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Isolated UI regression: missing models and independent notification lifetimes. */
import { addCanvasNode } from "./canvas_creation.mjs";
import { addCanvasNode, clickBlankCanvas } from "./canvas_creation.mjs";
import assert from "node:assert/strict";
const { chromium } = await import(
process.env.PLAYWRIGHT_MODULE ?? "playwright-core"
Expand Down Expand Up @@ -76,9 +76,8 @@ try {
}
// The toast mechanics below need a repeatable notification without side
// effects: cutting with nothing selected reports that nothing can be cut.
const pane = page.locator(".react-flow__pane");
const notifyOnce = async () => {
await pane.click({ position: { x: 1200, y: 160 } });
await clickBlankCanvas(page);
await page.keyboard.press("ControlOrMeta+x");
};
await notifyOnce();
Expand Down
5 changes: 3 additions & 2 deletions tests/browser/creation_ripple.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** New nodes light up the canvas dots once; opening a canvas and undo/redo do not. */
import assert from "node:assert/strict";
import { clickBlankCanvas } from "./canvas_creation.mjs";
import { launchBrowser } from "./engine.mjs";
const base = process.env.CREATION_WEB_URL ?? "http://127.0.0.1:5179";
const api = process.env.CREATION_API_URL ?? "http://127.0.0.1:8019";
Expand Down Expand Up @@ -44,7 +45,7 @@ try {
}
checks.push("opening a canvas does not ripple");

await page.locator(".react-flow__pane").click({ position: { x: 1000, y: 700 } });
await clickBlankCanvas(page);
const before = await page.locator(".react-flow__node").count();
await page.keyboard.press("t");
await page.waitForFunction((count) => document.querySelectorAll(".react-flow__node").length > count, before);
Expand All @@ -53,7 +54,7 @@ try {
await page.waitForFunction(() => !document.querySelector("[data-creation-ripple]"), undefined, { timeout: 4000 });
checks.push("local creation ripples once and clears");

await page.locator(".react-flow__pane").click({ position: { x: 1200, y: 820 } });
await clickBlankCanvas(page);
const mod = process.platform === "darwin" ? "Meta" : "Control";
await page.keyboard.press(`${mod}+z`);
await page.waitForFunction((count) => document.querySelectorAll(".react-flow__node").length === count, before);
Expand Down
Loading