2017-01-11 16:45:22 +03:00
|
|
|
import {countCharacters} from 'ghost-admin/helpers/gh-count-characters';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2017-01-11 16:45:22 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Unit: Helper: gh-count-characters', function () {
|
2017-05-17 15:24:31 +03:00
|
|
|
let defaultStyle = 'color: rgb(115, 138, 148);';
|
|
|
|
let errorStyle = 'color: rgb(240, 82, 48);';
|
2017-01-11 16:45:22 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
it('counts remaining chars', function () {
|
2017-01-11 16:45:22 +03:00
|
|
|
let result = countCharacters(['test']);
|
|
|
|
expect(result.string)
|
|
|
|
.to.equal(`<span class="word-count" style="${defaultStyle}">196</span>`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('warns when nearing limit', function () {
|
|
|
|
let result = countCharacters([Array(195 + 1).join('x')]);
|
|
|
|
expect(result.string)
|
|
|
|
.to.equal(`<span class="word-count" style="${errorStyle}">5</span>`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('indicates too many chars', function () {
|
|
|
|
let result = countCharacters([Array(205 + 1).join('x')]);
|
|
|
|
expect(result.string)
|
|
|
|
.to.equal(`<span class="word-count" style="${errorStyle}">-5</span>`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('counts multibyte correctly', function () {
|
|
|
|
let result = countCharacters(['💩']);
|
|
|
|
expect(result.string)
|
|
|
|
.to.equal(`<span class="word-count" style="${defaultStyle}">199</span>`);
|
|
|
|
|
|
|
|
// emoji + modifier is still two chars
|
|
|
|
result = countCharacters(['💃🏻']);
|
|
|
|
expect(result.string)
|
|
|
|
.to.equal(`<span class="word-count" style="${defaultStyle}">198</span>`);
|
|
|
|
});
|
|
|
|
});
|