Skip to content

Commit 72d05b6

Browse files
test(desktop): deselect-proof the code-scroll drag
The selection-drag assertion raced selection anchoring: mousedown on a guessed container offset sometimes never formed a selection anchor (cold-start font reflow moves the glyphs), so the long drag auto-scrolled without selecting and failed with an opaque zero at the end. Anchor on the measured first line after fonts settle, establish the selection with a short in-viewport drag, and only start the long auto-scroll drag once the selection observably exists.
1 parent 726fb80 commit 72d05b6

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

apps/desktop/e2e/code-scroll.spec.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,25 @@ test('a one-line Markdown code block exposes native and selection horizontal scr
100100
(element as HTMLElement).scrollLeft = 0;
101101
window.getSelection()?.removeAllRanges();
102102
});
103-
const code = viewport.locator('code');
104-
const codeBox = await code.boundingBox();
105-
if (!codeBox) throw new Error('code line has no visible bounds');
106-
const textY = codeBox.y + Math.min(codeBox.height / 2, 18);
107-
await page.mouse.move(codeBox.x + 24, textY);
103+
// Anchor the drag on the first rendered character, not a guessed container
104+
// offset: if mousedown lands in padding or between glyphs the selection
105+
// anchor never forms, and the long drag then auto-scrolls without selecting
106+
// (the historical flake in this test).
107+
const line = viewport.locator('code > [data-line]').first();
108+
// Cold-start guard: font loading reflows the glyphs, so a box measured
109+
// before fonts settle puts the anchor on the wrong pixel.
110+
await page.evaluate(() => document.fonts.ready.then(() => undefined));
111+
const lineBox = await line.boundingBox();
112+
if (!lineBox) throw new Error('code line has no visible bounds');
113+
const textY = lineBox.y + Math.min(lineBox.height / 2, 18);
114+
await page.mouse.move(lineBox.x + 24, textY);
108115
await page.mouse.down();
116+
// Establish the selection with a short in-viewport drag before the long
117+
// auto-scroll drag, and only proceed once the selection observably exists.
118+
await page.mouse.move(lineBox.x + 90, textY, { steps: 6 });
119+
await expect.poll(
120+
() => viewport.evaluate(() => window.getSelection()?.toString().length ?? 0),
121+
).toBeGreaterThan(0);
109122
await page.mouse.move(metrics.rect.x + metrics.rect.width + 50, textY, { steps: 20 });
110123
await expect.poll(
111124
() => viewport.evaluate((element) => (element as HTMLElement).scrollLeft),

0 commit comments

Comments
 (0)