import { beforeEach, describe, expect, it, vi } from 'vitest' import { createPinia, setActivePinia } from 'pinia' import { useUiStore } from '../app/stores/ui' describe('useUiStore', () => { beforeEach(() => { setActivePinia(createPinia()) vi.restoreAllMocks() }) it('tracks page loading state across nested requests', () => { const store = useUiStore() expect(store.isPageLoading).toBe(false) store.startLoading() store.startLoading() expect(store.isPageLoading).toBe(true) store.stopLoading() expect(store.isPageLoading).toBe(true) store.stopLoading() store.stopLoading() expect(store.isPageLoading).toBe(false) store.setLoading(true) expect(store.isPageLoading).toBe(true) store.setLoading(false) expect(store.isPageLoading).toBe(false) }) it('creates notifications with a default tone and removes them by id', () => { const store = useUiStore() vi.spyOn(crypto, 'randomUUID').mockReturnValue('generated-id') const id = store.pushNotification({ title: 'Saved', message: 'Changes were stored.' }) expect(id).toBe('generated-id') expect(store.notifications).toEqual([ { id: 'generated-id', title: 'Saved', message: 'Changes were stored.', tone: 'info' } ]) store.pushNotification({ id: 'custom-id', title: 'Warning', tone: 'warning' }) expect(store.notifications).toHaveLength(2) store.removeNotification('generated-id') expect(store.notifications.map((notification) => notification.id)).toEqual(['custom-id']) store.clearNotifications() expect(store.notifications).toEqual([]) }) })