import { describe, it, expect, vi, beforeEach } from 'vitest' import { setActivePinia, createPinia } from 'pinia' import { useAlertQualityStore } from './alertQuality' vi.mock('@/api/alertQuality', () => ({ submitAlertFeedback: vi.fn().mockResolvedValue({ id: 'fb-1', createdAt: '2026-06-23T00:00:00Z' }), fetchQualityMetricsSummary: vi.fn().mockResolvedValue({ totalAlerts: 10, totalFeedback: 4, acknowledgementRate: 0.8, usefulRate: 0.75, falsePositiveRate: 0.1, wouldActRate: 0.6, avgSecondsToAcknowledge: 300, avgSecondsToResolution: 1200, }), fetchQualityMetrics: vi.fn().mockResolvedValue({ items: [{ alertType: 'News2Warning', usefulRate: 0.75, falsePositiveRate: 0.1, acknowledgementRate: 0.8, totalAlerts: 5 }], }), FEEDBACK_TYPE_MAP: { useful: 'Useful' }, })) describe('alertQuality store', () => { beforeEach(() => { setActivePinia(createPinia()) }) it('loads dashboard summary and snapshots', async () => { const store = useAlertQualityStore() await store.loadDashboard() expect(store.summaryStats.totalAlerts).toBe(10) expect(store.summaryStats.usefulRate).toBe(75) expect(store.snapshots).toHaveLength(1) }) it('caches submitted feedback per alert', async () => { const store = useAlertQualityStore() await store.submitFeedback('alert-1', 'useful', 'test note') expect(store.getFeedback('alert-1').rating).toBe('useful') }) })