2023-11-17 18:47:05 +02:00
|
|
|
import htmlUtils, { extractHtmlBody, htmlDocIsImageOnly } from './htmlUtils';
|
2022-01-15 18:53:24 +02:00
|
|
|
|
|
|
|
describe('htmlUtils', () => {
|
|
|
|
|
|
|
|
test('should strip off HTML', () => {
|
|
|
|
const testCases = [
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<b>test</b>',
|
|
|
|
'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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-21 19:37:33 +02:00
|
|
|
test('should extract the HTML body', () => {
|
|
|
|
const testCases: [string, string][] = [
|
|
|
|
[
|
|
|
|
'Just <b>testing</b>',
|
|
|
|
'Just <b>testing</b>',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<html><head></head><meta bla><body>Here is the body<img src="test.png"/></body></html>',
|
|
|
|
'Here is the body<img src="test.png"/>',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const [input, expected] of testCases) {
|
|
|
|
const actual = extractHtmlBody(input);
|
|
|
|
expect(actual).toBe(expected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-17 18:47:05 +02:00
|
|
|
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
|
|
|
|
'<meta charset=\'utf-8\'>\n<img src="https://example.com/img.png"/>',
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<img src="https://example.com/img.png"/>',
|
|
|
|
true,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<img src="https://example.com/img.png"/><img src="https://example.com/img.png"/>',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<img src="https://example.com/img.png"/><p>Some text</p>',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<img src="https://example.com/img.png"/> Some text',
|
|
|
|
false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const [input, expected] of testCases) {
|
|
|
|
const actual = htmlDocIsImageOnly(input);
|
|
|
|
expect(actual).toBe(expected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-15 18:53:24 +02:00
|
|
|
});
|