Better emoji support in linkify/previews

This commit is contained in:
Fedor Indutny 2021-06-30 10:00:02 -07:00 committed by GitHub
parent 65ad608aa7
commit 773aa9af19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 337 additions and 260 deletions

View file

@ -0,0 +1,53 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { replaceEmojiWithSpaces, splitByEmoji } from '../../util/emoji';
describe('emoji', () => {
describe('replaceEmojiWithSpaces', () => {
it('replaces emoji and pictograms with a single space', () => {
assert.strictEqual(
replaceEmojiWithSpaces('hello🌀🐀🔀😀world'),
'hello world'
);
});
it('leaves regular text as it is', () => {
assert.strictEqual(
replaceEmojiWithSpaces('Привет 嘿 հեյ העלא مرحبا '),
'Привет 嘿 հեյ העלא مرحبا '
);
});
});
describe('splitByEmoji', () => {
it('replaces emoji and pictograms with a single space', () => {
assert.deepStrictEqual(splitByEmoji('hello😛world😎😛!'), [
{ type: 'text', value: 'hello' },
{ type: 'emoji', value: '😛' },
{ type: 'text', value: 'world' },
{ type: 'emoji', value: '😎' },
{ type: 'text', value: '' },
{ type: 'emoji', value: '😛' },
{ type: 'text', value: '!' },
]);
});
it('should return empty string after split at the end', () => {
assert.deepStrictEqual(splitByEmoji('hello😛'), [
{ type: 'text', value: 'hello' },
{ type: 'emoji', value: '😛' },
{ type: 'text', value: '' },
]);
});
it('should return empty string before the split at the start', () => {
assert.deepStrictEqual(splitByEmoji('😛hello'), [
{ type: 'text', value: '' },
{ type: 'emoji', value: '😛' },
{ type: 'text', value: 'hello' },
]);
});
});
});