import htmlUtils, { extractHtmlBody, htmlDocIsImageOnly, removeWrappingParagraphAndTrailingEmptyElements } from './htmlUtils'; describe('htmlUtils', () => { test('should strip off HTML', () => { const testCases = [ [ '', '', ], [ 'test', 'test', ], [ 'Joplin®', 'JoplinĀ®', ], [ '<b>test</b>', '<b>test</b>', ], ]; for (const t of testCases) { const [input, expected] = t; const actual = htmlUtils.stripHtml(input); expect(actual).toBe(expected); } }); test('should extract the HTML body', () => { const testCases: [string, string][] = [ [ 'Just testing', 'Just testing', ], [ '', '', ], [ '
Here is the body
',
'Here is the body
',
],
];
for (const [input, expected] of testCases) {
const actual = extractHtmlBody(input);
expect(actual).toBe(expected);
}
});
test('should tell if an HTML document is an image only', () => {
const testCases: [string, boolean][] = [
[
// This is the kind of HTML that's pasted when copying an image from Chrome
'\n
',
true,
],
[
'',
false,
],
[
'
',
true,
],
[
'
',
false,
],
[
'
Some text
', false, ], [ '
Some text',
false,
],
];
for (const [input, expected] of testCases) {
const actual = htmlDocIsImageOnly(input);
expect(actual).toBe(expected);
}
});
it.each([
['Test
', 'Test'], ['Testing
A test
', 'Testing
A test
'], ['Testing
Testing
Testing
', 'Testing
'], ['Testing
', 'Testing'], ['is
\n', 'is\n'], ])('should remove empty elements (case %#)', (before, expected) => { expect(removeWrappingParagraphAndTrailingEmptyElements(before)).toBe(expected); }); });