import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import VitalsEntryForm from '@/components/patient/VitalsEntryForm.vue'

describe('VitalsEntryForm', () => {
  it('rendersVitalSignFields', () => {
    const wrapper = mount(VitalsEntryForm)
    expect(wrapper.text()).toContain('Heart Rate')
    expect(wrapper.text()).toContain('SpO₂')
    expect(wrapper.text()).toContain('AVPU')
  })

  it('emitsBatchObservationsOnSubmit', async () => {
    const wrapper = mount(VitalsEntryForm)
    await wrapper.findAll('input[type="number"]')[0].setValue('90')
    await wrapper.find('select').setValue('0')
    await wrapper.find('button').trigger('click')

    const payload = wrapper.emitted('submit')?.[0]?.[0]
    expect(payload).toHaveLength(2)
    expect(payload).toEqual(expect.arrayContaining([
      expect.objectContaining({ observationCode: 'HEART_RATE', value: 90 }),
      expect.objectContaining({ observationCode: 'AVPU', value: 0 }),
    ]))
  })

  it('showsPlausibilityError', async () => {
    const wrapper = mount(VitalsEntryForm)
    await wrapper.findAll('input[type="number"]')[0].setValue('999')
    await wrapper.find('button').trigger('click')
    expect(wrapper.emitted('submit')).toBeUndefined()
    expect(wrapper.text()).toContain('Value must be between 1 and 300')
  })
})
