2019-07-30 09:35:42 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2018-05-23 13:14:38 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
|
2019-09-24 00:23:10 +02:00
|
|
|
const { asyncTest } = require('test-utils.js');
|
2018-05-23 13:14:38 +02:00
|
|
|
const markdownUtils = require('lib/markdownUtils.js');
|
|
|
|
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
|
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('markdownUtils', function() {
|
|
|
|
|
|
|
|
beforeEach(async (done) => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2019-09-24 00:23:10 +02:00
|
|
|
it('should prepend a base URL', asyncTest(async () => {
|
2018-05-23 13:14:38 +02:00
|
|
|
const baseUrl = 'https://test.com/site';
|
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
['[something](testing.html)', '[something](https://test.com/site/testing.html)'],
|
|
|
|
['![something](/img/test.png)', '![something](https://test.com/img/test.png)'],
|
|
|
|
['[![something](/img/test.png)](/index.html "Home page")', '[![something](https://test.com/img/test.png)](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)'],
|
2019-10-29 11:02:42 +02:00
|
|
|
['[![some text](/img/test.png)](/jmp/?s=80&l=related&u=http://example.com "some description")', '[![some text](https://test.com/img/test.png)](https://test.com/jmp/?s=80&l=related&u=http://example.com "some description")'],
|
2018-05-23 13:14:38 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-09-24 00:23:10 +02:00
|
|
|
}));
|
2018-05-23 13:14:38 +02:00
|
|
|
|
2019-09-24 00:23:10 +02:00
|
|
|
it('should extract image URLs', asyncTest(async () => {
|
2018-05-23 15:25:59 +02:00
|
|
|
const testCases = [
|
|
|
|
['![something](http://test.com/img.png)', ['http://test.com/img.png']],
|
|
|
|
['![something](http://test.com/img.png) ![something2](http://test.com/img2.png)', ['http://test.com/img.png', 'http://test.com/img2.png']],
|
|
|
|
['![something](http://test.com/img.png "Some description")', ['http://test.com/img.png']],
|
2018-09-24 21:15:23 +02:00
|
|
|
['![something](https://test.com/ohoh_(123).png)', ['https://test.com/ohoh_(123).png']],
|
2020-02-12 20:15:16 +02:00
|
|
|
['![nothing]() ![something](http://test.com/img.png)', ['http://test.com/img.png']],
|
2018-05-23 15:25:59 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
|
|
const md = testCases[i][0];
|
2020-02-12 20:15:16 +02:00
|
|
|
const actual = markdownUtils.extractImageUrls(md);
|
2018-05-23 15:25:59 +02:00
|
|
|
const expected = testCases[i][1];
|
|
|
|
|
2020-02-12 20:15:16 +02:00
|
|
|
expect(actual.join(' ')).toBe(expected.join(' '));
|
2018-05-23 15:25:59 +02:00
|
|
|
}
|
2019-09-24 00:23:10 +02:00
|
|
|
}));
|
2018-05-23 15:25:59 +02:00
|
|
|
|
2020-02-08 00:15:41 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|