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');
  });
});
