31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
|
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||
|
|
|
||
|
|
describe('sync-status store', () => {
|
||
|
|
beforeEach(async () => {
|
||
|
|
const mod = await import('../../src/lib/client/sync-status.svelte');
|
||
|
|
mod.syncStatus.state = { kind: 'idle' };
|
||
|
|
mod.syncStatus.lastSynced = null;
|
||
|
|
});
|
||
|
|
|
||
|
|
it('processes progress messages', async () => {
|
||
|
|
const { syncStatus } = await import('../../src/lib/client/sync-status.svelte');
|
||
|
|
syncStatus.handle({ type: 'sync-progress', current: 3, total: 10 });
|
||
|
|
expect(syncStatus.state).toEqual({ kind: 'syncing', current: 3, total: 10 });
|
||
|
|
});
|
||
|
|
|
||
|
|
it('transitions to idle on sync-done and records timestamp', async () => {
|
||
|
|
const { syncStatus } = await import('../../src/lib/client/sync-status.svelte');
|
||
|
|
syncStatus.handle({ type: 'sync-start', total: 5 });
|
||
|
|
expect(syncStatus.state.kind).toBe('syncing');
|
||
|
|
syncStatus.handle({ type: 'sync-done', lastSynced: 1700000000000 });
|
||
|
|
expect(syncStatus.state).toEqual({ kind: 'idle' });
|
||
|
|
expect(syncStatus.lastSynced).toBe(1700000000000);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('sets error state on sync-error', async () => {
|
||
|
|
const { syncStatus } = await import('../../src/lib/client/sync-status.svelte');
|
||
|
|
syncStatus.handle({ type: 'sync-error', message: 'Quota exceeded' });
|
||
|
|
expect(syncStatus.state).toEqual({ kind: 'error', message: 'Quota exceeded' });
|
||
|
|
});
|
||
|
|
});
|