import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import StatusBadge from '@/components/StatusBadge.vue'
import { BATCH_STATUS_META, getBatchStatusMeta } from '@/utils/batchStatus'

describe('StatusBadge', () => {
  it.each(Object.keys(BATCH_STATUS_META))('renders label and icon for %s', (status) => {
    const wrapper = mount(StatusBadge, { props: { status } })
    expect(wrapper.text()).toContain(BATCH_STATUS_META[status].label)
    expect(wrapper.find('svg').exists()).toBe(true)
  })

  it('humanizes unknown statuses without relying on color alone', () => {
    const wrapper = mount(StatusBadge, { props: { status: 'CUSTOM_STATE' } })
    expect(wrapper.text()).toContain('Custom State')
    expect(wrapper.find('svg').exists()).toBe(true)
  })

  it('handles null status', () => {
    const wrapper = mount(StatusBadge, { props: { status: null } })
    expect(wrapper.text()).toContain('Unknown')
  })
})

describe('getBatchStatusMeta', () => {
  it('maps REJECTED to Verification Rejected', () => {
    expect(getBatchStatusMeta('REJECTED').label).toBe('Verification Rejected')
  })

  it('maps AWAITING_CLINICAL_APPROVAL to Pending Approval', () => {
    expect(getBatchStatusMeta('AWAITING_CLINICAL_APPROVAL').label).toBe('Pending Approval')
  })
})
