2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
2021-10-06 12:52:46 +03:00
|
|
|
const hbs = require('../../../../core/frontend/services/theme-engine/engine');
|
|
|
|
const configUtils = require('../../../utils/configUtils');
|
2021-02-09 09:46:43 +03:00
|
|
|
const path = require('path');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
// Stuff we are testing
|
2021-10-06 12:52:46 +03:00
|
|
|
const content = require('../../../../core/frontend/helpers/content');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{content}} helper', function () {
|
2021-02-09 09:46:43 +03:00
|
|
|
before(function (done) {
|
|
|
|
hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]});
|
|
|
|
|
|
|
|
hbs.cachePartials(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-18 14:52:49 +03:00
|
|
|
it('renders empty string when null', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const html = null;
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = content.call({html: html});
|
2019-03-18 14:52:49 +03:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal('');
|
|
|
|
});
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
it('can render content', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const html = 'Hello World';
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = content.call({html: html});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal(html);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html by word', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const html = '<p>Hello <strong>World! It\'s me!</strong></p>';
|
|
|
|
|
|
|
|
const rendered = (
|
2021-10-04 18:30:54 +03:00
|
|
|
content
|
2020-04-29 18:44:27 +03:00
|
|
|
.call(
|
|
|
|
{html: html},
|
|
|
|
{hash: {words: 2}}
|
|
|
|
)
|
|
|
|
);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
should.exist(rendered);
|
2014-11-09 04:32:43 +03:00
|
|
|
rendered.string.should.equal('<p>Hello <strong>World!</strong></p>');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html to 0 words', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const html = '<p>Hello <strong>World! It\'s me!</strong></p>';
|
|
|
|
|
|
|
|
const rendered = (
|
2021-10-04 18:30:54 +03:00
|
|
|
content
|
2020-04-29 18:44:27 +03:00
|
|
|
.call(
|
|
|
|
{html: html},
|
|
|
|
{hash: {words: '0'}}
|
|
|
|
)
|
|
|
|
);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
should.exist(rendered);
|
2017-03-14 16:56:46 +03:00
|
|
|
rendered.string.should.equal('');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html by character', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const html = '<p>Hello <strong>World! It\'s me!</strong></p>';
|
|
|
|
|
|
|
|
const rendered = (
|
2021-10-04 18:30:54 +03:00
|
|
|
content
|
2020-04-29 18:44:27 +03:00
|
|
|
.call(
|
|
|
|
{html: html},
|
|
|
|
{hash: {characters: 8}}
|
|
|
|
)
|
|
|
|
);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal('<p>Hello <strong>Wo</strong></p>');
|
|
|
|
});
|
|
|
|
});
|
2021-02-09 09:46:43 +03:00
|
|
|
|
|
|
|
describe('{{content}} helper with no access', function () {
|
|
|
|
let optionsData;
|
|
|
|
before(function (done) {
|
|
|
|
hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]});
|
|
|
|
|
|
|
|
hbs.cachePartials(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
optionsData = {
|
|
|
|
data: {
|
|
|
|
site: {
|
|
|
|
accent_color: '#abcdef'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can render default template', function () {
|
2021-02-18 02:00:26 +03:00
|
|
|
const html = '';
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = content.call({html: html, access: false}, optionsData);
|
2021-02-09 09:46:43 +03:00
|
|
|
rendered.string.should.containEql('gh-post-upgrade-cta');
|
|
|
|
rendered.string.should.containEql('gh-post-upgrade-cta-content');
|
|
|
|
rendered.string.should.containEql('"background-color: #abcdef"');
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
});
|
2021-02-18 02:00:26 +03:00
|
|
|
|
|
|
|
it('outputs free content if available via paywall card', function () {
|
|
|
|
// html will be included when there is free content available
|
|
|
|
const html = 'Free content';
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = content.call({html: html, access: false}, optionsData);
|
2021-02-18 02:00:26 +03:00
|
|
|
rendered.string.should.containEql('Free content');
|
|
|
|
rendered.string.should.containEql('gh-post-upgrade-cta');
|
|
|
|
rendered.string.should.containEql('gh-post-upgrade-cta-content');
|
|
|
|
rendered.string.should.containEql('"background-color: #abcdef"');
|
|
|
|
});
|
2021-02-09 09:46:43 +03:00
|
|
|
});
|
|
|
|
|
2021-02-18 02:00:26 +03:00
|
|
|
describe('{{content}} helper with custom template', function () {
|
2021-02-09 09:46:43 +03:00
|
|
|
let optionsData;
|
|
|
|
before(function (done) {
|
|
|
|
hbs.express4({partialsDir: [path.resolve(__dirname, './test_tpl')]});
|
|
|
|
|
|
|
|
hbs.cachePartials(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can render custom template', function () {
|
|
|
|
const html = 'Hello World';
|
2021-10-04 18:30:54 +03:00
|
|
|
const rendered = content.call({html: html, access: false}, optionsData);
|
2021-02-09 09:46:43 +03:00
|
|
|
rendered.string.should.not.containEql('gh-post-upgrade-cta');
|
|
|
|
rendered.string.should.containEql('custom-post-upgrade-cta');
|
|
|
|
rendered.string.should.containEql('custom-post-upgrade-cta-content');
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
});
|
|
|
|
});
|