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

describe('GcsEntryForm', () => {
  it('rendersThreeDropdowns', () => {
    const wrapper = mount(GcsEntryForm)
    expect(wrapper.findAll('select')).toHaveLength(3)
    expect(wrapper.text()).toContain('Eye (E)')
    expect(wrapper.text()).toContain('Verbal (V)')
    expect(wrapper.text()).toContain('Motor (M)')
  })

  it('computesTotalCorrectly', async () => {
    const wrapper = mount(GcsEntryForm)
    await wrapper.findAll('select')[0].setValue(2)
    await wrapper.findAll('select')[1].setValue(3)
    await wrapper.findAll('select')[2].setValue(4)
    expect(wrapper.text()).toContain('GCS 9/15')
  })

  it('showsClassification', async () => {
    const wrapper = mount(GcsEntryForm)
    await wrapper.findAll('select')[0].setValue(2)
    await wrapper.findAll('select')[1].setValue(3)
    await wrapper.findAll('select')[2].setValue(3)
    expect(wrapper.text()).toContain('Severe')

    await wrapper.findAll('select')[0].setValue(4)
    await wrapper.findAll('select')[1].setValue(4)
    await wrapper.findAll('select')[2].setValue(4)
    expect(wrapper.text()).toContain('Moderate')

    await wrapper.findAll('select')[0].setValue(4)
    await wrapper.findAll('select')[1].setValue(5)
    await wrapper.findAll('select')[2].setValue(6)
    expect(wrapper.text()).toContain('Mild')
  })

  it('emitsSubmitWithComponents', async () => {
    const wrapper = mount(GcsEntryForm)
    await wrapper.findAll('select')[0].setValue(3)
    await wrapper.findAll('select')[1].setValue(4)
    await wrapper.findAll('select')[2].setValue(5)
    await wrapper.find('button').trigger('click')
    expect(wrapper.emitted('submit')?.[0]?.[0]).toEqual({ eye: 3, verbal: 4, motor: 5 })
  })

  it('defaultsToNormalValues', () => {
    const wrapper = mount(GcsEntryForm)
    expect(wrapper.text()).toContain('GCS 15/15')
    expect(wrapper.text()).toContain('E4 V5 M6')
  })

  it('usesResponsiveLayout', () => {
    const wrapper = mount(GcsEntryForm)
    const grid = wrapper.find('.grid')
    expect(grid.classes()).toContain('grid-cols-1')
    expect(grid.classes()).toContain('sm:grid-cols-3')
    expect(wrapper.find('button').classes()).toContain('w-full')
    expect(wrapper.find('button').classes()).toContain('sm:w-auto')
  })
})