import { htmlToClipboardData } from './clipboardUtils';
describe('clipboardUtils', () => {
test('should convert HTML to the right format', () => {
const testCases = [
[
'
Header
',
'# Header',
'Header
',
],
[
'One line
Two line
',
'One line\n\nTwo line',
'One line
Two line
',
],
[
'',
'aaa\n\n```javascript\nvar a = 123;\n```\n\n- [x] A checkbox',
'',
],
];
for (const testCase of testCases) {
const [inputHtml, expectedText, expectedHtml] = testCase;
const result = htmlToClipboardData(inputHtml);
expect(result.html).toBe(expectedHtml);
expect(result.text).toBe(expectedText);
}
});
test('should remove parameters from local images', () => {
const localImage = 'file:///home/some/path/test.jpg';
const content = ``;
const copyableContent = htmlToClipboardData(content);
expect(copyableContent.html).toEqual(``);
});
test('should be able to process mutiple images', () => {
const localImage1 = 'file:///home/some/path/test1.jpg';
const localImage2 = 'file:///home/some/path/test2.jpg';
const localImage3 = 'file:///home/some/path/test3.jpg';
const content = `
`;
const copyableContent = htmlToClipboardData(content);
const expectedContent = `
`;
expect(copyableContent.html).toEqual(expectedContent);
});
test('should not change parameters for images on the internet', () => {
const image1 = 'http://www.somelink.com/image1.jpg';
const image2 = 'https://www.somelink.com/image2.jpg';
const content = `
`;
const copyableContent = htmlToClipboardData(content);
expect(copyableContent.html).toEqual(content);
});
});