2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
// Stuff we are testing
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{content}} helper', function () {
|
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;
|
|
|
|
const rendered = helpers.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';
|
|
|
|
const rendered = helpers.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 = (
|
|
|
|
helpers.content
|
|
|
|
.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 = (
|
|
|
|
helpers.content
|
|
|
|
.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 = (
|
|
|
|
helpers.content
|
|
|
|
.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>');
|
|
|
|
});
|
|
|
|
});
|