From 6bf1b1ea87c931825f7698bb74f6573d1ac5b82c Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Mon, 6 Apr 2026 11:34:53 +0300 Subject: [PATCH] test(UnifiedFontStore): add pagination navigation tests --- .../unifiedFontStore/unifiedFontStore.test.ts | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts b/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts index c92f0c5..38c8a4d 100644 --- a/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts +++ b/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts @@ -210,3 +210,73 @@ describe('pagination state', () => { 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); + }); +});