forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_menu.test.tsx
175 lines (149 loc) · 5.54 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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow, ShallowWrapper} from 'enzyme';
import {PostType} from 'mattermost-redux/types/posts';
import React from 'react';
import {Locations, PostTypes} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import DotMenu, {PLUGGABLE_COMPONENT} from './dot_menu';
jest.mock('utils/utils', () => {
const original = jest.requireActual('utils/utils');
return {
...original,
isMobile: jest.fn(() => false),
};
});
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(),
},
canEdit: false,
canDelete: false,
appBindings: [],
pluginMenuItems: [],
appsEnabled: false,
};
test('should match snapshot, on Center', () => {
const props = {
...baseProps,
canEdit: true,
};
const wrapper: ShallowWrapper<any, any, DotMenu> = shallow(
<DotMenu {...props}/>,
);
expect(wrapper).toMatchSnapshot();
const instance = wrapper.instance();
const setStateMock = jest.fn();
instance.setState = setStateMock;
wrapper.instance().handleEditDisable();
expect(setStateMock).toBeCalledWith({canEdit: false});
});
test('should match snapshot, canDelete', () => {
const props = {
...baseProps,
canEdit: true,
canDelete: true,
};
const wrapper: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<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: ShallowWrapper<any, any, DotMenu> = shallow(
<DotMenu {...props}/>,
);
expect(wrapper.find(`#unread_post_${baseProps.post.id}`).prop('show')).toBe(false);
});
});