-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathentities-test.js
43 lines (38 loc) · 1.74 KB
/
entities-test.js
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
import { assert } from 'chai';
import entities from '../../src/utils/entities';
describe('entities utility', () => {
it('renders a user',() => {
assert.equal(entities('Hi @first', {}), 'Hi <a href="https://twitter.com/first" target="_blank">@first</a>');
assert.equal(entities('Hi @first, @second', {}), 'Hi <a href="https://twitter.com/first" target="_blank">@first</a>, <a href="https://twitter.com/second" target="_blank">@second</a>');
});
it('renders an URL',() => {
const urls = [
{
url: 'https://first.com',
expanded_url: 'https://www.first.com',
display_url: 'first.com'
},
{
url: 'https://second.com',
expanded_url: 'https://www.second.com',
display_url: 'second.com'
},
{
url: 'https://third.com',
expanded_url: 'https://www.third.com',
display_url: 'third.com'
}
];
assert.equal(entities('Hi https://first.com', { urls }), 'Hi <a href="https://www.first.com" target="_blank">first.com</a>');
assert.equal(entities('Hi https://second.com, https://third.com', { urls }), 'Hi <a href="https://www.second.com" target="_blank">second.com</a>, <a href="https://www.third.com" target="_blank">third.com</a>');
});
it('replaces a hashtag',() => {
const hashtags = [
{ text: 'first' },
{ text: 'second' },
{ text: 'third' }
];
assert.equal(entities('Hi #first', { hashtags }), 'Hi <a href="https://twitter.com/hashtag/first?src=hash" target="_blank">#first</a>');
assert.equal(entities('Hi #second, #third', { hashtags }), `Hi <a href="https://twitter.com/hashtag/second?src=hash" target="_blank">#second</a>, <a href="https://twitter.com/hashtag/third?src=hash" target="_blank">#third</a>`);
});
});