mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
b1c94c6397
closes https://github.com/TryGhost/Ghost/issues/7739 - use es6's `Array.from` to convert the string to an array to get a symbol count rather than a byte count
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
import {expect} from 'chai';
|
|
import {describe, it} from 'mocha';
|
|
import {countCharacters} from 'ghost-admin/helpers/gh-count-characters';
|
|
|
|
describe('Unit: Helper: gh-count-characters', function() {
|
|
let defaultStyle = 'color: rgb(158, 157, 149);';
|
|
let errorStyle = 'color: rgb(226, 84, 64);';
|
|
|
|
it('counts remaining chars', function() {
|
|
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>`);
|
|
});
|
|
});
|