diff --git a/tests/browser/canvas_creation.mjs b/tests/browser/canvas_creation.mjs index 9d530edd4..657696fea 100644 --- a/tests/browser/canvas_creation.mjs +++ b/tests/browser/canvas_creation.mjs @@ -1,3 +1,5 @@ +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|画布创作工具)$/ }); @@ -5,3 +7,19 @@ export async function addCanvasNode(page, label) { 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) => { + 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); +} diff --git a/tests/browser/canvas_notifications.mjs b/tests/browser/canvas_notifications.mjs index 1f864da71..e7019a510 100644 --- a/tests/browser/canvas_notifications.mjs +++ b/tests/browser/canvas_notifications.mjs @@ -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" @@ -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(); diff --git a/tests/browser/creation_ripple.mjs b/tests/browser/creation_ripple.mjs index 12798443f..bd8269939 100644 --- a/tests/browser/creation_ripple.mjs +++ b/tests/browser/creation_ripple.mjs @@ -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"; @@ -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); @@ -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);