import { plainTextToHtml } from './htmlUtils'; describe('htmlUtils', () => { test('should convert a plain text string to its HTML equivalent', () => { const testCases = [ [ '', '', ], [ 'line 1\nline 2', '

line 1
line 2

', ], [ 'one\n\ntwo\nthree\n\nfour', '

one

two
three

four

', ], [ '\n\n', '

', ], [ '\n\none', '

one

', ], [ '\none\ntwo\n', '

one
two

', ], [ 'one\n\n\ntwo', '

one


two

', ], [ 'one\n\n\n\ntwo', '

one



two

', ], [ '', '<img onerror="http://downloadmalware.com"/>', ], [ 'Some text indented by a tab:\n\tIndented', '

Some text indented by a tab:
    Indented

', ], [ 'Some text indented by two spaces:\n Indented', '

Some text indented by two spaces:
  Indented

', ], [ 'Some text with white space between the content\nNewLine', '

Some text with white space between the content
NewLine

', ], [ 'Some text with \t tab\nNewLine', '

Some text with \t tab
NewLine

', ], [ 'Tab at the end of the line is ignored\t\nNewLine', '

Tab at the end of the line is ignored
NewLine

', ], [ 'White space at the end of the line is ignored \nNewLine', '

White space at the end of the line is ignored
NewLine

', ], ]; for (const t of testCases) { const [input, expected] = t; const actual = plainTextToHtml(input); expect(actual).toBe(expected); } }); });