2021-05-20 18:08:59 +02:00
|
|
|
import { plainTextToHtml } from './htmlUtils';
|
|
|
|
|
|
|
|
describe('htmlUtils', () => {
|
|
|
|
|
|
|
|
test('should convert a plain text string to its HTML equivalent', () => {
|
|
|
|
const testCases = [
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'line 1\nline 2',
|
2023-07-27 15:48:41 +02:00
|
|
|
'<p>line 1<br/>line 2</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'one\n\ntwo\nthree\n\nfour',
|
|
|
|
'<p>one</p><p>two<br/>three</p><p>four</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'\n\n',
|
|
|
|
'<br/><br/>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'\n\none',
|
|
|
|
'<br/><p>one</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'\none\ntwo\n',
|
|
|
|
'<p>one<br/>two</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'one\n\n\ntwo',
|
|
|
|
'<p>one</p><br/><p>two</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'one\n\n\n\ntwo',
|
|
|
|
'<p>one</p><br/><br/><p>two</p>',
|
2021-05-20 18:08:59 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<img onerror="http://downloadmalware.com"/>',
|
|
|
|
'<img onerror="http://downloadmalware.com"/>',
|
|
|
|
],
|
2024-03-02 17:43:38 +02:00
|
|
|
[
|
|
|
|
'Some text indented by a tab:\n\tIndented',
|
|
|
|
'<p>Some text indented by a tab:<br/> Indented</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Some text indented by two spaces:\n Indented',
|
|
|
|
'<p>Some text indented by two spaces:<br/> Indented</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Some text with white space between the content\nNewLine',
|
|
|
|
'<p>Some text with white space between the content<br/>NewLine</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Some text with \t tab\nNewLine',
|
|
|
|
'<p>Some text with \t tab<br/>NewLine</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'Tab at the end of the line is ignored\t\nNewLine',
|
|
|
|
'<p>Tab at the end of the line is ignored<br/>NewLine</p>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'White space at the end of the line is ignored \nNewLine',
|
|
|
|
'<p>White space at the end of the line is ignored<br/>NewLine</p>',
|
|
|
|
],
|
2021-05-20 18:08:59 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
for (const t of testCases) {
|
|
|
|
const [input, expected] = t;
|
|
|
|
const actual = plainTextToHtml(input);
|
|
|
|
expect(actual).toBe(expected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|