/**
 * (initials from display name: empty, single word, multi-word, trim).
 */
import { getInitials } from '@/util/avatar'

describe('[util/avatar] getInitials', () => {
  describe('edge — empty input', () => {
    it('returns placeholder when name is null or undefined', () => {
      expect(getInitials(null)).toBe('?')
      expect(getInitials(undefined)).toBe('?')
    })

    it('returns placeholder when name is blank', () => {
      expect(getInitials('')).toBe('?')
      expect(getInitials('   ')).toBe('?')
    })
  })

  describe('happy path', () => {
    it('uses two letters from single word (duplicated if length 1)', () => {
      expect(getInitials('John')).toBe('JO')
      expect(getInitials('A')).toBe('AA')
    })

    it('uses first letters of first and last tokens', () => {
      expect(getInitials('Nguyen Van A')).toBe('VA')
      expect(getInitials('John Doe')).toBe('JD')
    })

    it('trims surrounding whitespace', () => {
      expect(getInitials('  John  Doe  ')).toBe('JD')
    })
  })
})
