Skip to content

Commit 8674954

Browse files
author
Brain
committed
test(desktop): settle startup before steady-state scroll probes
Signed-off-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
1 parent 48e9c0d commit 8674954

1 file changed

Lines changed: 98 additions & 59 deletions

File tree

‎desktop/tests/e2e/scroll-history.spec.ts‎

Lines changed: 98 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,79 @@ async function getTimelineMetrics(page: import("@playwright/test").Page) {
2121
});
2222
}
2323

24+
// These default mock fixtures have immediate EOSE and no injected reconnect.
25+
// Steady-state pagination begins after live admission and its head refresh,
26+
// which can replace paged tails. This does not test early startup scrolling.
27+
async function waitForMockChannelHeadReady(
28+
page: import("@playwright/test").Page,
29+
channelName: string,
30+
channelId: string,
31+
) {
32+
await page.waitForFunction(
33+
({ channelId, channelName }) => {
34+
if (
35+
!window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
36+
channelName,
37+
kind: 39005,
38+
})
39+
) {
40+
return false;
41+
}
42+
const commands = window.__BUZZ_E2E_COMMAND_PAYLOADS__ ?? [];
43+
const liveIndex = commands.findIndex(({ command, payload }) => {
44+
if (command !== "plugin:websocket|send") return false;
45+
const message = (
46+
payload as { message?: { type: string; data: string } }
47+
)?.message;
48+
if (message?.type !== "Text") return false;
49+
const [type, id, ...filters] = JSON.parse(message.data);
50+
return (
51+
type === "REQ" &&
52+
id.startsWith("live-") &&
53+
filters.some(
54+
(filter: { kinds?: number[]; "#h"?: string[] }) =>
55+
filter.kinds?.includes(39005) &&
56+
filter["#h"]?.includes(channelId),
57+
)
58+
);
59+
});
60+
const refreshed = commands
61+
.slice(liveIndex + 1)
62+
.some(({ command, payload }) => {
63+
const args = payload as {
64+
channelId?: string;
65+
cursor?: unknown;
66+
} | null;
67+
return (
68+
command === "get_channel_window" &&
69+
args?.channelId === channelId &&
70+
args.cursor === null
71+
);
72+
});
73+
const state = window.__BUZZ_E2E_QUERY_CLIENT__?.getQueryState([
74+
"channel-messages",
75+
channelId,
76+
]);
77+
return (
78+
liveIndex >= 0 &&
79+
refreshed &&
80+
state?.status === "success" &&
81+
state.fetchStatus === "idle"
82+
);
83+
},
84+
{ channelId, channelName },
85+
);
86+
const timeline = page.getByTestId("message-timeline");
87+
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
88+
await expect
89+
.poll(async () => {
90+
const { scrollHeight, scrollTop, clientHeight } =
91+
await getTimelineMetrics(page);
92+
return scrollHeight - scrollTop - clientHeight;
93+
})
94+
.toBeLessThanOrEqual(2);
95+
}
96+
2497
async function getFirstVisibleMessage(page: import("@playwright/test").Page) {
2598
return page.getByTestId("message-timeline").evaluate((element) => {
2699
const timeline = element as HTMLDivElement;
@@ -188,66 +261,12 @@ test("preserves user scroll while older channel history loads", async ({
188261
await page.getByTestId("channel-deep-history").click();
189262
await expect(page.getByTestId("chat-title")).toHaveText("deep-history");
190263

191-
// This tests steady-state prepending, not early scrolling during startup.
192-
// Admission precedes EOSE and the hook's post-subscribe head refresh, which
193-
// replaces paged tails. Observe that refresh through the existing IPC journal
194-
// and query state before collecting the baseline; admission alone can race it.
195-
await page.waitForFunction(() => {
196-
const channelId = "feedf00d-0000-4000-8000-000000000007";
197-
if (
198-
!window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
199-
channelName: "deep-history",
200-
kind: 39005,
201-
})
202-
) {
203-
return false;
204-
}
205-
const commands = window.__BUZZ_E2E_COMMAND_PAYLOADS__ ?? [];
206-
const liveIndex = commands.findIndex(({ command, payload }) => {
207-
if (command !== "plugin:websocket|send") return false;
208-
const message = (payload as { message?: { type: string; data: string } })
209-
?.message;
210-
if (message?.type !== "Text") return false;
211-
const [type, id, ...filters] = JSON.parse(message.data);
212-
return (
213-
type === "REQ" &&
214-
id.startsWith("live-") &&
215-
filters.some(
216-
(filter: { kinds?: number[]; "#h"?: string[] }) =>
217-
filter.kinds?.includes(39005) && filter["#h"]?.includes(channelId),
218-
)
219-
);
220-
});
221-
const refreshed = commands
222-
.slice(liveIndex + 1)
223-
.some(({ command, payload }) => {
224-
const args = payload as { channelId?: string; cursor?: unknown } | null;
225-
return (
226-
command === "get_channel_window" &&
227-
args?.channelId === channelId &&
228-
args.cursor === null
229-
);
230-
});
231-
const state = window.__BUZZ_E2E_QUERY_CLIENT__?.getQueryState([
232-
"channel-messages",
233-
channelId,
234-
]);
235-
return (
236-
liveIndex >= 0 &&
237-
refreshed &&
238-
state?.status === "success" &&
239-
state.fetchStatus === "idle"
240-
);
241-
});
264+
await waitForMockChannelHeadReady(
265+
page,
266+
"deep-history",
267+
"feedf00d-0000-4000-8000-000000000007",
268+
);
242269
const timeline = page.getByTestId("message-timeline");
243-
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
244-
await expect
245-
.poll(async () => {
246-
const { scrollHeight, scrollTop, clientHeight } =
247-
await getTimelineMetrics(page);
248-
return scrollHeight - scrollTop - clientHeight;
249-
})
250-
.toBeLessThanOrEqual(2);
251270
await page.waitForFunction(() => {
252271
const element = document.querySelector(
253272
'[data-testid="message-timeline"]',
@@ -1709,6 +1728,11 @@ test("channel intro stays hidden while paginating past the timeline cap", async
17091728

17101729
await page.getByTestId("channel-general").click();
17111730
await expect(page.getByTestId("chat-title")).toHaveText("general");
1731+
await waitForMockChannelHeadReady(
1732+
page,
1733+
"general",
1734+
"9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
1735+
);
17121736
const timeline = page.getByTestId("message-timeline");
17131737
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
17141738

@@ -1846,6 +1870,11 @@ test("older-history fetches never overlap (no concurrent in-flight requests)", a
18461870

18471871
await page.getByTestId("channel-general").click();
18481872
await expect(page.getByTestId("chat-title")).toHaveText("general");
1873+
await waitForMockChannelHeadReady(
1874+
page,
1875+
"general",
1876+
"9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
1877+
);
18491878
const timeline = page.getByTestId("message-timeline");
18501879
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
18511880

@@ -1909,6 +1938,11 @@ test("older-history spinner stays visible in viewport while fetching mid-scroll"
19091938

19101939
await page.getByTestId("channel-general").click();
19111940
await expect(page.getByTestId("chat-title")).toHaveText("general");
1941+
await waitForMockChannelHeadReady(
1942+
page,
1943+
"general",
1944+
"9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
1945+
);
19121946
const timeline = page.getByTestId("message-timeline");
19131947
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
19141948

@@ -2085,6 +2119,11 @@ test("older-history prepend keeps the reading row fixed (no jump to oldest)", as
20852119

20862120
await page.getByTestId("channel-general").click();
20872121
await expect(page.getByTestId("chat-title")).toHaveText("general");
2122+
await waitForMockChannelHeadReady(
2123+
page,
2124+
"general",
2125+
"9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50",
2126+
);
20882127
const timeline = page.getByTestId("message-timeline");
20892128
await expect(timeline.locator("[data-message-id]").first()).toBeVisible();
20902129
await page.waitForFunction(() => {

0 commit comments

Comments
 (0)