var should = require('should'), // Stuff we are testing helpers = require('../../../frontend/helpers'); describe('{{excerpt}} Helper', function () { it('renders empty string when html and excerpt are null', function () { var html = null, rendered = helpers.excerpt.call({ html: html, custom_excerpt: null }); should.exist(rendered); rendered.string.should.equal(''); }); it('can render excerpt', function () { var html = 'Hello World', rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(html); }); it('does not output HTML', function () { var html = '

There are
10
types
of people in the world:' + 'c those who ' + 'understand trinary,

those who don\'t
and' + '< test > those<<< test >>> who mistake it <for> binary.', expected = 'There are 10 types of people in the world: those who understand trinary, those who ' + 'don\'t and those>> who mistake it <for> binary.', rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(expected); }); it('strips multiple inline footnotes', function () { var html = '

Testing1, my footnotes. And stuff. Footnote2with a link right after.', expected = 'Testing, my footnotes. And stuff. Footnotewith a link right after.', rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(expected); }); it('strips inline and bottom footnotes', function () { var html = '

Testing1 a very short post with a single footnote.

\n' + '
  1. https://ghost.org

', expected = 'Testing a very short post with a single footnote.', rendered = helpers.excerpt.call({ html: html, custom_excerpt: '' }); should.exist(rendered); rendered.string.should.equal(expected); }); it('can truncate html by word', function () { var html = '

Hello World! It\'s me!

', expected = 'Hello World!', 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 () { var html = '

Едквюэ опортэат праэчынт ючю но, квуй эю

', expected = 'Едквюэ опортэат', 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 () { var html = '

Hello World! It\'s me!

', expected = 'Hello Wo', 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 () { var html = '

Hello World! It\'s me!

', customExcerpt = 'My Custom Excerpt wins!', expected = 'My Custom Excerpt wins!', 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 () { var html = '

Hello World! It\'s me!

', 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', 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', 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 () { var html = '

Hello World! It\'s me!

', 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', 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', 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 () { var html = '

Testing.

Space before this text.

And this as well!

', expected = 'Testing. Space before this text. And this as well!', rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('puts additional space instead of
tag', function () { var html = '

Testing.
Space before this text.
And this as well!

', expected = 'Testing. Space before this text. And this as well!', rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); it('puts additional space between paragraph in markup generated by Ghost', function () { var html = '

put space in excerpt.

before this paragraph.

' + '
' + '

and skip the image.

', expected = 'put space in excerpt. before this paragraph. and skip the image.', rendered = ( helpers.excerpt.call( { html: html, custom_excerpt: '' } ) ); should.exist(rendered); rendered.string.should.equal(expected); }); });