-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
51 lines (49 loc) · 1.28 KB
/
index.test.ts
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
import { splitMentionsAndText, getMentionIdAndName } from './index';
describe('planyard-mentions', () => {
const mention = '@(1)[I am a long name]';
describe('splitMentionsAndText', () => {
it('should work without mentions', () => {
const input = 'string with \n newline';
expect(splitMentionsAndText(input)).toEqual([input]);
});
it('should work with one mention', () => {
const input = mention;
expect(splitMentionsAndText(input)).toEqual([
'',
input,
'',
]);
});
it('should work with multiple mentions', () => {
const input = `${mention} ${mention}`;
expect(splitMentionsAndText(input)).toEqual([
'',
mention,
' ',
mention,
'',
]);
});
it('should work with multiple mentions and text', () => {
const input = `Hey ${mention}, look at ${mention}'s invoice.`;
expect(splitMentionsAndText(input)).toEqual([
'Hey ',
mention,
', look at ',
mention,
'\'s invoice.',
]);
});
});
describe('getMentionIdAndName', () => {
it('should return null if no match', () => {
expect(getMentionIdAndName('random string')).toEqual(null);
});
it('should return object with id and name if ', () => {
expect(getMentionIdAndName(mention)).toEqual({
id: '1',
name: 'I am a long name',
});
});
});
});