Skip to content

Commit 9213090

Browse files
cameronhotchkiesnpub1x4hk035p3p9q39a3fcrd2fe30lpkrhr5dwe0cqzzjphxyyh8m0gsq4vqapwesbillman
authored
test(desktop): await thread scroll anchor (block#3174)
## Why The focus/split E2E test could capture the thread root before its programmatic middle-thread scroll had settled, then incorrectly report a scroll-restoration failure. ## What - Poll until the requested middle-thread scroll position is applied - Require the captured anchor to intersect the thread viewport and differ from the root - Preserve the existing focus-to-split-to-focus viewport assertions ## Risk Assessment Low — test-only synchronization change with no production behavior changes. ## References - Original failure: https://github.com/block/buzz/actions/runs/30231271427/job/89870533541 - Buzz thread: buzz://message?channel=12dd513d-45fd-48ff-80ac-8596d2fcc9d3&id=87ce6024b4bf74bfac2fa75d9f7bbbcc8f8fe2df460afe534152c495929f51ba - Reproduced confidence: 20 consecutive targeted passes, full spec pass, `just desktop-ci`, and `just ci` Generated with Codex Signed-off-by: npub1x4hk035p3p9q39a3fcrd2fe30lpkrhr5dwe0cqzzjphxyyh8m0gsq4vqap <356f67c681884a0897b14e06d527317fc361dc746bb2fc0042906e6212e7dbd1@buzz.block.builderlab.xyz> Co-authored-by: npub1x4hk035p3p9q39a3fcrd2fe30lpkrhr5dwe0cqzzjphxyyh8m0gsq4vqap <356f67c681884a0897b14e06d527317fc361dc746bb2fc0042906e6212e7dbd1@buzz.block.builderlab.xyz> Co-authored-by: Wes <[email protected]>
1 parent 480c41e commit 9213090

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

‎desktop/tests/e2e/thread-focus-mode.spec.ts‎

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,37 @@ async function seedLongThread(page: import("@playwright/test").Page) {
3030
});
3131
}
3232

33-
async function topVisibleMessageId(
33+
async function scrollToMiddleVisibleMessage(
3434
body: import("@playwright/test").Locator,
35+
threadRootId: string,
3536
): Promise<string> {
36-
return body.evaluate((element) => {
37-
const top = element.getBoundingClientRect().top;
38-
const row = Array.from(
39-
element.querySelectorAll<HTMLElement>("[data-message-id]"),
40-
).find((candidate) => candidate.getBoundingClientRect().bottom > top);
41-
if (!row?.dataset.messageId) throw new Error("No visible thread anchor");
42-
return row.dataset.messageId;
43-
});
37+
let anchorId: string | null = null;
38+
await expect
39+
.poll(async () => {
40+
anchorId = await body.evaluate((element) => {
41+
const maxScrollTop = element.scrollHeight - element.clientHeight;
42+
if (maxScrollTop <= 0) return null;
43+
44+
const targetScrollTop = Math.floor(maxScrollTop * 0.4);
45+
element.scrollTop = targetScrollTop;
46+
element.dispatchEvent(new Event("scroll", { bubbles: true }));
47+
48+
if (Math.abs(element.scrollTop - targetScrollTop) > 1) return null;
49+
const bounds = element.getBoundingClientRect();
50+
const row = Array.from(
51+
element.querySelectorAll<HTMLElement>("[data-message-id]"),
52+
).find((candidate) => {
53+
const rect = candidate.getBoundingClientRect();
54+
return rect.bottom > bounds.top && rect.top < bounds.bottom;
55+
});
56+
return row?.dataset.messageId ?? null;
57+
});
58+
return anchorId !== null && anchorId !== threadRootId;
59+
})
60+
.toBe(true);
61+
62+
if (!anchorId) throw new Error("No visible middle-thread anchor");
63+
return anchorId;
4464
}
4565

4666
/**
@@ -181,11 +201,7 @@ test("focus and split preserve reading context and interaction ownership", async
181201
.toBe(true);
182202
await expect(channel).toHaveAttribute("inert", "");
183203

184-
await body.evaluate((element) => {
185-
element.scrollTop = element.scrollHeight * 0.4;
186-
element.dispatchEvent(new Event("scroll", { bubbles: true }));
187-
});
188-
const anchorId = await topVisibleMessageId(body);
204+
const anchorId = await scrollToMiddleVisibleMessage(body, rootId);
189205

190206
const focusModeToggle = page.getByRole("button", {
191207
name: "Show thread beside channel",

0 commit comments

Comments
 (0)