Files
kochwas/tests/unit/toast-store.test.ts
hsiegeln 0c66bd677e
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m19s
feat(pwa): Toast-Store + Renderer
Toast-Queue als $state-Store mit Auto-Dismiss nach 3 s und manuellem
dismiss(id). Drei Kinds: info/error/success (Farbe). Renderer als
<Toast /> im Root-Layout, fix-positioniert oben mittig. Wird
vom Offline-Check der Schreib-Aktionen genutzt und später auch für
Sync-Abschluss-Meldungen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 16:21:14 +02:00

36 lines
1.2 KiB
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
describe('toast store', () => {
beforeEach(async () => {
vi.useFakeTimers();
const mod = await import('../../src/lib/client/toast.svelte');
mod.toastStore.toasts = [];
});
it('queues toasts with auto-dismiss', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
toastStore.info('Hello');
expect(toastStore.toasts.length).toBe(1);
expect(toastStore.toasts[0].message).toBe('Hello');
expect(toastStore.toasts[0].kind).toBe('info');
vi.advanceTimersByTime(3000);
expect(toastStore.toasts.length).toBe(0);
});
it('supports error kind and manual dismiss', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
const id = toastStore.error('Boom');
expect(toastStore.toasts[0].kind).toBe('error');
toastStore.dismiss(id);
expect(toastStore.toasts.length).toBe(0);
});
it('allows multiple concurrent toasts', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
toastStore.info('A');
toastStore.info('B');
expect(toastStore.toasts.length).toBe(2);
});
});