This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
popover_list_members.test.jsx
113 lines (93 loc) · 3.47 KB
/
popover_list_members.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
108
109
110
111
112
113
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import Constants from 'utils/constants';
import PopoverListMembers from 'components/popover_list_members/popover_list_members.jsx';
jest.mock('utils/browser_history', () => {
const original = jest.requireActual('utils/browser_history');
return {
...original,
browserHistory: {
push: jest.fn(),
},
};
});
describe('components/PopoverListMembers', () => {
const channel = {
id: 'channel_id',
name: 'channel-name',
display_name: 'Channel Name',
type: Constants.DM_CHANNEl,
};
const users = [
{id: 'member_id_1', delete_at: 0},
{id: 'member_id_2', delete_at: 0},
{id: 'member_id_3', delete_at: 1234},
];
const statuses = {
member_id_1: 'online',
member_id_2: 'offline',
};
const actions = {
loadProfilesAndStatusesInChannel: jest.fn(),
openDirectChannelToUserId: jest.fn().mockResolvedValue({data: {name: 'channelname'}}),
openModal: jest.fn(),
};
const baseProps = {
channel,
statuses,
users,
manageMembers: true,
memberCount: 2,
currentUserId: 'current_user_id',
actions,
sortedUsers: [{id: 'member_id_1', delete_at: 0}, {id: 'member_id_2', delete_at: 0}, {id: 'member_id_3', delete_at: 1234}],
};
test('should match snapshot', () => {
const wrapper = shallow(
<PopoverListMembers {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should have called openDirectChannelToUserId when handleShowDirectChannel is called', (done) => {
const browserHistory = require('utils/browser_history').browserHistory; //eslint-disable-line global-require
const wrapper = shallow(
<PopoverListMembers {...baseProps}/>,
);
wrapper.instance().closePopover = jest.fn();
wrapper.instance().handleShowDirectChannel({
id: 'teammateId',
});
expect(baseProps.actions.openDirectChannelToUserId).toHaveBeenCalledTimes(1);
process.nextTick(() => {
expect(browserHistory.push).toHaveBeenCalledTimes(1);
expect(browserHistory.push).toHaveBeenCalledWith(`${baseProps.teamUrl}/channels/channelname`);
expect(wrapper.state('showPopover')).toEqual(false);
done();
});
});
test('should match state when closePopover is called', () => {
const wrapper = shallow(
<PopoverListMembers {...baseProps}/>,
);
wrapper.instance().componentDidUpdate = jest.fn();
wrapper.setState({showPopover: true});
wrapper.instance().closePopover();
expect(wrapper.state('showPopover')).toEqual(false);
});
test('should match snapshot with archived channel', () => {
const props = {...baseProps, channel: {...channel, delete_at: 1234}};
const wrapper = shallow(
<PopoverListMembers {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with group-constrained channel', () => {
const props = {...baseProps, channel: {...channel, group_constrained: true}};
const wrapper = shallow(
<PopoverListMembers {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
});