signal-desktop/ts/test-node/util/splitText_test.ts
Fedor Indutny d811dd1ed4
Username UI Improvements
Co-authored-by: Fedor Indutny <238531+indutny@users.noreply.github.com>
2024-01-25 15:48:44 -08:00

59 lines
1.5 KiB
TypeScript

// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import type { SplitTextOptionsType } from '../../util/splitText';
import { splitText } from '../../util/splitText';
describe('splitText', () => {
describe('grapheme granularity', () => {
const options: SplitTextOptionsType = {
granularity: 'grapheme',
shouldBreak: x => x.length > 6,
};
it('splits text into one line', () => {
assert.deepEqual(splitText('signal', options), ['signal']);
});
it('splits text into two lines', () => {
assert.deepEqual(splitText('signal.0123', options), ['signal', '.0123']);
});
it('splits text into three lines', () => {
assert.deepEqual(splitText('signal.01234567', options), [
'signal',
'.01234',
'567',
]);
});
});
describe('word granularity', () => {
const options: SplitTextOptionsType = {
granularity: 'word',
shouldBreak: x => x.length > 6,
};
it('splits text into one line', () => {
assert.deepEqual(splitText('signal', options), ['signal']);
});
it('splits text into two lines', () => {
assert.deepEqual(splitText('signal.0123', options), ['signal.', '0123']);
});
it('splits text into three lines', () => {
assert.deepEqual(splitText('aaaaaa b b ccccc', options), [
'aaaaaa',
'b b',
'ccccc',
]);
});
it('trims lines', () => {
assert.deepEqual(splitText('signa 0123', options), ['signa', '0123']);
});
});
});