2019-07-30 07:35:42 +00:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
|
2018-05-23 11:14:38 +00:00
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
|
2019-09-23 22:23:10 +00:00
|
|
|
const { asyncTest } = require('test-utils.js');
|
2018-05-23 11:14:38 +00: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-23 22:23:10 +00:00
|
|
|
it('should prepend a base URL', asyncTest(async () => {
|
2018-05-23 11:14:38 +00:00
|
|
|
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)'],
|
2019-10-29 09:02:42 +00:00
|
|
|
['[](/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")'],
|
2018-05-23 11:14:38 +00: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-23 22:23:10 +00:00
|
|
|
}));
|
2018-05-23 11:14:38 +00:00
|
|
|
|
2019-09-23 22:23:10 +00:00
|
|
|
it('should extract image URLs', asyncTest(async () => {
|
2018-05-23 13:25:59 +00:00
|
|
|
const testCases = [
|
|
|
|
['', ['http://test.com/img.png']],
|
|
|
|
[' ', ['http://test.com/img.png', 'http://test.com/img2.png']],
|
|
|
|
['', ['http://test.com/img.png']],
|
2018-09-24 19:15:23 +00:00
|
|
|
['.png)', ['https://test.com/ohoh_(123).png']],
|
2018-05-23 13:25:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
|
|
const md = testCases[i][0];
|
|
|
|
const expected = testCases[i][1];
|
|
|
|
|
|
|
|
expect(markdownUtils.extractImageUrls(md).join('')).toBe(expected.join(''));
|
|
|
|
}
|
2019-09-23 22:23:10 +00:00
|
|
|
}));
|
2018-05-23 13:25:59 +00:00
|
|
|
|
2019-07-30 07:35:42 +00:00
|
|
|
});
|