const should = require('should'); // Stuff we are testing const helpers = require('../../../core/frontend/helpers'); describe('{{excerpt}} Helper', function () { it('renders empty string when html, excerpt, and custom_excerpt are null', function () { const html = null; const rendered = helpers.excerpt.call({ html: html, custom_excerpt: null, excerpt: null }); should.exist(rendered); rendered.string.should.equal(''); }); it('can render custom_excerpt', function () { const html = 'Hello World'; const rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(html); }); it('can render excerpt when other fields are empty', function () { const html = ''; const rendered = helpers.excerpt.call({ html: html, custom_excerpt: '', excerpt: 'Regular excerpt' }); should.exist(rendered); rendered.string.should.equal('Regular excerpt'); }); it('does not output HTML', function () { const html = '
There are
10
types
of people in the world:' +
' those who ' +
'understand trinary,
Testing1, my footnotes. And stuff. Footnote2with a link right after.'; const expected = 'Testing, my footnotes. And stuff. Footnotewith a link right after.'; const rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(expected); }); it('strips inline and bottom footnotes', function () { const html = '
Testing1 a very short post with a single footnote.
\n' + ''; const expected = 'Testing a very short post with a single footnote.'; const rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(expected); }); it('can truncate html by word', function () { const html = 'Hello World! It\'s me!
'; const expected = 'Hello World!'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' }, {hash: {words: '2'}} ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('can truncate html with non-ascii characters by word', function () { const html = 'Едквюэ опортэат праэчынт ючю но, квуй эю
'; const expected = 'Едквюэ опортэат'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' }, {hash: {words: '2'}} ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('can truncate html by character', function () { const html = 'Hello World! It\'s me!
'; const expected = 'Hello Wo'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' }, {hash: {characters: '8'}} ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('uses custom_excerpt if provided instead of truncating html', function () { const html = 'Hello World! It\'s me!
'; const customExcerpt = 'My Custom Excerpt wins!'; const expected = 'My Custom Excerpt wins!'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: customExcerpt } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('does not truncate custom_excerpt if characters options is provided', function () { const html = 'Hello World! It\'s me!
'; const customExcerpt = 'This is a custom excerpt. It should always be rendered in full length and not being cut ' + 'off. The maximum length of a custom excerpt is 300 characters. Enough to tell a bit about ' + 'your story and make a nice summary for your readers. It\s only allowed to truncate anything ' + 'after 300 characters. This give'; const expected = 'This is a custom excerpt. It should always be rendered in full length and not being cut ' + 'off. The maximum length of a custom excerpt is 300 characters. Enough to tell a bit about ' + 'your story and make a nice summary for your readers. It\s only allowed to truncate anything ' + 'after 300 characters. This give'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: customExcerpt }, {hash: {characters: '8'}} ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('does not truncate custom_excerpt if words options is provided', function () { const html = 'Hello World! It\'s me!
'; const customExcerpt = 'This is a custom excerpt. It should always be rendered in full length and not being cut ' + 'off. The maximum length of a custom excerpt is 300 characters. Enough to tell a bit about ' + 'your story and make a nice summary for your readers. It\s only allowed to truncate anything ' + 'after 300 characters. This give'; const expected = 'This is a custom excerpt. It should always be rendered in full length and not being cut ' + 'off. The maximum length of a custom excerpt is 300 characters. Enough to tell a bit about ' + 'your story and make a nice summary for your readers. It\s only allowed to truncate anything ' + 'after 300 characters. This give'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: customExcerpt }, {hash: {words: '10'}} ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('puts additional space after closing paragraph', function () { const html = 'Testing.
Space before this text.
And this as well!
'; const expected = 'Testing. Space before this text. And this as well!'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('puts additional space instead ofTesting.
Space before this text.
And this as well!
put space in excerpt.
before this paragraph.
' + '' + 'and skip the image.
'; const expected = 'put space in excerpt. before this paragraph. and skip the image.'; const rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); });