test(UnifiedFontStore): add category getter tests
This commit is contained in:
@@ -31,7 +31,10 @@ vi.mock('../../../api', () => ({
|
||||
import { queryClient } from '$shared/api/queryClient';
|
||||
import { flushSync } from 'svelte';
|
||||
import { fetchProxyFonts } from '../../../api';
|
||||
import { generateMockFonts } from '../../../lib/mocks/fonts.mock';
|
||||
import {
|
||||
generateMixedCategoryFonts,
|
||||
generateMockFonts,
|
||||
} from '../../../lib/mocks/fonts.mock';
|
||||
import type { UnifiedFont } from '../../types';
|
||||
import { UnifiedFontStore } from './unifiedFontStore.svelte';
|
||||
|
||||
@@ -370,3 +373,63 @@ describe('filter change resets pagination', () => {
|
||||
expect(store.fonts).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('category getters', () => {
|
||||
let store: UnifiedFontStore;
|
||||
|
||||
beforeEach(() => {
|
||||
store = new UnifiedFontStore({ limit: 10 });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
store.destroy();
|
||||
queryClient.clear();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('sansSerifFonts returns only sans-serif fonts', async () => {
|
||||
const fonts = generateMixedCategoryFonts(2);
|
||||
mockedFetch.mockResolvedValue(makeResponse(fonts, { total: fonts.length, limit: fonts.length }));
|
||||
await store.refetch();
|
||||
|
||||
expect(store.fonts).toHaveLength(10);
|
||||
expect(store.sansSerifFonts).toHaveLength(2);
|
||||
expect(store.sansSerifFonts.every(f => f.category === 'sans-serif')).toBe(true);
|
||||
});
|
||||
|
||||
it('serifFonts returns only serif fonts', async () => {
|
||||
const fonts = generateMixedCategoryFonts(2);
|
||||
mockedFetch.mockResolvedValue(makeResponse(fonts, { total: fonts.length, limit: fonts.length }));
|
||||
await store.refetch();
|
||||
|
||||
expect(store.serifFonts).toHaveLength(2);
|
||||
expect(store.serifFonts.every(f => f.category === 'serif')).toBe(true);
|
||||
});
|
||||
|
||||
it('displayFonts returns only display fonts', async () => {
|
||||
const fonts = generateMixedCategoryFonts(2);
|
||||
mockedFetch.mockResolvedValue(makeResponse(fonts, { total: fonts.length, limit: fonts.length }));
|
||||
await store.refetch();
|
||||
|
||||
expect(store.displayFonts).toHaveLength(2);
|
||||
expect(store.displayFonts.every(f => f.category === 'display')).toBe(true);
|
||||
});
|
||||
|
||||
it('handwritingFonts returns only handwriting fonts', async () => {
|
||||
const fonts = generateMixedCategoryFonts(2);
|
||||
mockedFetch.mockResolvedValue(makeResponse(fonts, { total: fonts.length, limit: fonts.length }));
|
||||
await store.refetch();
|
||||
|
||||
expect(store.handwritingFonts).toHaveLength(2);
|
||||
expect(store.handwritingFonts.every(f => f.category === 'handwriting')).toBe(true);
|
||||
});
|
||||
|
||||
it('monospaceFonts returns only monospace fonts', async () => {
|
||||
const fonts = generateMixedCategoryFonts(2);
|
||||
mockedFetch.mockResolvedValue(makeResponse(fonts, { total: fonts.length, limit: fonts.length }));
|
||||
await store.refetch();
|
||||
|
||||
expect(store.monospaceFonts).toHaveLength(2);
|
||||
expect(store.monospaceFonts.every(f => f.category === 'monospace')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user