From 8278ccf29085c5fcc754f0702609d2ebe2af5c14 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 6 Oct 2026 05:52:32 +0800 Subject: [PATCH] =?UTF-8?q?gui=20tests:=20plugin-move=20scrolls=20Zed's=20?= =?UTF-8?q?editor=20with=20the=20wheel=20and=20presses=20Move=20where=20it?= =?UTF-8?q?=20is=20=E2=80=94=20the=20test=20set=20.ebody's=20scrollTop=20t?= =?UTF-8?q?o=20120,=20which=20took=20the=20Move=20button=20out=20of=20sigh?= =?UTF-8?q?t,=20so=20Playwright's=20click=20scrolled=20the=20body=20back?= =?UTF-8?q?=20first=20(120=20=E2=86=92=2060=20or=200,=20"the=20failure=20m?= =?UTF-8?q?oved=20the=20editor",=20Chromium,=20failing=20in=20zh=20on=206e?= =?UTF-8?q?623d16=20and=20in=20both=20languages=20after).=20It=20now=20whe?= =?UTF-8?q?els=20only=20as=20far=20as=20the=20button=20stays=20in=20sight,?= =?UTF-8?q?=20and=20presses=20it=20with=20the=20mouse,=20checking=20it=20i?= =?UTF-8?q?s=20in=20sight;=20"the=20failure/the=20move=20moved=20the=20edi?= =?UTF-8?q?tor"=20are=20unchanged.=20Passes=20in=20Chromium=20and=20WebKit?= =?UTF-8?q?,=20en=20and=20zh,=20twice.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/tests/plugin-move.test.cjs | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/internal/gui/tests/plugin-move.test.cjs b/internal/gui/tests/plugin-move.test.cjs index 66b8f814..93b9a5aa 100644 --- a/internal/gui/tests/plugin-move.test.cjs +++ b/internal/gui/tests/plugin-move.test.cjs @@ -116,12 +116,29 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.ok(!text.includes(pkg), "names the npm package in the sentence"); assert.ok(text.includes(w.own), "doesn't say Zed stays signed in"); - // the reader scrolled to the field: nothing the move does moves it - const body = ed.locator(".ebody"); - const top = await body.evaluate((e) => { e.scrollTop = 120; return e.scrollTop; }); + // the reader scrolled to the field: nothing the move does moves it. + // A wheel, as a reader's scroll (a script's scrollTop is put back), and + // only so far that the button stays in sight: a click on a button out + // of sight is Playwright's own scroll first, not the reader's + const body = ed.locator(".ebody"), box = await body.boundingBox(); + const at = () => body.evaluate((e) => e.scrollTop); + await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); + for (let i = 0; i < 20 && (await btn.boundingBox()).y > box.y + 40; i++) { + const was = await at(); + await page.mouse.wheel(0, 30); + await page.waitForTimeout(80); + if (await at() === was) break; + } + const top = await at(); assert.ok(top > 0, "the editor doesn't scroll: the test proves nothing about keeping its place"); + // a press where the button is, as the reader's mouse does + const press = async () => { + const b = await btn.boundingBox(); + assert.ok(b.y >= box.y && b.y + b.height <= box.y + box.height, "the button is out of sight"); + await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2); + }; - await btn.click(); + await press(); await page.waitForFunction((busy) => [...document.querySelectorAll("#modal .move button")].some((b) => b.textContent === busy), w.busy, { timeout: 300 }); assert.equal(await btn.isDisabled(), true, "the button can be pressed again mid-move"); @@ -135,7 +152,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", if (process.env.ARTIFACT_DIR) await ed.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `plugin-move-failed-${engine}-${lang}.png`) }); // tried again, it goes through: the same editor, turned over - await btn.click(); + await press(); const back = ed.locator(".move button", { hasText: w.back }); await back.waitFor(); assert.equal(await page.locator("#modal .editor").count(), 1, "the editor closed");