forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_menu.test.tsx
255 lines (216 loc) · 8.45 KB
/
dot_menu.test.tsx
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {PostType} from 'mattermost-redux/types/posts';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {Locations, PostTypes} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import DotMenu, {PLUGGABLE_COMPONENT, DotMenuClass} from './dot_menu';
describe('components/dot_menu/DotMenu', () => {
const baseProps = {
post: TestHelper.getPostMock({id: 'post_id_1', is_pinned: false, type: '' as PostType}),
isLicensed: false,
postEditTimeLimit: '-1',
handleCommentClick: jest.fn(),
handleDropdownOpened: jest.fn(),
enableEmojiPicker: true,
components: {},
channelIsArchived: false,
currentTeamUrl: '',
actions: {
flagPost: jest.fn(),
unflagPost: jest.fn(),
setEditingPost: jest.fn(),
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
doAppCall: jest.fn(),
postEphemeralCallResponseForPost: jest.fn(),
setThreadFollow: jest.fn(),
openAppsModal: jest.fn(),
fetchBindings: jest.fn(),
},
canEdit: false,
canDelete: false,
appBindings: [],
pluginMenuItems: [],
appsEnabled: false,
isReadOnly: false,
teamId: 'team_id_1',
isFollowingThread: false,
isCollapsedThreadsEnabled: false,
isMobileView: false,
threadId: 'post_id_1',
threadReplyCount: 0,
userId: 'user_id_1',
};
test('should match snapshot, on Center', () => {
const props = {
...baseProps,
canEdit: true,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper).toMatchSnapshot();
const instance = wrapper.instance();
const setStateMock = jest.fn();
instance.setState = setStateMock;
(wrapper.instance() as DotMenuClass).handleEditDisable();
expect(setStateMock).toBeCalledWith({canEdit: false});
});
test('should match snapshot, canDelete', () => {
const props = {
...baseProps,
canEdit: true,
canDelete: true,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should have divider when able to edit or delete post', () => {
const props = {
...baseProps,
canEdit: true,
canDelete: true,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.state('canEdit')).toBe(true);
expect(wrapper.state('canDelete')).toBe(true);
expect(wrapper.find('#divider_post_post_id_1_edit').exists()).toBe(true);
wrapper.setProps({isReadOnly: true});
expect(wrapper.state('canEdit')).toBe(false);
expect(wrapper.state('canDelete')).toBe(false);
expect(wrapper.find('#divider_post_post_id_1_edit').exists()).toBe(false);
});
test('should not have divider when able to edit or delete a system message', () => {
const props = {
...baseProps,
post: TestHelper.getPostMock({
...baseProps.post,
type: PostTypes.JOIN_CHANNEL as PostType,
}),
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.find('#divider_post_post_id_1_edit').exists()).toBe(false);
});
test('should have divider when plugin menu item exists', () => {
const wrapper = shallowWithIntl(
<DotMenu {...baseProps}/>,
);
expect(wrapper.find('#divider_post_post_id_1_plugins').exists()).toBe(false);
wrapper.setProps({
pluginMenuItems: [
{id: 'test_plugin_menu_item_1', text: 'woof'},
],
});
expect(wrapper.find('#divider_post_post_id_1_plugins').exists()).toBe(true);
});
test('should have divider when pluggable menu item exists', () => {
const wrapper = shallowWithIntl(
<DotMenu {...baseProps}/>,
);
expect(wrapper.find('#divider_post_post_id_1_plugins').exists()).toBe(false);
wrapper.setProps({
components: {
[PLUGGABLE_COMPONENT]: [{}],
},
});
expect(wrapper.find('#divider_post_post_id_1_plugins').exists()).toBe(true);
});
test('should show mark as unread when channel is not archived', () => {
const wrapper = shallowWithIntl(
<DotMenu {...baseProps}/>,
);
expect(wrapper.find(`#unread_post_${baseProps.post.id}`).prop('show')).toBe(true);
});
test('should not show mark as unread when channel is archived', () => {
const props = {
...baseProps,
channelIsArchived: true,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.find(`#unread_post_${baseProps.post.id}`).prop('show')).toBe(false);
});
test('should not show mark as unread in search', () => {
const props = {
...baseProps,
location: Locations.SEARCH,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.find(`#unread_post_${baseProps.post.id}`).prop('show')).toBe(false);
});
describe('RHS', () => {
test.each([
[true, {location: Locations.RHS_ROOT, isCollapsedThreadsEnabled: true}],
[true, {location: Locations.RHS_COMMENT, isCollapsedThreadsEnabled: true}],
[true, {location: Locations.CENTER, isCollapsedThreadsEnabled: true}],
[false, {location: Locations.RHS_ROOT, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.RHS_COMMENT, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.CENTER, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.SEARCH, isCollapsedThreadsEnabled: true}],
[false, {location: Locations.NO_WHERE, isCollapsedThreadsEnabled: true}],
])('follow message/thread menu item should be shown only in RHS and center channel when CRT is enabled', (showing, caseProps) => {
const props = {
...baseProps,
...caseProps,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.find(`#follow_post_thread_${baseProps.post.id}`).prop('show')).toBe(showing);
});
test.each([
['Follow message', {isFollowingThread: false, threadReplyCount: 0}],
['Unfollow message', {isFollowingThread: true, threadReplyCount: 0}],
['Follow thread', {isFollowingThread: false, threadReplyCount: 1}],
['Unfollow thread', {isFollowingThread: true, threadReplyCount: 1}],
])('should show correct text', (text, caseProps) => {
const props = {
...baseProps,
...caseProps,
location: Locations.RHS_ROOT,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper.find(`#follow_post_thread_${baseProps.post.id}`).prop('text')).toBe(text);
});
test.each([
[false, {isFollowingThread: true}],
[true, {isFollowingThread: false}],
])('should call setThreadFollow with following as %s', (following, caseProps) => {
const spySetThreadFollow = jest.fn();
const props = {
...baseProps,
...caseProps,
location: Locations.RHS_ROOT,
actions: {
...baseProps.actions,
setThreadFollow: spySetThreadFollow,
},
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
wrapper.find(`#follow_post_thread_${baseProps.post.id}`).simulate('click');
expect(spySetThreadFollow).toHaveBeenCalledWith(
'user_id_1',
'team_id_1',
'post_id_1',
following,
);
});
});
});