import {bioParagraphs} from './bioText';

describe('bioParagraphs', () => {
  it.each([undefined, null, '', '   ', '<p></p>', '<p>&nbsp;</p><br>'])(
    'shouldReturnNoParagraphForAnEmptyBio (%s)',
    (bio) => {
      expect(bioParagraphs(bio)).toEqual([]);
    }
  );

  it('shouldStripTagsAndKeepParagraphs', () => {
    const html = '<p>Né à <b>Quimper</b>.</p><p>Sonneur &amp; pédagogue.<br/>Depuis 1990</p>';

    expect(bioParagraphs(html)).toEqual(['Né à Quimper.', 'Sonneur & pédagogue.', 'Depuis 1990']);
  });

  it('shouldDecodeHtmlEntities', () => {
    expect(bioParagraphs('&laquo;&nbsp;Kan ha diskan&nbsp;&raquo; &#233;cole d&#039;Alan')).toEqual([
      '« Kan ha diskan » école d\'Alan',
    ]);
  });

  it('shouldKeepPlainTextLineBreaksAsParagraphs', () => {
    expect(bioParagraphs('Première ligne\n\nDeuxième ligne')).toEqual(['Première ligne', 'Deuxième ligne']);
  });

  it('shouldDropScriptContent', () => {
    expect(bioParagraphs('<p>Bio</p><script>alert(1)</script>')).toEqual(['Bio']);
  });
});
