forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_html_to_component.test.jsx
107 lines (81 loc) · 4.04 KB
/
message_html_to_component.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import Constants from 'utils/constants.jsx';
import messageHtmlToComponent from 'utils/message_html_to_component';
import * as TextFormatting from 'utils/text_formatting';
import MarkdownImage from 'components/markdown_image';
import AtMention from 'components/at_mention';
describe('messageHtmlToComponent', () => {
test('plain text', () => {
const input = 'Hello, world!';
const html = TextFormatting.formatText(input);
expect(messageHtmlToComponent(html)).toMatchSnapshot();
});
test('latex', () => {
const input = `This is some latex!
\`\`\`latex
x^2 + y^2 = z^2
\`\`\`
\`\`\`latex
F_m - 2 = F_0 F_1 \\dots F_{m-1}
\`\`\`
That was some latex!`;
const html = TextFormatting.formatText(input);
expect(messageHtmlToComponent(html)).toMatchSnapshot();
});
test('link without enabled tooltip plugins', () => {
const input = 'lorem ipsum www.dolor.com sit amet';
const html = TextFormatting.formatText(input);
expect(messageHtmlToComponent(html)).toMatchSnapshot();
});
test('link with enabled a tooltip plugin', () => {
const input = 'lorem ipsum www.dolor.com sit amet';
const html = TextFormatting.formatText(input);
expect(messageHtmlToComponent(html, false, {hasPluginTooltips: true})).toMatchSnapshot();
});
test('Inline markdown image', () => {
const options = {markdown: true};
const html = TextFormatting.formatText('![Mattermost](/images/icon.png) and a [link](link)', options);
const component = messageHtmlToComponent(html, false, {hasPluginTooltips: false,
postId: 'post_id',
postType: Constants.PostTypes.HEADER_CHANGE,
});
expect(component).toMatchSnapshot();
expect(shallow(component).find(MarkdownImage).prop('imageIsLink')).toBe(false);
});
test('Inline markdown image where image is link', () => {
const options = {markdown: true};
const html = TextFormatting.formatText('[![Mattermost](images/icon.png)](images/icon.png)', options);
const component = messageHtmlToComponent(html, false, {hasPluginTooltips: false,
postId: 'post_id',
postType: Constants.PostTypes.HEADER_CHANGE,
});
expect(component).toMatchSnapshot();
expect(shallow(component).find(MarkdownImage).prop('imageIsLink')).toBe(true);
});
test('At mention', () => {
const options = {mentionHighlight: true, atMentions: true, mentionKeys: [{key: '@joram'}]};
let html = TextFormatting.formatText('@joram', options);
let component = messageHtmlToComponent(html, false, {mentionHighlight: true});
expect(component).toMatchSnapshot();
expect(shallow(component).find(AtMention).prop('disableHighlight')).toBe(false);
options.mentionHighlight = false;
html = TextFormatting.formatText('@joram', options);
component = messageHtmlToComponent(html, false, {mentionHighlight: false});
expect(component).toMatchSnapshot();
expect(shallow(component).find(AtMention).prop('disableHighlight')).toBe(true);
});
test('At mention with group highlight disabled', () => {
const options = {mentionHighlight: true, atMentions: true, mentionKeys: [{key: '@joram'}]};
let html = TextFormatting.formatText('@developers', options);
let component = messageHtmlToComponent(html, false, {disableGroupHighlight: false});
expect(component).toMatchSnapshot();
expect(shallow(component).find(AtMention).prop('disableGroupHighlight')).toBe(false);
options.disableGroupHighlight = true;
html = TextFormatting.formatText('@developers', options);
component = messageHtmlToComponent(html, false, {disableGroupHighlight: true});
expect(component).toMatchSnapshot();
expect(shallow(component).find(AtMention).prop('disableGroupHighlight')).toBe(true);
});
});