test(UnifiedFontStore): add pagination navigation tests

This commit is contained in:
Ilia Mashkov
2026-04-06 11:34:53 +03:00
parent 3ef012eb43
commit 6bf1b1ea87

View File

@@ -210,3 +210,73 @@ describe('pagination state', () => {
expect(store.pagination.totalPages).toBe(3); expect(store.pagination.totalPages).toBe(3);
}); });
}); });
describe('pagination navigation', () => {
let store: UnifiedFontStore;
beforeEach(async () => {
store = new UnifiedFontStore({ limit: 10 });
mockedFetch.mockResolvedValue(makeResponse(generateMockFonts(10), { total: 30, limit: 10, offset: 0 }));
await store.refetch();
});
afterEach(() => {
store.destroy();
queryClient.clear();
vi.resetAllMocks();
});
it('nextPage() advances offset by limit when hasMore', () => {
store.nextPage();
expect(store.params.offset).toBe(10);
});
it('nextPage() does nothing when hasMore is false', async () => {
mockedFetch.mockResolvedValue(makeResponse(generateMockFonts(10), { total: 20, limit: 10, offset: 10 }));
store.setParams({ offset: 10 });
await store.refetch();
store.nextPage();
expect(store.params.offset).toBe(10);
});
it('prevPage() decrements offset by limit when on page > 1', () => {
store.setParams({ offset: 10 });
store.prevPage();
expect(store.params.offset).toBe(0);
});
it('prevPage() does nothing on the first page', () => {
store.prevPage();
expect(store.params.offset).toBe(0);
});
it('goToPage() sets the correct offset', () => {
store.goToPage(2);
expect(store.params.offset).toBe(10);
});
it('goToPage() does nothing for page 0', () => {
store.goToPage(0);
expect(store.params.offset).toBe(0);
});
it('goToPage() does nothing for page beyond totalPages', () => {
store.goToPage(99);
expect(store.params.offset).toBe(0);
});
it('setLimit() updates the limit param', () => {
store.setLimit(25);
expect(store.params.limit).toBe(25);
});
});