import { describe, it, expect } from 'vitest'
import {
  computeAge,
  formatAllergiesDisplay,
  formatBloodType,
  formatDepartment,
  formatDobWithAge,
  hasKnownAllergies,
} from '@/composables/patientFormat'

describe('patientFormat', () => {
  it('computesAgeFromDob', () => {
    expect(computeAge('1990-06-15', new Date('2026-06-23'))).toBe(36)
  })

  it('formatsBloodType', () => {
    expect(formatBloodType('AbNegative')).toBe('AB-')
    expect(formatBloodType('AB-')).toBe('AB-')
  })

  it('formatsDepartment', () => {
    expect(formatDepartment('Icu')).toBe('ICU')
    expect(formatDepartment('GENERAL_MEDICINE')).toBe('General Medicine')
  })

  it('showsNkdaWhenNoAllergies', () => {
    expect(hasKnownAllergies('')).toBe(false)
    expect(hasKnownAllergies(null)).toBe(false)
    expect(formatAllergiesDisplay('')).toBe('NKDA')
    expect(formatAllergiesDisplay('  Penicillin ')).toBe('Penicillin')
  })

  it('formatsDobWithAge', () => {
    const text = formatDobWithAge('1990-06-15')
    expect(text).toContain('1990')
    expect(text).toMatch(/\(\d+y\)/)
  })
})
