test(desktop): await native block selection before typing

Apply sealed 6492 test-only readiness correction; production is unchanged.

Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-09-09 19:08:03 -04:00
parent c26596866a
commit 524d92cd26

View File

@@ -307,7 +307,26 @@ for (const format of [
await input.pressSequentially("before");
await input.press("Shift+Enter");
await applyCaretFormat(page, format.label);
await input.pressSequentially("inside");
// Toolbar focus synchronizes the new caret on a later animation frame.
// Locator typing would focus the DOM itself, reviving the old caret.
await expect(input).toBeFocused();
await expect
.poll(() =>
input.evaluate((element, selector) => {
const block = element.querySelector(`:scope > ${selector}`);
const selection = window.getSelection();
return (
document.activeElement === element &&
!!selection?.isCollapsed &&
!!selection.anchorNode &&
!!selection.focusNode &&
!!block?.contains(selection.anchorNode) &&
block.contains(selection.focusNode)
);
}, format.selector),
)
.toBe(true);
await page.keyboard.type("inside");
await expect(input.locator(":scope > p").first()).toHaveText("before");
await expect(input.locator(`:scope > ${format.selector}`)).toHaveText(