refactor(font): replace fontLifecycleManager singleton with lazy accessor
Convert the eager fontLifecycleManager singleton to getFontLifecycleManager() (+ __resetFontLifecycleManager for tests), so its AbortController/FontFace bookkeeping is set up on first use rather than at module load. Update consumers (FontVirtualList, FontList, SampleList) and resolve it once as a field in comparisonStore; the comparisonStore mock now exposes getFontLifecycleManager.
This commit is contained in:
@@ -63,6 +63,14 @@ vi.mock('$entities/Font', async importOriginal => {
|
||||
};
|
||||
});
|
||||
|
||||
const mockLifecycle = vi.hoisted(() => ({
|
||||
touch: vi.fn(),
|
||||
pin: vi.fn(),
|
||||
unpin: vi.fn(),
|
||||
getFontStatus: vi.fn(),
|
||||
ready: vi.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
// Stores moved behind the model segment; mock them there. FontsByIdsStore is
|
||||
// intentionally left real (spread from actual) so $state reactivity works.
|
||||
vi.mock('$entities/Font/model', async importOriginal => {
|
||||
@@ -70,13 +78,7 @@ vi.mock('$entities/Font/model', async importOriginal => {
|
||||
return {
|
||||
...actual,
|
||||
getFontCatalog: () => mockFontCatalog,
|
||||
fontLifecycleManager: {
|
||||
touch: vi.fn(),
|
||||
pin: vi.fn(),
|
||||
unpin: vi.fn(),
|
||||
getFontStatus: vi.fn(),
|
||||
ready: vi.fn(() => Promise.resolve()),
|
||||
},
|
||||
getFontLifecycleManager: () => mockLifecycle,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -100,10 +102,7 @@ vi.mock('$features/AdjustTypography/model', () => ({
|
||||
}));
|
||||
|
||||
import * as proxyFonts from '$entities/Font/api/proxy/proxyFonts';
|
||||
import {
|
||||
fontLifecycleManager,
|
||||
getFontCatalog,
|
||||
} from '$entities/Font/model';
|
||||
import { getFontCatalog } from '$entities/Font/model';
|
||||
import { __resetFontCatalog } from '$entities/Font/model/store/fontCatalogStore/fontCatalogStore.svelte';
|
||||
import { ComparisonStore } from './comparisonStore.svelte';
|
||||
|
||||
@@ -273,12 +272,12 @@ describe('ComparisonStore', () => {
|
||||
new ComparisonStore();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(fontLifecycleManager.pin).toHaveBeenCalledWith(
|
||||
expect(mockLifecycle.pin).toHaveBeenCalledWith(
|
||||
mockFontA.id,
|
||||
400,
|
||||
mockFontA.features?.isVariable,
|
||||
);
|
||||
expect(fontLifecycleManager.pin).toHaveBeenCalledWith(
|
||||
expect(mockLifecycle.pin).toHaveBeenCalledWith(
|
||||
mockFontB.id,
|
||||
400,
|
||||
mockFontB.features?.isVariable,
|
||||
@@ -299,12 +298,12 @@ describe('ComparisonStore', () => {
|
||||
store.fontA = mockFontC;
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(fontLifecycleManager.unpin).toHaveBeenCalledWith(
|
||||
expect(mockLifecycle.unpin).toHaveBeenCalledWith(
|
||||
mockFontA.id,
|
||||
400,
|
||||
mockFontA.features?.isVariable,
|
||||
);
|
||||
expect(fontLifecycleManager.pin).toHaveBeenCalledWith(
|
||||
expect(mockLifecycle.pin).toHaveBeenCalledWith(
|
||||
mockFontC.id,
|
||||
400,
|
||||
mockFontC.features?.isVariable,
|
||||
|
||||
Reference in New Issue
Block a user