2019-04-16 08:00:01 +05:30
|
|
|
const should = require('should');
|
|
|
|
const helperUtils = require('@tryghost/helpers').utils;
|
2017-12-13 14:05:53 +01:00
|
|
|
|
|
|
|
describe('Helpers Utils', function () {
|
|
|
|
describe('Word Count', function () {
|
|
|
|
it('[success] can count words', function () {
|
|
|
|
var html = 'Some words here',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countWords(html);
|
2017-12-13 14:05:53 +01:00
|
|
|
|
|
|
|
result.should.equal(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('[success] sanitized HTML tags', function () {
|
2018-08-03 13:02:14 +02:00
|
|
|
var html = '<p>This is a text example! Count me in ;)</p>',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countWords(html);
|
2017-12-13 14:05:53 +01:00
|
|
|
|
|
|
|
result.should.equal(8);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('[success] sanitized non alpha-numeric characters', function () {
|
2018-08-03 13:02:14 +02:00
|
|
|
var html = '<p>This is a text example! I love Döner. Especially number 875.</p>',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countWords(html);
|
2017-12-13 14:05:53 +01:00
|
|
|
|
|
|
|
result.should.equal(11);
|
|
|
|
});
|
|
|
|
|
2018-03-22 04:27:02 +01:00
|
|
|
it('[success] counted Chinese characters', function () {
|
2018-08-03 13:02:14 +02:00
|
|
|
var html = '<p>我今天在家吃了好多好多好吃的,现在的我非常开心非常满足</p>',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countWords(html);
|
2018-03-22 04:27:02 +01:00
|
|
|
|
|
|
|
result.should.equal(26);
|
|
|
|
});
|
|
|
|
|
2017-12-13 14:05:53 +01:00
|
|
|
it('[success] sanitized white space correctly', function () {
|
2018-08-03 13:02:14 +02:00
|
|
|
var html = ' <p> This is a text example!\n Count me in ;)</p> ',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countWords(html);
|
2017-12-13 14:05:53 +01:00
|
|
|
|
|
|
|
result.should.equal(8);
|
|
|
|
});
|
|
|
|
});
|
2018-03-05 09:30:15 +01:00
|
|
|
|
|
|
|
describe('Image Count', function () {
|
|
|
|
it('[success] can count images', function () {
|
2018-08-03 13:02:14 +02:00
|
|
|
var html = '<p>This is a <img src="hello.png"> text example! Count me in ;)</p><img src="hello.png">',
|
2019-04-16 08:00:01 +05:30
|
|
|
result = helperUtils.countImages(html);
|
2018-03-05 09:30:15 +01:00
|
|
|
|
|
|
|
result.should.equal(2);
|
|
|
|
});
|
|
|
|
});
|
2017-12-13 14:05:53 +01:00
|
|
|
});
|