import { getInitials } from './initials';

describe('getInitials', () => {
  it('returns both letters if input is exactly two uppercase letters', () => {
    expect(getInitials('ML')).toBe('ML');
    expect(getInitials('JS')).toBe('JS');
  });

  it('returns one letter if input is exactly two letters and either letter is lowercase', () => {
    expect(getInitials('Na')).toBe('N');
    expect(getInitials('aa')).toBe('A');
  });

  it('returns first letter if only one word is given', () => {
    expect(getInitials('Anton')).toBe('A');
    expect(getInitials('richard')).toBe('R');
  });

  it('returns first and last initials for multi-word names', () => {
    expect(getInitials('Ness Grixti')).toBe('NG');
    expect(getInitials('João Goão Cevada')).toBe('JC');
    expect(getInitials('Caio Kaio Erio Orio')).toBe('CO');
  });

  it('handles lowercase and mixed case names', () => {
    expect(getInitials('ilya puchka')).toBe('IP');
    expect(getInitials('ilYa pUchka')).toBe('IP');
  });

  it('ignores extra spaces', () => {
    expect(getInitials('  Deji     Ajetomobi  ')).toBe('DA');
    expect(getInitials(' Gusso   ')).toBe('G');
  });

  it('returns first and last letter if name is two words with single letters', () => {
    expect(getInitials('S L')).toBe('SL');
  });

  it('handles single character', () => {
    expect(getInitials('Q')).toBe('Q');
  });

  it('handles names with (parenthesized) values', () => {
    expect(getInitials('Squirrel (GBP)')).toBe('S');
    expect(getInitials('Fantastic Squirrel (USD)')).toBe('FS');
    expect(getInitials('Squirrel [GBP]')).toBe('S');
    expect(getInitials('Fantastic Squirrel [USD]')).toBe('FS');
    expect(getInitials('Squirrel {GBP}')).toBe('S');
    expect(getInitials('Fantastic Squirrel {USD}')).toBe('FS');
    expect(getInitials('Squirrel <GBP>')).toBe('S');
    expect(getInitials('Fantastic Squirrel <USD>')).toBe('FS');
    expect(getInitials('(Super) Fantastic Squirrel')).toBe('FS');
    expect(getInitials('Super (Fantastic) Squirrel')).toBe('SS');
  });

  it('handles emojis correctly', () => {
    expect(getInitials('😀')).toBe('😀');
    expect(getInitials('😀 Christian Dalby')).toBe('😀D');
    expect(getInitials('Christian 😀')).toBe('C😀');
    expect(getInitials('😎 Christian 😎')).toBe('😎😎');
    expect(getInitials('🎉 Party 🎊 Time')).toBe('🎉T');
  });

  it('handles unicode strings correctly', () => {
    expect(getInitials('\u{1F600}')).toBe('\u{1F600}');
    expect(getInitials('\u{1F600} Christian Dalby')).toBe('\u{1F600}D');
    expect(getInitials('Christian \u{1F600}')).toBe('C\u{1F600}');
    expect(getInitials('\u{1F60E} Christian \u{1F60E}')).toBe('\u{1F60E}\u{1F60E}');
    expect(getInitials('\u{1F389} Party \u{1F38A} Time')).toBe('\u{1F389}T');
  });

  it('handles multi-byte emojis with skin tones and ZWJ sequences', () => {
    expect(getInitials('👨‍👩‍👧‍👦')).toBe('👨‍👩‍👧‍👦');
    expect(getInitials('👨‍👩‍👧‍👦 Family')).toBe('👨‍👩‍👧‍👦F');
    expect(getInitials('👋🏽')).toBe('👋🏽');
    expect(getInitials('Christian 👋🏽')).toBe('C👋🏽');
  });

  it('handles diacritical marks correctly', () => {
    expect(getInitials('André Müller')).toBe('AM');
    expect(getInitials('Ángel Muñoz')).toBe('ÁM');
    expect(getInitials('François Élis')).toBe('FÉ');
    expect(getInitials('Łukasz Ślusarczyk')).toBe('ŁŚ');
    expect(getInitials('Ömer Özdemir')).toBe('ÖÖ');
  });
});
