mirror of
https://github.com/hectorqin/reader.git
synced 2026-11-13 22:41:06 +08:00
mergePages replaced the accumulated page with the latest chunk, so only the most recent chunk's errors were shown. Merge errors by source and code, as the reader's alternatives panel already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
1.4 KiB
TypeScript
22 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { mergePages } from '../src/features/sources/pages/SourceCatalogPage.tsx';
|
|
|
|
describe('source catalog page helpers', () => {
|
|
it('merges streamed result batches by ref and keeps pagination metadata', () => {
|
|
const first = mergePages(undefined, { items: [{ ref: 'a', title: 'A' }], nextCursor: 'next-1' });
|
|
const second = mergePages(first, { items: [{ ref: 'a', title: 'A updated', latestChapter: '第 2 章' }, { ref: 'b', title: 'B' }], nextCursor: 'next-2', batch: { completed: 2, total: 3 } });
|
|
expect(second.items).toEqual([{ ref: 'a', title: 'A updated', latestChapter: '第 2 章' }, { ref: 'b', title: 'B' }]);
|
|
expect(second.nextCursor).toBe('next-2');
|
|
expect(second.batch?.completed).toBe(2);
|
|
});
|
|
|
|
it('accumulates failures across streamed chunks instead of keeping only the latest', () => {
|
|
const failure = (source: string, code = 'HTTP_ERROR') => ({ source, code, message: `${source} 失败` });
|
|
const first = mergePages(undefined, { items: [], errors: [failure('甲')] });
|
|
const second = mergePages(first, { items: [{ ref: 'a', title: 'A' }] });
|
|
const third = mergePages(second, { items: [], errors: [failure('乙'), failure('甲')] });
|
|
expect(third.errors?.map(error => error.source)).toEqual(['甲', '乙']);
|
|
expect(mergePages(undefined, { items: [] }).errors).toBeUndefined();
|
|
});
|
|
});
|