From 71fed58af90ac98be64883f76e2c27f028b220e0 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Mon, 6 Apr 2026 12:24:23 +0300 Subject: [PATCH] test(UnifiedFontStore): add category getter tests --- .../unifiedFontStore/unifiedFontStore.test.ts | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts b/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts index 7b59d37..360ae68 100644 --- a/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts +++ b/src/entities/Font/model/store/unifiedFontStore/unifiedFontStore.test.ts @@ -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); + }); +});