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
103 lines (92 loc) · 3 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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
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 * as Actions from 'actions/team_actions.jsx';
import {browserHistory} from 'utils/browser_history';
jest.mock('mattermost-redux/actions/teams', () => ({
addUsersToTeam: 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',
};
}),
}));
const store = configureStore([thunk]);
describe('Actions.Team', () => {
let testStore;
beforeEach(async () => {
testStore = store({
entities: {
channels: {
currentChannelId: 'currentChannelId',
},
},
});
});
test('switchTeam', () => {
browserHistory.push = jest.fn();
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.addUsersToTeam).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');
});
});