Skip to content

Commit 2ea6c0e

Browse files
committed
Stabilize loading footer browser test
1 parent 44195f3 commit 2ea6c0e

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

packages/data-table/src/scroll/tests/browser/loading-slots.test.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ async function waitForReady(screen: Awaited<ReturnType<typeof render>>) {
5050
await expect.poll(() => screen.container.querySelector(readySelector)).not.toBeNull()
5151
}
5252

53+
async function waitForScrollable(scroller: HTMLElement) {
54+
await expect.poll(() => scroller.scrollHeight - scroller.clientHeight).toBeGreaterThan(0)
55+
}
56+
5357
describe('loading slots', () => {
5458
test('initial loading placeholder renders before the first dataset resolves and suppresses the empty placeholder', async () => {
5559
const fetch = vi.fn(async (params: AppendFetchParams) => {
@@ -163,13 +167,15 @@ describe('loading slots', () => {
163167
})
164168

165169
test('measured loading footer appears for append fetches and exposes error state', async () => {
170+
const loadMoreRequest = Promise.withResolvers<void>()
166171
const fetch = vi.fn(async (params: AppendFetchParams) => {
167-
await delay(80)
168172
const startIndex = (params.cursor as number | undefined) ?? 0
169173
if (startIndex >= 20) {
174+
await loadMoreRequest.promise
170175
throw new Error('load more failed')
171176
}
172177

178+
await delay(80)
173179
const rows = Array.from({ length: params.limit }, (_, index) => ({
174180
id: startIndex + index,
175181
name: `item-${startIndex + index}`,
@@ -215,11 +221,13 @@ describe('loading slots', () => {
215221
await expect.poll(() => fetch.mock.calls.length).toBe(1)
216222

217223
const scroller = screen.container.querySelector(scrollerSelector) as HTMLElement
224+
await waitForScrollable(scroller)
218225
scroller.scrollTop = 15 * ROW_HEIGHT
219226

227+
await expect.poll(() => fetch.mock.calls.length).toBe(2)
220228
await expect.poll(() => screen.container.querySelector('[data-testid=loading-footer]')?.textContent ?? null).toBe('loading')
221229

222-
await expect.poll(() => fetch.mock.calls.length).toBe(2)
230+
loadMoreRequest.resolve()
223231

224232
await expect.poll(() => screen.container.querySelector('[data-testid=loading-footer]')?.textContent ?? null).toBe('error')
225233

0 commit comments

Comments
 (0)