refactor/code-splitting #31

Merged
ilia merged 32 commits from refactor/code-splitting into main 2026-04-08 06:34:20 +00:00
Showing only changes of commit fee3355a65 - Show all commits

View File

@@ -1,4 +1,5 @@
import { QueryClient } from '@tanstack/query-core';
import { tick } from 'svelte';
import {
afterEach,
beforeEach,
@@ -331,3 +332,41 @@ describe('filter setters', () => {
expect(store.params.sort).toBe('popularity');
});
});
describe('filter change resets pagination', () => {
let store: UnifiedFontStore;
beforeEach(async () => {
store = new UnifiedFontStore({ limit: 10 });
// Let the initial effect run so #previousFilterParams is set.
// Without this, the first filter change is treated as initialisation, not a reset.
await tick();
});
afterEach(() => {
store.destroy();
queryClient.clear();
vi.resetAllMocks();
});
it('resets offset to 0 when a filter changes', async () => {
store.setParams({ offset: 20 });
store.setSearch('roboto');
await tick();
expect(store.params.offset).toBe(0);
});
it('clears accumulated fonts when a filter changes', async () => {
const fonts = generateMockFonts(3);
mockedFetch.mockResolvedValue(makeResponse(fonts));
await store.refetch();
expect(store.fonts).toHaveLength(3);
store.setSearch('roboto');
await tick();
expect(store.fonts).toHaveLength(0);
});
});