This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
emoticons.test.jsx
93 lines (80 loc) · 3.68 KB
/
emoticons.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as Emoticons from 'utils/emoticons.jsx';
describe('Emoticons', () => {
describe('handleEmoticons', () => {
// test emoticon patterns
const emoticonPatterns = {
slightly_smiling_face: [':)', ':-)'],
wink: [';)', ';-)'],
open_mouth: [':o'],
scream: [':-o'],
smirk: [':]', ':-]'],
smile: [':D', ':-D'],
stuck_out_tongue_closed_eyes: ['x-d'],
stuck_out_tongue: [':p', ':-p'],
rage: [':@', ':-@'],
slightly_frowning_face: [':(', ':-('],
cry: [':`(', ':\'(', ':’('],
confused: [':/', ':-/'],
confounded: [':s', ':-s'],
neutral_face: [':|', ':-|'],
flushed: [':$', ':-$'],
mask: [':-x'],
heart: ['<3', '<3'],
broken_heart: ['</3', '</3'],
thumbsup: [':+1:'],
thumbsdown: [':-1:'],
};
Array.prototype.concat(...Object.values(emoticonPatterns)).forEach((emoticon) => {
test(`text sequence '${emoticon}' should be recognized as an emoticon`, () => {
expect(Emoticons.handleEmoticons(emoticon, new Map())).toEqual('$MM_EMOTICON0$');
});
});
// test various uses of emoticons
test('should replace emoticons with tokens', () => {
expect(Emoticons.handleEmoticons(':goat: :dash:', new Map())).
toEqual('$MM_EMOTICON0$ $MM_EMOTICON1$');
});
test('should replace emoticons not separated by whitespace', () => {
expect(Emoticons.handleEmoticons(':goat::dash:', new Map())).
toEqual('$MM_EMOTICON0$$MM_EMOTICON1$');
});
test('should replace emoticons separated by punctuation', () => {
expect(Emoticons.handleEmoticons('/:goat:..:dash:)', new Map())).
toEqual('/$MM_EMOTICON0$..$MM_EMOTICON1$)');
});
test('should replace emoticons separated by text', () => {
expect(Emoticons.handleEmoticons('asdf:goat:asdf:dash:asdf', new Map())).
toEqual('asdf$MM_EMOTICON0$asdf$MM_EMOTICON1$asdf');
});
test('shouldn\'t replace invalid emoticons', () => {
expect(Emoticons.handleEmoticons(':goat : : dash:', new Map())).
toEqual(':goat : : dash:');
});
test('should allow comma immediately following emoticon :)', () => {
expect(Emoticons.handleEmoticons(':),', new Map())).
toEqual('$MM_EMOTICON0$,');
});
test('should allow comma immediately following emoticon :P', () => {
expect(Emoticons.handleEmoticons(':P,', new Map())).
toEqual('$MM_EMOTICON0$,');
});
test('should allow punctuation immediately following emoticon :)', () => {
expect(Emoticons.handleEmoticons(':)!', new Map())).
toEqual('$MM_EMOTICON0$!');
});
test('should allow punctuation immediately following emoticon :P', () => {
expect(Emoticons.handleEmoticons(':P!', new Map())).
toEqual('$MM_EMOTICON0$!');
});
test('should allow punctuation immediately before and following emoticon :)', () => {
expect(Emoticons.handleEmoticons('":)"', new Map())).
toEqual('"$MM_EMOTICON0$"');
});
test('should allow punctuation immediately before and following emoticon :P', () => {
expect(Emoticons.handleEmoticons('":P"', new Map())).
toEqual('"$MM_EMOTICON0$"');
});
});
});