forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.test.jsx
55 lines (45 loc) · 1.74 KB
/
root.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import Root from 'components/root/root';
import * as GlobalActions from 'actions/global_actions.jsx';
jest.mock('fastclick', () => ({
attach: () => {}, // eslint-disable-line no-empty-function
}));
jest.mock('actions/diagnostics_actions', () => ({
trackLoadTime: () => {}, // eslint-disable-line no-empty-function
}));
jest.mock('actions/global_actions', () => ({
redirectUserToDefaultTeam: jest.fn(),
}));
describe('components/Root', () => {
const baseProps = {
diagnosticsEnabled: true,
diagnosticId: '1234ab',
noAccounts: false,
showTermsOfService: false,
actions: {
loadMeAndConfig: async () => {}, // eslint-disable-line no-empty-function
},
};
test('should load user, config, and license on mount and redirect to defaultTeam on success', (done) => {
const props = {
...baseProps,
actions: {
...baseProps.actions,
loadMeAndConfig: jest.fn(baseProps.actions.loadMeAndConfig),
},
};
// Mock the method by extending the class because we don't have a chance to do it before shallow mounts the component
class MockedRoot extends Root {
onConfigLoaded = jest.fn(() => {
expect(this.onConfigLoaded).toHaveBeenCalledTimes(1);
expect(GlobalActions.redirectUserToDefaultTeam).toHaveBeenCalledTimes(1);
done();
});
}
shallow(<MockedRoot {...props}/>);
expect(props.actions.loadMeAndConfig).toHaveBeenCalledTimes(1);
});
});