refactor: replace unifiedFontStore with fontStore in comparisonStore tests
All checks were successful
Workflow / build (pull_request) Successful in 1m1s
Workflow / publish (pull_request) Has been skipped

This commit is contained in:
Ilia Mashkov
2026-04-10 08:06:51 +03:00
parent dc6e15492a
commit 14dbd374ec

View File

@@ -4,7 +4,7 @@
* Tests the font comparison store functionality including: * Tests the font comparison store functionality including:
* - Font loading via CSS Font Loading API * - Font loading via CSS Font Loading API
* - Storage synchronization when fonts change * - Storage synchronization when fonts change
* - Default values from unifiedFontStore * - Default values from fontStore
* - Reset functionality * - Reset functionality
* - isReady computed state * - isReady computed state
*/ */
@@ -25,7 +25,6 @@ import {
// Mock all dependencies // Mock all dependencies
vi.mock('$entities/Font', () => ({ vi.mock('$entities/Font', () => ({
fetchFontsByIds: vi.fn(), fetchFontsByIds: vi.fn(),
unifiedFontStore: { fonts: [] },
fontStore: { fonts: [] }, fontStore: { fonts: [] },
})); }));
@@ -120,7 +119,7 @@ vi.mock('$shared/lib/helpers/createPersistentStore/createPersistentStore.svelte'
// Import after mocks // Import after mocks
import { import {
fetchFontsByIds, fetchFontsByIds,
unifiedFontStore, fontStore,
} from '$entities/Font'; } from '$entities/Font';
import { createTypographyControlManager } from '$features/SetupFont'; import { createTypographyControlManager } from '$features/SetupFont';
import { ComparisonStore } from './comparisonStore.svelte'; import { ComparisonStore } from './comparisonStore.svelte';
@@ -151,8 +150,8 @@ describe('ComparisonStore', () => {
}; };
mockStorage._clear.mockClear(); mockStorage._clear.mockClear();
// Setup mock unifiedFontStore // Setup mock fontStore
(unifiedFontStore as any).fonts = []; (fontStore as any).fonts = [];
// Setup mock fetchFontsByIds // Setup mock fetchFontsByIds
vi.mocked(fetchFontsByIds).mockResolvedValue([]); vi.mocked(fetchFontsByIds).mockResolvedValue([]);
@@ -302,8 +301,8 @@ describe('ComparisonStore', () => {
}); });
it('should handle partial restoration when only one font is found', async () => { it('should handle partial restoration when only one font is found', async () => {
// Ensure unifiedFontStore is empty so $effect doesn't interfere // Ensure fontStore is empty so $effect doesn't interfere
(unifiedFontStore as any).fonts = []; (fontStore as any).fonts = [];
mockStorage._value.fontAId = mockFontA.id; mockStorage._value.fontAId = mockFontA.id;
mockStorage._value.fontBId = mockFontB.id; mockStorage._value.fontBId = mockFontB.id;
@@ -331,7 +330,7 @@ describe('ComparisonStore', () => {
describe('Font Loading with CSS Font Loading API', () => { describe('Font Loading with CSS Font Loading API', () => {
it('should construct correct font strings for checking', async () => { it('should construct correct font strings for checking', async () => {
mockFontFaceSet.check.mockReturnValue(false); mockFontFaceSet.check.mockReturnValue(false);
(unifiedFontStore as any).fonts = [mockFontA, mockFontB]; (fontStore as any).fonts = [mockFontA, mockFontB];
vi.mocked(fetchFontsByIds).mockResolvedValue([mockFontA, mockFontB]); vi.mocked(fetchFontsByIds).mockResolvedValue([mockFontA, mockFontB]);
const store = new ComparisonStore(); const store = new ComparisonStore();
@@ -368,7 +367,7 @@ describe('ComparisonStore', () => {
// Mock load to fail // Mock load to fail
mockFontFaceSet.load.mockRejectedValue(new Error('Font load failed')); mockFontFaceSet.load.mockRejectedValue(new Error('Font load failed'));
(unifiedFontStore as any).fonts = [mockFontA, mockFontB]; (fontStore as any).fonts = [mockFontA, mockFontB];
vi.mocked(fetchFontsByIds).mockResolvedValue([mockFontA, mockFontB]); vi.mocked(fetchFontsByIds).mockResolvedValue([mockFontA, mockFontB]);
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
@@ -385,11 +384,11 @@ describe('ComparisonStore', () => {
}); });
}); });
describe('Default Values from unifiedFontStore', () => { describe('Default Values from fontStore', () => {
it('should set default fonts from unifiedFontStore when available', () => { it('should set default fonts from fontStore when available', () => {
// Note: This test relies on Svelte 5's $effect which may not work // Note: This test relies on Svelte 5's $effect which may not work
// reliably in the test environment. We test the logic path instead. // reliably in the test environment. We test the logic path instead.
(unifiedFontStore as any).fonts = [mockFontA, mockFontB]; (fontStore as any).fonts = [mockFontA, mockFontB];
const store = new ComparisonStore(); const store = new ComparisonStore();
@@ -403,9 +402,9 @@ describe('ComparisonStore', () => {
expect(store.fontB).toBeDefined(); expect(store.fontB).toBeDefined();
}); });
it('should use first and last font from unifiedFontStore as defaults', () => { it('should use first and last font from fontStore as defaults', () => {
const mockFontC = UNIFIED_FONTS.lato; const mockFontC = UNIFIED_FONTS.lato;
(unifiedFontStore as any).fonts = [mockFontA, mockFontC, mockFontB]; (fontStore as any).fonts = [mockFontA, mockFontC, mockFontB];
const store = new ComparisonStore(); const store = new ComparisonStore();