mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 09:50:34 +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
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
import {expect} from 'chai';
|
|
import {describe, it} from 'mocha';
|
|
import {countDownCharacters} from 'ghost-admin/helpers/gh-count-down-characters';
|
|
|
|
describe('Unit: Helper: gh-count-down-characters', function() {
|
|
let validStyle = 'color: rgb(159, 187, 88);';
|
|
let errorStyle = 'color: rgb(226, 84, 64);';
|
|
|
|
it('counts chars', function() {
|
|
let result = countDownCharacters(['test', 200]);
|
|
expect(result.string)
|
|
.to.equal(`<span class="word-count" style="${validStyle}">4</span>`);
|
|
});
|
|
|
|
it('warns with too many chars', function () {
|
|
let result = countDownCharacters([Array(205 + 1).join('x'), 200]);
|
|
expect(result.string)
|
|
.to.equal(`<span class="word-count" style="${errorStyle}">205</span>`);
|
|
});
|
|
|
|
it('counts multibyte correctly', function () {
|
|
let result = countDownCharacters(['💩', 200]);
|
|
expect(result.string)
|
|
.to.equal(`<span class="word-count" style="${validStyle}">1</span>`);
|
|
|
|
// emoji + modifier is still two chars
|
|
result = countDownCharacters(['💃🏻', 200]);
|
|
expect(result.string)
|
|
.to.equal(`<span class="word-count" style="${validStyle}">2</span>`);
|
|
});
|
|
});
|