All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
Spiegelt SW-Messages (sync-start/progress/done/error) in einen Svelte-State. lastSynced wird in localStorage persistiert, damit der User nach einem Reload sieht, wann zuletzt synchronisiert wurde. Wird vom SyncIndicator und der Admin-App-Tab konsumiert. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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' });
|
|
});
|
|
});
|