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
/
team_actions.test.js
128 lines (112 loc) · 3.82 KB
/
team_actions.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
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as TeamActions from 'mattermost-redux/actions/teams';
import * as channelActions from 'mattermost-redux/actions/channels';
import * as userActions from 'mattermost-redux/actions/users';
import {ChannelTypes} from 'mattermost-redux/action_types';
import * as Actions from 'actions/team_actions.jsx';
import {browserHistory} from 'utils/browser_history';
jest.mock('mattermost-redux/actions/teams', () => ({
addUsersToTeamGracefully: jest.fn(() => {
return {
type: 'ADD_USER',
};
}),
removeUserFromTeam: jest.fn(() => {
return {
type: 'REMOVE_USER_FROM_TEAM',
};
}),
getTeamStats: jest.fn(() => {
return {
type: 'GET_TEAM_STATS',
};
}),
addUserToTeam: jest.fn(() => {
return {
type: 'ADD_USERS_TO_TEAM',
data: {
team_id: 'teamId',
},
};
}),
getTeam: jest.fn(() => {
return {
type: 'GET_TEAM',
};
}),
}));
jest.mock('mattermost-redux/actions/channels', () => ({
viewChannel: jest.fn(() => {
return {
type: 'VIEW_CHANNEL',
};
}),
getChannelStats: jest.fn(() => {
return {
type: 'GET_CHANNEL_STAT',
};
}),
}));
jest.mock('mattermost-redux/actions/users', () => ({
getUser: jest.fn(() => {
return {
type: 'GET_USER',
};
}),
}));
jest.mock('utils/browser_history', () => ({
browserHistory: {
push: jest.fn(),
},
}));
const store = configureStore([thunk]);
describe('Actions.Team', () => {
const currentChannelId = 'currentChannelId';
let testStore;
beforeEach(async () => {
testStore = store({
entities: {
channels: {
currentChannelId,
manuallyUnread: {},
},
},
});
});
describe('switchTeam', () => {
test('should view the current channel if it is not manually unread', () => {
testStore.dispatch(Actions.switchTeam('/test'));
expect(channelActions.viewChannel).toHaveBeenCalledWith(currentChannelId);
expect(browserHistory.push).toHaveBeenCalledWith('/test');
});
test('should not view the current channel if it is manually unread', () => {
testStore.dispatch({
type: ChannelTypes.ADD_MANUALLY_UNREAD,
data: {
channelId: currentChannelId,
},
});
testStore.dispatch(Actions.switchTeam('/test'));
expect(channelActions.viewChannel).toHaveBeenCalledWith(currentChannelId);
expect(browserHistory.push).toHaveBeenCalledWith('/test');
});
});
test('addUsersToTeam', () => {
testStore.dispatch(Actions.addUsersToTeam('teamId', ['123', '1234']));
expect(TeamActions.addUsersToTeamGracefully).toHaveBeenCalledWith('teamId', ['123', '1234']);
});
test('removeUserFromTeamAndGetStats', async () => {
await testStore.dispatch(Actions.removeUserFromTeamAndGetStats('teamId', '123'));
expect(userActions.getUser).toHaveBeenCalledWith('123');
expect(TeamActions.getTeamStats).toHaveBeenCalledWith('teamId');
expect(channelActions.getChannelStats).toHaveBeenCalledWith(currentChannelId);
});
test('addUserToTeam', async () => {
await testStore.dispatch(Actions.addUserToTeam('teamId', 'userId'));
expect(TeamActions.addUserToTeam).toHaveBeenCalledWith('teamId', 'userId');
expect(TeamActions.getTeam).toHaveBeenCalledWith('teamId');
});
});