test(UnifiedFontStore): add isEmpty and destroy tests

This commit is contained in:
Ilia Mashkov
2026-04-06 12:26:08 +03:00
parent 71fed58af9
commit 9c538069e4

View File

@@ -433,3 +433,58 @@ describe('category getters', () => {
expect(store.monospaceFonts.every(f => f.category === 'monospace')).toBe(true); expect(store.monospaceFonts.every(f => f.category === 'monospace')).toBe(true);
}); });
}); });
describe('isEmpty', () => {
let store: UnifiedFontStore;
beforeEach(() => {
store = new UnifiedFontStore({ limit: 10 });
});
afterEach(() => {
store.destroy();
queryClient.clear();
vi.resetAllMocks();
});
it('is true when fetch returns no fonts', async () => {
mockedFetch.mockResolvedValue(makeResponse([]));
await store.refetch();
expect(store.isEmpty).toBe(true);
});
it('is false when fonts are present', async () => {
mockedFetch.mockResolvedValue(makeResponse(generateMockFonts(3)));
await store.refetch();
expect(store.isEmpty).toBe(false);
});
it('is true after an error (no fonts loaded)', async () => {
mockedFetch.mockRejectedValue(new Error('network down'));
await store.refetch().catch((e: unknown) => e);
expect(store.isEmpty).toBe(true);
});
});
describe('destroy', () => {
it('can be called without throwing', () => {
const store = new UnifiedFontStore({ limit: 10 });
expect(() => {
store.destroy();
}).not.toThrow();
});
it('sets filterCleanup to null so it is not called again', () => {
const store = new UnifiedFontStore({ limit: 10 });
store.destroy();
// Second destroy should not throw even though filterCleanup is now null
expect(() => {
store.destroy();
}).not.toThrow();
});
});