From aefcb325368aa1d2a7084dfa9525e2215093e31f Mon Sep 17 00:00:00 2001 From: ZQR1101 <2970159221@qq.com> Date: Wed, 25 Nov 2026 10:20:36 +0800 Subject: [PATCH] test(mobile): cover a refresh racing a page that is still loading The index now lets a refresh abort an in-flight page fetch; this pins that the stale page is discarded rather than appended later. --- apps/mobile/__tests__/session-list.test.tsx | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/mobile/__tests__/session-list.test.tsx b/apps/mobile/__tests__/session-list.test.tsx index 69a2a55cd..194dee85b 100644 --- a/apps/mobile/__tests__/session-list.test.tsx +++ b/apps/mobile/__tests__/session-list.test.tsx @@ -214,3 +214,38 @@ test('a null client never fetches', async () => { expect(list).not.toHaveBeenCalled(); expect(result.current.status).toBe('loading'); }); + +test('a refresh supersedes a page that is still loading', async () => { + let release: (value: SessionPage) => void = () => {}; + const list = jest + .fn() + .mockResolvedValueOnce(page([summary('a')], true)) + .mockImplementationOnce( + () => + new Promise(resolve => { + release = resolve; + }), + ) + .mockResolvedValueOnce(page([summary('fresh')], false)); + const api = fakeApi({ list }); + const { result } = renderHook(() => useSessionList(api)); + + await waitFor(() => expect(result.current.status).toBe('ready')); + await act(async () => { + result.current.loadMore().catch(() => {}); + }); + expect(result.current.loadingMore).toBe(true); + + // Pulling to refresh must not be swallowed by the page in flight. + await act(async () => { + await result.current.refresh(); + }); + expect(result.current.sessions.map(row => row.id)).toEqual(['fresh']); + expect(result.current.loadingMore).toBe(false); + + // The abandoned page lands late and is discarded. + await act(async () => { + release(page([summary('stale')], true)); + }); + expect(result.current.sessions.map(row => row.id)).toEqual(['fresh']); +});