import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import ThresholdManagementView from '@/views/ThresholdManagementView.vue'

vi.mock('@/api/thresholds', () => ({
  fetchThresholds: vi.fn(() => Promise.resolve([
    {
      id: 'thr-1',
      observationCode: 'HEART_RATE',
      displayName: 'Heart Rate',
      unit: 'bpm',
      criticalLow: 30,
      warningLow: 50,
      warningHigh: 100,
      criticalHigh: 150,
    },
  ])),
  createThreshold: vi.fn(),
  updateThreshold: vi.fn(),
  deleteThreshold: vi.fn(),
}))

describe('ThresholdManagementView', () => {
  it('rendersThresholdTable', async () => {
    setActivePinia(createPinia())
    const wrapper = mount(ThresholdManagementView)
    await vi.waitFor(() => expect(wrapper.text()).toContain('HEART_RATE'))
    expect(wrapper.text()).toContain('Alert Thresholds')
    expect(wrapper.text()).toContain('Create Threshold')
  })
})
