const should = require('should');
const configUtils = require('../../utils/configUtils');
const mobiledocLib = require('../../../core/server/lib/mobiledoc');
describe('lib/mobiledoc', function () {
beforeEach(function () {
configUtils.set('url', 'https://example.com');
});
afterEach(function () {
configUtils.restore();
// ensure config changes are reset and picked up by next test
mobiledocLib.reload();
});
describe('mobiledocHtmlRenderer', function () {
it('renders all default cards and atoms', function () {
let mobiledoc = {
version: '0.3.1',
atoms: [
['soft-return', '', {}]
],
cards: [
['markdown', {
markdown: '# Markdown card\nSome markdown'
}],
['hr', {}],
['image', {
cardWidth: 'wide',
src: '/content/images/2018/04/NatGeo06.jpg',
width: 4000,
height: 2000,
caption: 'Birdies'
}],
['html', {
html: '
HTML card
\n'
}],
['embed', {
html: 'Embed card
'
}],
['gallery', {
images: [{
row: 0,
fileName: 'test.png',
src: '/content/images/test.png',
width: 1000,
height: 500
}]
}]
],
markups: [],
sections: [
[1, 'p', [
[0, [], 0, 'One'],
[1, [], 0, 0],
[0, [], 0, 'Two']
]],
[10, 0],
[1, 'p', [
[0, [], 0, 'Three']
]],
[10, 1],
[10, 2],
[1, 'p', [
[0, [], 0, 'Four']
]],
[10, 3],
[10, 4],
[10, 5],
[1, 'p', []]
]
};
mobiledocLib.mobiledocHtmlRenderer.render(mobiledoc)
.should.eql('One
Two
Markdown card
\nSome markdown
\nThree
BirdiesFour
HTML card
\nEmbed card
');
});
it('respects srcsets config', function () {
configUtils.set('imageOptimization:srcsets', false);
let mobiledoc = {
version: '0.3.1',
atoms: [],
cards: [
['image', {
cardWidth: 'wide',
src: '/content/images/2018/04/NatGeo06.jpg',
width: 4000,
height: 2000,
caption: 'Birdies'
}],
['gallery', {
images: [{
row: 0,
fileName: 'test.png',
src: '/content/images/test.png',
width: 1000,
height: 500
}]
}]
],
markups: [],
sections: [
[10, 0],
[10, 1]
]
};
mobiledocLib.mobiledocHtmlRenderer.render(mobiledoc)
.should.eql('
Birdies');
});
});
});