mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
fix(admin): a failed "Load more" in the desktop release history keeps the list and can be retried
On the desktop admin GitHub panel, when "Load more" failed (for example GitHub rate limiting), the whole release history was replaced by the error card for the rest of the session: no list, no Load more button, no way to retry. Had the user found a way to load again, the next load would also have skipped the page that failed. Cause: in its one page per load mode useGithubReleases advanced the page counter whether the request worked or not and never cleared the error, and GitHubPanel showed the error card whenever an error was set. The phone (fillPages mode) already held the page, cleared the error on the next good load and drew the error inline under its timeline. Fix: the one page mode now moves the page on only after a good load and clears the error then, like fillPages. GitHubPanel shows the error card only when nothing has loaded yet; after that it keeps the timeline, shows the error as a line above Load more and leaves the button there. The page walk difference behind fillPages stays as it was. Red tests: - FE-COMP-GHREL-HOOK-012 (new, useGithubReleases.test.ts) failed with "AssertionError: expected [ 1, 2, 3 ] to deeply equal [ 1, 2, 2 ]". - FE-ADMIN-GH-017 (new, GitHubPanel.test.tsx) failed with "Unable to find an element with the text: /v1\.\d\.0/" after the failed load. Changed assertions in src/components/Admin/useGithubReleases.test.ts: - FE-COMP-GHREL-HOOK-004 (renamed from "sets the error and still moves the page on" to "sets the error and holds the page"): requested pages were [1, 2, 3], now [1, 2, 2].
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-COMP-GHREL-HOOK-001 to -011: the release history behind both admin shells.
|
||||
// FE-COMP-GHREL-HOOK-001 to -012: the release history behind both admin shells.
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
|
||||
import apiClient from '../../api/client';
|
||||
@@ -76,7 +76,7 @@ describe('useGithubReleases, one page per load', () => {
|
||||
expect(result.current.loadingMore).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-COMP-GHREL-HOOK-004: a failed load more sets the error and still moves the page on', async () => {
|
||||
it('FE-COMP-GHREL-HOOK-004: a failed load more sets the error and holds the page', async () => {
|
||||
const spy = serve({ 1: fullPage(1), 2: new Error('rate limited'), 3: [release(21)] });
|
||||
const { result } = renderHook(() => useGithubReleases({ isPrerelease: false }));
|
||||
await waitFor(() => expect(result.current.loading).toBe(false));
|
||||
@@ -87,10 +87,37 @@ describe('useGithubReleases, one page per load', () => {
|
||||
await act(async () => {
|
||||
await result.current.handleLoadMore();
|
||||
});
|
||||
expect(requestedPages(spy)).toEqual([1, 2, 3]);
|
||||
expect(requestedPages(spy)).toEqual([1, 2, 2]);
|
||||
expect(result.current.error).toBe('rate limited');
|
||||
});
|
||||
|
||||
it('FE-COMP-GHREL-HOOK-012: a failed load more keeps the list and the retry clears the error', async () => {
|
||||
let failPage2 = true;
|
||||
const spy = vi
|
||||
.spyOn(apiClient, 'get')
|
||||
.mockImplementation(async (_url: string, config?: { params?: { page?: number } }) => {
|
||||
const page = config?.params?.page;
|
||||
if (page === 1) return { data: fullPage(1) };
|
||||
if (failPage2) throw new Error('offline');
|
||||
return { data: [release(11)] };
|
||||
});
|
||||
const { result } = renderHook(() => useGithubReleases({ isPrerelease: false }));
|
||||
await waitFor(() => expect(result.current.loading).toBe(false));
|
||||
await act(async () => {
|
||||
await result.current.handleLoadMore();
|
||||
});
|
||||
expect(result.current.error).toBe('offline');
|
||||
expect(result.current.releases).toHaveLength(10);
|
||||
failPage2 = false;
|
||||
await act(async () => {
|
||||
await result.current.handleLoadMore();
|
||||
});
|
||||
expect(requestedPages(spy)).toEqual([1, 2, 2]);
|
||||
expect(result.current.error).toBeNull();
|
||||
expect(result.current.releases).toHaveLength(11);
|
||||
expect(result.current.hasMore).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-COMP-GHREL-HOOK-005: a first page of only prereleases is all a stable install gets', async () => {
|
||||
const spy = serve({ 1: fullPage(1, true), 2: [release(11)] });
|
||||
const { result } = renderHook(() => useGithubReleases({ isPrerelease: false }));
|
||||
|
||||
Reference in New Issue
Block a user