2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
2014-10-10 15:54:07 +01:00
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
// Stuff we are testing
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
2014-10-10 15:54:07 +01:00
|
|
|
|
|
|
|
describe('{{content}} helper', function () {
|
2019-03-18 19:52:49 +08:00
|
|
|
it('renders empty string when null', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const html = null;
|
|
|
|
const rendered = helpers.content.call({html: html});
|
2019-03-18 19:52:49 +08:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal('');
|
|
|
|
});
|
|
|
|
|
2014-10-10 15:54:07 +01:00
|
|
|
it('can render content', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
const html = 'Hello World';
|
|
|
|
const rendered = helpers.content.call({html: html});
|
2014-10-10 15:54:07 +01:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal(html);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html by word', function () {
|
2020-04-29 16:44:27 +01: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 15:54:07 +01:00
|
|
|
|
|
|
|
should.exist(rendered);
|
2014-11-08 17:32:43 -08:00
|
|
|
rendered.string.should.equal('<p>Hello <strong>World!</strong></p>');
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html to 0 words', function () {
|
2020-04-29 16:44:27 +01: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 15:54:07 +01:00
|
|
|
|
|
|
|
should.exist(rendered);
|
2017-03-14 13:56:46 +00:00
|
|
|
rendered.string.should.equal('');
|
2014-10-10 15:54:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can truncate html by character', function () {
|
2020-04-29 16:44:27 +01: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 15:54:07 +01:00
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.string.should.equal('<p>Hello <strong>Wo</strong></p>');
|
|
|
|
});
|
|
|
|
});
|