mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-19 20:00:20 +02:00
104 lines
4.1 KiB
JavaScript
104 lines
4.1 KiB
JavaScript
/* eslint-disable no-unused-vars */
|
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
const { asyncTest } = require('test-utils.js');
|
|
const markdownUtils = require('lib/markdownUtils').default;
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
});
|
|
|
|
describe('markdownUtils', function() {
|
|
|
|
beforeEach(async (done) => {
|
|
done();
|
|
});
|
|
|
|
it('should prepend a base URL', asyncTest(async () => {
|
|
const baseUrl = 'https://test.com/site';
|
|
|
|
const testCases = [
|
|
['[something](testing.html)', '[something](https://test.com/site/testing.html)'],
|
|
['', ''],
|
|
['[](/index.html "Home page")', '[](https://test.com/index.html "Home page")'],
|
|
['[onelink.com](/jmp/?id=123&u=http://something.com/test)', '[onelink.com](https://test.com/jmp/?id=123&u=http://something.com/test)'],
|
|
['[](/jmp/?s=80&l=related&u=http://example.com "some description")', '[](https://test.com/jmp/?s=80&l=related&u=http://example.com "some description")'],
|
|
];
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
const md = testCases[i][0];
|
|
const expected = testCases[i][1];
|
|
expect(markdownUtils.prependBaseUrl(md, baseUrl)).toBe(expected);
|
|
}
|
|
}));
|
|
|
|
it('should extract image URLs', asyncTest(async () => {
|
|
const testCases = [
|
|
['', ['http://test.com/img.png']],
|
|
[' ', ['http://test.com/img.png', 'http://test.com/img2.png']],
|
|
['', ['http://test.com/img.png']],
|
|
['.png)', ['https://test.com/ohoh_(123).png']],
|
|
['![nothing]() ', ['http://test.com/img.png']],
|
|
];
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
const md = testCases[i][0];
|
|
const actual = markdownUtils.extractImageUrls(md);
|
|
const expected = testCases[i][1];
|
|
|
|
expect(actual.join(' ')).toBe(expected.join(' '));
|
|
}
|
|
}));
|
|
|
|
it('escape a markdown link', asyncTest(async () => {
|
|
|
|
const testCases = [
|
|
['file:///Users/who put spaces in their username??/.config/joplin', 'file:///Users/who%20put%20spaces%20in%20their%20username??/.config/joplin'],
|
|
['file:///Users/(and brackets???)/.config/joplin', 'file:///Users/%28and%20brackets???%29/.config/joplin'],
|
|
['file:///Users/thisisfine/.config/joplin', 'file:///Users/thisisfine/.config/joplin'],
|
|
];
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
const md = testCases[i][0];
|
|
const expected = testCases[i][1];
|
|
expect(markdownUtils.escapeLinkUrl(md)).toBe(expected);
|
|
}
|
|
}));
|
|
|
|
it('escape a markdown link (title)', asyncTest(async () => {
|
|
|
|
const testCases = [
|
|
['Helmut K. C. Tessarek', 'Helmut K. C. Tessarek'],
|
|
['Helmut (K. C.) Tessarek', 'Helmut (K. C.) Tessarek'],
|
|
['Helmut [K. C.] Tessarek', 'Helmut \\[K. C.\\] Tessarek'],
|
|
];
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
const md = testCases[i][0];
|
|
const expected = testCases[i][1];
|
|
expect(markdownUtils.escapeTitleText(md)).toBe(expected);
|
|
}
|
|
}));
|
|
|
|
it('replace markdown link with description', asyncTest(async () => {
|
|
|
|
const testCases = [
|
|
['Test case [one](link)', 'Test case one'],
|
|
['Test case ', 'Test case two'],
|
|
['**# -Test case three', 'Test case three'],
|
|
['This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a [link](linkurl) at the end', 'This is a looooooong tiiitlllle with moore thaaaaaaan eighty characters and a li'],
|
|
['', ''],
|
|
['These are [link1](one), [link2](two) and ', 'These are link1, link2 and link3'],
|
|
['No description link to [](https://joplinapp.org)', 'No description link to https://joplinapp.org'],
|
|
];
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
const md = testCases[i][0];
|
|
const expected = testCases[i][1];
|
|
expect(markdownUtils.titleFromBody(md)).toBe(expected);
|
|
}
|
|
}));
|
|
|
|
});
|