chore: delete unused code

This commit is contained in:
Ilia Mashkov
2026-01-13 19:56:20 +03:00
parent 4c9b9f631f
commit 4810c2b228
10 changed files with 0 additions and 1297 deletions

View File

@@ -1,41 +0,0 @@
import { vi } from 'vitest';
import type { UnifiedFont } from '../types/normalize';
export function createMockStore() {
let fonts = $state<UnifiedFont[]>([]);
let isLoading = $state(false);
let isFetching = $state(false);
let error = $state<string | null>(null);
return {
get fonts() {
console.log('MockStore: get fonts', fonts.length);
return fonts;
},
set fonts(v) {
console.log('MockStore: set fonts', v.length);
fonts = v;
},
get isLoading() {
return isLoading;
},
set isLoading(v) {
isLoading = v;
},
get isFetching() {
return isFetching;
},
set isFetching(v) {
isFetching = v;
},
get error() {
return error;
},
set error(v) {
error = v;
},
setParams: vi.fn(),
clearCache: vi.fn(),
cancel: vi.fn(),
};
}

View File

@@ -1,202 +0,0 @@
/**
* Unit tests for unified font store
*/
import type {
FontCategory,
FontProvider,
} from '$entities/Font/model/types/common';
import type { UnifiedFont } from '$entities/Font/model/types/normalize';
import {
beforeEach,
describe,
expect,
it,
vi,
} from 'vitest';
// Import reactive mock factory
import { tick } from 'svelte';
import { createMockStore } from './mocks.svelte';
// Mock the service stores BEFORE importing the unified store
// We use the reactive mock factory
const mockGoogleFonts = createMockStore();
const mockFontshareFonts = createMockStore();
vi.mock('../../services/fetchGoogleFonts.svelte', () => ({
createGoogleFontsStore: () => mockGoogleFonts,
}));
vi.mock('../../services/fetchFontshareFonts.svelte', () => ({
createFontshareStore: () => mockFontshareFonts,
}));
// Import store after mocking
// Import factory and type
import {
type UnifiedFontStore,
createUnifiedFontStore,
} from '../unifiedFontStore.svelte';
// Mock UnifiedFont for testing
const mockFont = (
id: string,
name: string,
provider: FontProvider,
category: FontCategory,
): UnifiedFont => ({
id,
name,
provider,
category,
subsets: ['latin'],
variants: ['regular'],
styles: {
regular: 'https://example.com/font.woff2',
},
metadata: {
cachedAt: Date.now(),
popularity: 100,
},
features: {
isVariable: false,
},
});
describe('Unified Font Store', () => {
let unifiedFontStore: UnifiedFontStore;
beforeEach(() => {
// Reset mock data
mockGoogleFonts.fonts = [];
mockFontshareFonts.fonts = [];
mockGoogleFonts.isLoading = false;
mockFontshareFonts.isLoading = false;
mockGoogleFonts.error = null;
mockFontshareFonts.error = null;
// Create fresh store instance
unifiedFontStore = createUnifiedFontStore();
unifiedFontStore.clearFilters();
vi.clearAllMocks();
// Reset mock data
mockGoogleFonts.fonts = [];
mockFontshareFonts.fonts = [];
mockGoogleFonts.isLoading = false;
mockFontshareFonts.isLoading = false;
mockGoogleFonts.error = null;
mockFontshareFonts.error = null;
});
describe('Debug Identity', () => {
it('uses the correct mock instance', () => {
// @ts-ignore
expect(unifiedFontStore.providers.google).toBe(mockGoogleFonts);
});
});
describe('Aggregation', () => {
it('aggregates fonts from both providers', async () => {
const googleFont = mockFont('g1', 'Google Font', 'google', 'sans-serif');
const fontshareFont = mockFont('f1', 'Fontshare Font', 'fontshare', 'serif');
mockGoogleFonts.fonts = [googleFont];
mockFontshareFonts.fonts = [fontshareFont];
// Wait for reactivity (Svelte 5 updates are batched)
await tick();
// Trigger reactivity updates if needed (Store getters compute on access)
expect(unifiedFontStore.count).toBe(2);
expect(unifiedFontStore.fonts).toContain(googleFont);
expect(unifiedFontStore.fonts).toContain(fontshareFont);
});
it('handles empty states', () => {
expect(unifiedFontStore.count).toBe(0);
});
it('aggregates loading state', async () => {
mockGoogleFonts.isLoading = true;
await tick();
expect(unifiedFontStore.isLoading).toBe(true);
mockGoogleFonts.isLoading = false;
mockFontshareFonts.isLoading = true;
await tick();
expect(unifiedFontStore.isLoading).toBe(true);
mockFontshareFonts.isLoading = false;
await tick();
expect(unifiedFontStore.isLoading).toBe(false);
});
});
describe('Filter Management', () => {
it('sets and applies provider filter', async () => {
const googleFont = mockFont('g1', 'Google Font', 'google', 'sans-serif');
const fontshareFont = mockFont('f1', 'Fontshare Font', 'fontshare', 'serif');
mockGoogleFonts.fonts = [googleFont];
mockFontshareFonts.fonts = [fontshareFont];
await tick();
// Filter to Google only
unifiedFontStore.setFilter('providers', ['google']);
expect(unifiedFontStore.filteredFonts.length).toBe(1);
expect(unifiedFontStore.filteredFonts[0].id).toBe('g1');
// Filter to Fontshare only
unifiedFontStore.setFilter('providers', ['fontshare']);
expect(unifiedFontStore.filteredFonts.length).toBe(1);
expect(unifiedFontStore.filteredFonts[0].id).toBe('f1');
});
it('sets search query and filters', async () => {
const font1 = mockFont('1', 'Roboto', 'google', 'sans-serif');
const font2 = mockFont('2', 'Open Sans', 'google', 'sans-serif');
mockGoogleFonts.fonts = [font1, font2];
await tick();
unifiedFontStore.searchQuery = 'Robo';
expect(unifiedFontStore.filteredFonts.length).toBe(1);
expect(unifiedFontStore.filteredFonts[0].name).toBe('Roboto');
});
it('clears all filters', () => {
unifiedFontStore.setFilter('providers', ['google']);
unifiedFontStore.searchQuery = 'Test';
unifiedFontStore.clearFilters();
expect(unifiedFontStore.filters.providers).toEqual([]);
expect(unifiedFontStore.searchQuery).toBe('');
});
});
describe('Interaction with Services', () => {
it('fetchFonts calls setParams on underlying stores', async () => {
await unifiedFontStore.fetchFonts({
search: 'test',
categories: ['serif'],
});
expect(mockGoogleFonts.setParams).toHaveBeenCalledWith(expect.objectContaining({
category: 'serif',
}));
// Verify local state update as well
expect(unifiedFontStore.searchQuery).toBe('test');
});
it('clearCache calls clearCache on underlying stores', () => {
unifiedFontStore.clearCache();
expect(mockGoogleFonts.clearCache).toHaveBeenCalled();
expect(mockFontshareFonts.clearCache).toHaveBeenCalled();
});
});
});

View File

@@ -1,3 +0,0 @@
import { createFontCollection } from '../../lib';
export const fontCollection = createFontCollection();