import { describe, it, expect, beforeEach, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { useAlertStore } from '@/stores/alerts'

describe('alert store notifications', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  })

  it('queuesBannerAlertsForNewCriticalItems', () => {
    const store = useAlertStore()
    const critical = {
      id: 'alert-1',
      severity: 'CRITICAL',
      status: 'OPEN',
      alertType: 'SOFA_SEPSIS',
    }

    expect(store.applyPollResults([critical])).toEqual([])
    expect(store.bannerAlerts).toEqual([])

    const next = {
      id: 'alert-2',
      severity: 'CRITICAL',
      status: 'OPEN',
      alertType: 'GCS_CRITICAL',
    }
    const newAlerts = store.applyPollResults([critical, next])
    expect(newAlerts.map(alert => alert.id)).toEqual(['alert-2'])
    expect(store.bannerAlerts.map(alert => alert.id)).toEqual(['alert-2'])
  })

  it('dismissesBannerAlert', () => {
    const store = useAlertStore()
    store.bannerAlerts = [{ id: 'alert-1' }]
    store.dismissBannerAlert('alert-1')
    expect(store.bannerAlerts).toEqual([])
  })
})
