feat(pwa): Toast-Store + Renderer
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m19s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m19s
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>
This commit is contained in:
35
tests/unit/toast-store.test.ts
Normal file
35
tests/unit/toast-store.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user