test(UnifiedFontStore): add isEmpty and destroy tests
This commit is contained in:
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user