Harden scroll E2E timing

This commit is contained in:
klopez4212
2026-06-30 13:55:17 +01:00
parent 5edb57e860
commit 69af99aa9f
2 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -248,7 +248,7 @@ test("preserves user scroll while older channel history loads", async ({
return Math.abs(anchor.top - (anchorBeforeLanding?.top ?? 0));
},
{
timeout: 8_000,
timeout: 10_000,
},
)
.toBeLessThanOrEqual(2);
+11 -3
View File
@@ -28,6 +28,13 @@ async function getTimelineMetrics(page: Page) {
});
}
async function isScrollToLatestVisible(page: Page) {
return page
.getByTestId("message-scroll-to-latest")
.isVisible()
.catch(() => false);
}
async function ensureTimelineScrollable(
senderPage: Page,
receiverPage: Page,
@@ -143,10 +150,12 @@ async function scrollTimelineAwayFromBottom(page: Page, minDistance = 160) {
const timeline = page.getByTestId("message-timeline");
await timeline.hover();
for (let attempt = 0; attempt < 8; attempt += 1) {
for (let attempt = 0; attempt < 12; attempt += 1) {
await page.mouse.wheel(0, -800);
await page.waitForTimeout(100);
const metrics = await getTimelineMetrics(page);
if (metrics.distanceFromBottom > minDistance) {
const scrollToLatestVisible = await isScrollToLatestVisible(page);
if (metrics.distanceFromBottom > minDistance && scrollToLatestVisible) {
// The DOM scroll position is now off the bottom, but the timeline's
// `onScroll` handler updates the React "away from bottom" anchor state
// asynchronously. If a new message lands before that commit, the stale
@@ -154,7 +163,6 @@ async function scrollTimelineAwayFromBottom(page: Page, minDistance = 160) {
// The scroll-to-latest pill only mounts once that state has committed,
// so waiting for it guarantees the anchor is in the away-from-bottom
// branch before callers send the message they expect to be counted.
await expect(page.getByTestId("message-scroll-to-latest")).toBeVisible();
return;
}
}