From 3203ab5859a3e9f99015d9fd0ac4e3a049c76566 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Thu, 26 Nov 2026 14:01:10 +0800 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=E7=AD=89=E5=BE=85=E5=88=92?= =?UTF-8?q?=E9=80=89=E6=B5=AE=E5=B1=82=E5=9C=A8=E7=AA=97=E5=8F=A3=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E5=90=8E=E9=87=8D=E6=8E=92=E5=86=8D=E9=87=8F=E5=87=A0?= =?UTF-8?q?=E4=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 菜单的 left/width 由 useViewportSize 推导,而该 hook 在 resize 事件里 经过一次 requestAnimationFrame 才测量。测试在 setViewportSize() 之后 立刻读 boundingBox,偶发读到 resize 前的旧几何(CI 上实测 x+width = 529 > 390),于是 mount lane 间歇性失败。 改成用 expect.poll 等浮层重排到视口内再断言,断言本身不变:仍然要求 x >= 0、x+width <= 390。 --- tests/e2e/clues-ui19.e2e.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/e2e/clues-ui19.e2e.ts b/tests/e2e/clues-ui19.e2e.ts index a5a9904f..fbb07792 100644 --- a/tests/e2e/clues-ui19.e2e.ts +++ b/tests/e2e/clues-ui19.e2e.ts @@ -288,9 +288,16 @@ test('UI19 translates read-only body and comments inline and inserts without sen await menu.screenshot({ path: info.outputPath('selection-translation-' + theme + '.png') }) } await page.setViewportSize({ width: 390, height: 844 }) + // The menu re-clamps from `useViewportSize`, which measures on the next + // animation frame after a resize; reading the box straight after + // setViewportSize() races that frame. Poll for the settled geometry so the + // assertion covers the re-clamp instead of the resize timing. + await expect.poll(async () => { + const box = await menu.boundingBox() + return box === null ? Number.POSITIVE_INFINITY : Math.round(box.x + box.width) + }, { message: 'the menu re-clamps inside the 390px viewport' }).toBeLessThanOrEqual(390) const bounds = (await menu.boundingBox())! expect(bounds.x).toBeGreaterThanOrEqual(0) - expect(bounds.x + bounds.width).toBeLessThanOrEqual(390) await expect(footer.getByRole('menuitem', { name: 'Back', exact: true })).toBeVisible() await expect(footer.getByRole('menuitem', { name: 'Copy', exact: true })).toBeVisible() expect(await menu.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true)