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
/
text_formatting_at_mentions.test.jsx
156 lines (140 loc) · 7.12 KB
/
text_formatting_at_mentions.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import * as TextFormatting from 'utils/text_formatting.jsx';
describe('TextFormatting.AtMentions', () => {
it('At mentions', () => {
assert.equal(
TextFormatting.autolinkAtMentions('@user', new Map()),
'$MM_ATMENTION0$',
'should replace mention with token'
);
assert.equal(
TextFormatting.autolinkAtMentions('abc"@user"def', new Map()),
'abc"$MM_ATMENTION0$"def',
'should replace mention surrounded by punctuation with token'
);
assert.equal(
TextFormatting.autolinkAtMentions('@user1 @user2', new Map()),
'$MM_ATMENTION0$ $MM_ATMENTION1$',
'should replace multiple mentions with tokens'
);
assert.equal(
TextFormatting.autolinkAtMentions('@user1/@user2/@user3', new Map()),
'$MM_ATMENTION0$/$MM_ATMENTION1$/$MM_ATMENTION2$',
'should replace multiple mentions with tokens'
);
assert.equal(
TextFormatting.autolinkAtMentions('@us_-e.r', new Map()),
'$MM_ATMENTION0$',
'should replace multiple mentions containing punctuation with token'
);
assert.equal(
TextFormatting.autolinkAtMentions('@user.', new Map()),
'$MM_ATMENTION0$',
'should capture trailing punctuation as part of mention'
);
assert.equal(
TextFormatting.autolinkAtMentions('@foo.com @bar.com', new Map()),
'$MM_ATMENTION0$ $MM_ATMENTION1$',
'should capture two at mentions with space in between'
);
assert.equal(
TextFormatting.autolinkAtMentions('@[email protected]', new Map()),
'$MM_ATMENTION0$$MM_ATMENTION1$',
'should capture two at mentions without space in between'
);
assert.equal(
TextFormatting.autolinkAtMentions('@[email protected]@baz.com', new Map()),
'$MM_ATMENTION0$$MM_ATMENTION1$$MM_ATMENTION2$',
'should capture multiple at mentions without space in between'
);
});
it('Not at mentions', () => {
assert.equal(
TextFormatting.autolinkAtMentions('user@host', new Map()),
'user@host'
);
assert.equal(
TextFormatting.autolinkAtMentions('[email protected]', new Map()),
);
assert.equal(
TextFormatting.autolinkAtMentions('@', new Map()),
'@'
);
assert.equal(
TextFormatting.autolinkAtMentions('@ ', new Map()),
'@ '
);
assert.equal(
TextFormatting.autolinkAtMentions(':@', new Map()),
':@'
);
});
it('Highlighted at mentions', () => {
assert.equal(
TextFormatting.formatText('@user', {atMentions: true, mentionKeys: [{key: '@user'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="user">@user</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@channel', {atMentions: true, mentionKeys: [{key: '@channel'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="channel">@channel</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@all', {atMentions: true, mentionKeys: [{key: '@all'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="all">@all</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@USER', {atMentions: true, mentionKeys: [{key: '@user'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="USER">@USER</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@CHanNEL', {atMentions: true, mentionKeys: [{key: '@channel'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="CHanNEL">@CHanNEL</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@ALL', {atMentions: true, mentionKeys: [{key: '@all'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="ALL">@ALL</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@foo.com', {atMentions: true, mentionKeys: [{key: '@foo.com'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="foo.com">@foo.com</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@foo.com @bar.com', {atMentions: true, mentionKeys: [{key: '@foo.com'}, {key: '@bar.com'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="foo.com">@foo.com</span></span> <span class="mention--highlight"><span data-mention="bar.com">@bar.com</span></span></p>',
);
assert.equal(
TextFormatting.formatText('@[email protected]', {atMentions: true, mentionKeys: [{key: '@foo.com'}, {key: '@bar.com'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="foo.com">@foo.com</span></span><span class="mention--highlight"><span data-mention="bar.com">@bar.com</span></span></p>',
);
});
it('Mix highlight at mentions', () => {
assert.equal(
TextFormatting.formatText('@foo.com @bar.com', {atMentions: true, mentionKeys: [{key: '@foo.com'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="foo.com">@foo.com</span></span> <span data-mention="bar.com">@bar.com</span></p>',
'should highlight first at mention, with space in between'
);
assert.equal(
TextFormatting.formatText('@foo.com @bar.com', {atMentions: true, mentionKeys: [{key: '@bar.com'}]}).trim(),
'<p><span data-mention="foo.com">@foo.com</span> <span class="mention--highlight"><span data-mention="bar.com">@bar.com</span></span></p>',
'should highlight second at mention, with space in between'
);
assert.equal(
TextFormatting.formatText('@[email protected]', {atMentions: true, mentionKeys: [{key: '@foo.com'}]}).trim(),
'<p><span class="mention--highlight"><span data-mention="foo.com">@foo.com</span></span><span data-mention="bar.com">@bar.com</span></p>',
'should highlight first at mention, without space in between'
);
assert.equal(
TextFormatting.formatText('@[email protected]', {atMentions: true, mentionKeys: [{key: '@bar.com'}]}).trim(),
'<p><span data-mention="foo.com">@foo.com</span><span class="mention--highlight"><span data-mention="bar.com">@bar.com</span></span></p>',
'should highlight second at mention, without space in between'
);
assert.equal(
TextFormatting.formatText('@[email protected]', {atMentions: true, mentionKeys: [{key: '@user'}]}).trim(),
'<p><span data-mention="foo.com">@foo.com</span><span data-mention="bar.com">@bar.com</span></p>',
'should not highlight any at mention'
);
});
});