summaryrefslogtreecommitdiffstats
path: root/webapp/tests/utils/formatting_at_mentions.test.jsx
blob: e9147b565408b3593a5973301570021524bd8eda (plain)
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
// Copyright (c) 2016-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', function() {
    it('At mentions', function() {
        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'
        );
    });

    it('Not at mentions', function() {
        assert.equal(
            TextFormatting.autolinkAtMentions('user@host', new Map()),
            'user@host'
        );

        assert.equal(
            TextFormatting.autolinkAtMentions('user@email.com', new Map()),
            'user@email.com'
        );
    });
});