import { describe, expect, it } from 'vitest' import { dismissToast, initialToasts, pushToast, TOAST_LIMIT } from '../src/toast-store' describe('toast store', () => { it('pushes with increasing ids', () => { let s = pushToast(initialToasts, 'ok', 'saved') s = pushToast(s, 'err', 'failed') expect(s.toasts.map((t) => t.id)).toEqual([1, 2]) expect(s.toasts[1]).toMatchObject({ tone: 'err', message: 'failed' }) }) it('keeps only the newest TOAST_LIMIT toasts', () => { let s = initialToasts for (let i = 0; i < TOAST_LIMIT + 2; i++) s = pushToast(s, 'ok', `m${i}`) expect(s.toasts).toHaveLength(TOAST_LIMIT) expect(s.toasts[0]!.message).toBe('m2') }) it('dismisses by id and ignores unknown ids', () => { let s = pushToast(initialToasts, 'ok', 'a') s = pushToast(s, 'ok', 'b') s = dismissToast(s, 1) expect(s.toasts.map((t) => t.message)).toEqual(['b']) expect(dismissToast(s, 99).toasts).toHaveLength(1) }) })