forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_formatting_channel_links.test.jsx
95 lines (85 loc) · 3.55 KB
/
text_formatting_channel_links.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as TextFormatting from 'utils/text_formatting.jsx';
describe('TextFormatting.ChannelLinks', () => {
test('Not channel links', () => {
expect(
TextFormatting.formatText('~123').trim()
).toBe(
'<p>~123</p>'
);
expect(
TextFormatting.formatText('~town-square').trim()
).toBe(
'<p>~town-square</p>'
);
});
describe('Channel links', () => {
afterEach(() => {
delete window.basename;
});
test('should link ~town-square', () => {
expect(
TextFormatting.formatText('~town-square', {
channelNamesMap: {'town-square': {display_name: 'Town Square'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a></p>'
);
});
test('should link ~town-square followed by a period', () => {
expect(
TextFormatting.formatText('~town-square.', {
channelNamesMap: {'town-square': {display_name: 'Town Square'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a>.</p>'
);
});
test('should link ~town-square, with display_name an HTML string', () => {
expect(
TextFormatting.formatText('~town-square', {
channelNamesMap: {'town-square': {display_name: '<b>Reception</b>'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p><a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~<b>Reception</b></a></p>'
);
});
test('should link ~town-square, with a basename defined', () => {
window.basename = '/subpath';
expect(
TextFormatting.formatText('~town-square', {
channelNamesMap: {'town-square': {display_name: '<b>Reception</b>'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p><a class="mention-link" href="/subpath/myteam/channels/town-square" data-channel-mention="town-square">~<b>Reception</b></a></p>'
);
});
test('should link in brackets', () => {
expect(
TextFormatting.formatText('(~town-square)', {
channelNamesMap: {'town-square': {display_name: 'Town Square'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p>(<a class="mention-link" href="/myteam/channels/town-square" data-channel-mention="town-square">~Town Square</a>)</p>'
);
});
});
describe('invalid channel links', () => {
test('should not link when a ~ is in the middle of a word', () => {
expect(
TextFormatting.formatText('aa~town-square', {
channelNamesMap: {'town-square': {display_name: 'Town Square'}},
team: {name: 'myteam'},
}).trim()
).toBe(
'<p>aa~town-square</p>'
);
});
});
});