var should = require('should'), // jshint ignore:line getExcerpt = require('../../../server/data/meta/excerpt'); describe('getExcerpt', function () { it('should return html excerpt with no 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.'; getExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt 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.'; getExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt striping 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.'; getExcerpt(html, {}).should.equal(expected); }); it('should return html excerpt truncated by word', function () { var html = '

Hello World! It\'s me!

', expected = 'Hello World!'; getExcerpt(html, {words: '2'}).should.equal(expected); }); it('should return html excerpt truncated by words with non-ascii characters', function () { var html = '

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

', expected = 'Едквюэ опортэат'; getExcerpt(html, {words: '2'}).should.equal(expected); }); it('should return html excerpt truncated by character', function () { var html = '

Hello World! It\'s me!

', expected = 'Hello Wo'; getExcerpt(html, {characters: '8'}).should.equal(expected); }); it('should fall back to 50 words if not specified', 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.'; getExcerpt(html).should.equal(expected); }); it('should truncate plain text for custom excerpts', function () { var html = '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'; getExcerpt(html, {characters: '300'}).should.equal(expected); }); });