From e65e86fd9492f07a7d8d079617aa7449379c4d72 Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 15 May 2026 15:42:25 +0100 Subject: [PATCH] test: focus the editor before typing in three specs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These three Playwright tests started failing after the autofocus removal in ef95498 because they reached for keyboard input without first clicking into the editor: - enter.spec.ts: `lastLine.focus()` is a no-op on a
(not natively focusable), so Enter went to instead of the contenteditable. Replaced with `.click()`. - indentation.spec.ts: `selectText()` triple-clicks but the focus event didn't reliably reach the inner contenteditable in CI; added an explicit `.click()` first. - collab_client.spec.ts: each test opens its own browser contexts via goToPad, which does not click into the editor; selectText() in replaceLineText was the only thing landing focus, and that proved flaky. Added `body.click()` at the top of replaceLineText. All three previously relied on the page-load auto-focus that ef95498 removed. The new pattern (click first, then type) is what writeToPad and clearPadContent already do — these specs now match. Refs #7255 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/tests/frontend-new/specs/collab_client.spec.ts | 5 +++++ src/tests/frontend-new/specs/enter.spec.ts | 6 +++++- src/tests/frontend-new/specs/indentation.spec.ts | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tests/frontend-new/specs/collab_client.spec.ts b/src/tests/frontend-new/specs/collab_client.spec.ts index 9d4581438..12b89a104 100644 --- a/src/tests/frontend-new/specs/collab_client.spec.ts +++ b/src/tests/frontend-new/specs/collab_client.spec.ts @@ -30,6 +30,11 @@ test.describe('Messages in the COLLABROOM', function () { const div = body.locator('div').nth(lineNumber) + // Click into the editor before keypresses. Each test opens its own + // browser contexts via goToPad, which does not click — previously the + // page-load auto-focus put the editor in focus regardless, but that + // was removed in #7255 so the skip link could be Tab-reachable. + await body.click(); // simulate key presses to delete content await div.locator('span').selectText() // select all await page.keyboard.press('Backspace') // clear the first line diff --git a/src/tests/frontend-new/specs/enter.spec.ts b/src/tests/frontend-new/specs/enter.spec.ts index beb54203a..d5c30eb30 100644 --- a/src/tests/frontend-new/specs/enter.spec.ts +++ b/src/tests/frontend-new/specs/enter.spec.ts @@ -49,7 +49,11 @@ test.describe('enter keystroke', function () { for (let i = 0; i < numberOfLines; i++) { const expectedCount = originalLength + i + 1; const lastLine = padBody.locator('div').last(); - await lastLine.focus(); + // `.focus()` is a no-op on a
(not natively focusable), so click + // the line to put the caret in the editor. Previously the editor was + // auto-focused on page load and this still happened to work; removing + // that auto-focus (#7255) makes the click explicit. + await lastLine.click(); await page.keyboard.press('End'); await page.keyboard.press('Enter'); await expect(padBody.locator('div')).toHaveCount(expectedCount); diff --git a/src/tests/frontend-new/specs/indentation.spec.ts b/src/tests/frontend-new/specs/indentation.spec.ts index a08834537..1190d71cc 100644 --- a/src/tests/frontend-new/specs/indentation.spec.ts +++ b/src/tests/frontend-new/specs/indentation.spec.ts @@ -12,6 +12,10 @@ test.describe('indentation button', function () { // get the first text element out of the inner iframe const $firstTextElement = padBody.locator('div').first(); + // Click first to land focus inside the editor iframe; the load-time + // auto-focus that previously did this was removed in #7255 so Tab + // could reach the skip-to-content link. + await $firstTextElement.click(); // select this text element await $firstTextElement.selectText()