fix: reader loads the full chapter list for prev/next and the dropdown
The reader fetched only the first 200 chapters, so a deep chapter (#250) fell outside the window and its prev/next chevrons resolved to null — a dead end — and the chapter dropdown was truncated. Add listAllChapters, which pages through the API's 200-row cap, and use it in the reader loader. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
} from 'vitest';
|
||||
import {
|
||||
listChapters,
|
||||
listAllChapters,
|
||||
getChapter,
|
||||
getChapterPages,
|
||||
createChapter,
|
||||
@@ -142,6 +143,30 @@ describe('chapters api client', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('listAllChapters pages through the 200-row cap and returns every chapter', async () => {
|
||||
const mk = (n: number) => ({ ...chapterFixture, id: `c${n}`, number: n });
|
||||
const first = Array.from({ length: 200 }, (_, i) => mk(i + 1));
|
||||
const second = Array.from({ length: 50 }, (_, i) => mk(i + 201));
|
||||
fetchSpy
|
||||
.mockResolvedValueOnce(ok({ items: first, page: { limit: 200, offset: 0, total: 250 } }))
|
||||
.mockResolvedValueOnce(ok({ items: second, page: { limit: 200, offset: 200, total: 250 } }));
|
||||
|
||||
const all = await listAllChapters('m1');
|
||||
expect(all).toHaveLength(250);
|
||||
expect(all[249].number).toBe(250);
|
||||
expect(fetchSpy.mock.calls[0][0]).toContain('offset=0');
|
||||
expect(fetchSpy.mock.calls[1][0]).toContain('offset=200');
|
||||
});
|
||||
|
||||
it('listAllChapters stops after a short final page (single request)', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(
|
||||
ok({ items: [chapterFixture], page: { limit: 200, offset: 0, total: 1 } })
|
||||
);
|
||||
const all = await listAllChapters('m1');
|
||||
expect(all).toHaveLength(1);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('getChapterPages unwraps the {pages} envelope into the array', async () => {
|
||||
fetchSpy.mockResolvedValueOnce(
|
||||
ok({
|
||||
|
||||
Reference in New Issue
Block a user