From 6f55548661593b3b1abfba860436ac6ad064adfe Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Fri, 15 May 2026 03:14:52 +0800 Subject: [PATCH] fix(editor): improve tests stability (#14971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### PR Dependency Tree * **PR #14971** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Tests** * Improved shape selection reliability in edge case testing scenarios * Enhanced rich text editor focusing logic with better synchronization for inline editor state validation [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14971) --- .../blocksuite/e2e/utils/actions/edgeless.ts | 19 +++++------------ tests/blocksuite/e2e/utils/actions/misc.ts | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/blocksuite/e2e/utils/actions/edgeless.ts b/tests/blocksuite/e2e/utils/actions/edgeless.ts index f00007bd76..0c3ab90e65 100644 --- a/tests/blocksuite/e2e/utils/actions/edgeless.ts +++ b/tests/blocksuite/e2e/utils/actions/edgeless.ts @@ -376,28 +376,19 @@ export async function setEdgelessTool( 'shape', false ); - const shapeToolBox = await shapeToolButton.boundingBox(); - if (!shapeToolBox) { - throw new Error('shapeToolBox is not found'); - } - - await page.mouse.click(shapeToolBox.x + 2, shapeToolBox.y + 2); + await shapeToolButton.click({ position: { x: 2, y: 2 } }); const shapeMenu = page.locator('edgeless-shape-menu'); + if ((await shapeMenu.count()) === 0 && shape === Shape.Square) { + break; + } await expect(shapeMenu).toBeVisible(); const squareShapeButton = shapeMenu .locator('edgeless-tool-icon-button') .filter({ hasText: shape }); await expect(squareShapeButton).toBeVisible(); - const squareShapeBox = await squareShapeButton.boundingBox(); - if (!squareShapeBox) { - throw new Error('squareShapeBox is not found'); - } - await page.mouse.click( - squareShapeBox.x + squareShapeBox.width / 2, - squareShapeBox.y + squareShapeBox.height / 2 - ); + await squareShapeButton.click(); break; } } diff --git a/tests/blocksuite/e2e/utils/actions/misc.ts b/tests/blocksuite/e2e/utils/actions/misc.ts index 6e6b7f96a1..bfcff6b6e7 100644 --- a/tests/blocksuite/e2e/utils/actions/misc.ts +++ b/tests/blocksuite/e2e/utils/actions/misc.ts @@ -552,6 +552,27 @@ export async function focusRichText( await expect(locator).toBeVisible(); // need to set `force` to true when clicking on `affine-selected-blocks` await locator.click({ force: true, position: options?.clickPosition }); + await expect + .poll(() => + page.evaluate( + ([i, currentEditorIndex]) => { + const editorHost = + document.querySelectorAll('editor-host')[currentEditorIndex]; + const richText = + editorHost?.querySelectorAll('rich-text')[i]; + const inlineEditor = richText?.inlineEditor; + if (!inlineEditor) { + return false; + } + if (inlineEditor.getInlineRange() === null) { + inlineEditor.focusIndex(0); + } + return inlineEditor.getInlineRange() !== null; + }, + [i, currentEditorIndex] + ) + ) + .toBe(true); } export async function focusRichTextEnd(page: Page, i = 0) {