forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
warn_metric_ack_modal.test.tsx
126 lines (104 loc) · 3.76 KB
/
warn_metric_ack_modal.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import {Modal} from 'react-bootstrap';
import {UserProfile} from 'mattermost-redux/src/types/users';
import WarnMetricAckModal from 'components/warn_metric_ack_modal/warn_metric_ack_modal';
jest.mock('react-dom', () => ({
findDOMNode: () => ({
blur: jest.fn(),
}),
}));
describe('components/WarnMetricAckModal', () => {
const serverError = 'some error';
const gettingTrialError = 'some error';
const baseProps = {
stats: {
registered_users: 200,
},
user: {
id: 'someUserId',
first_name: 'Fake',
last_name: 'Person',
email: '[email protected]',
} as UserProfile,
show: false,
diagnosticId: 'diag_0',
closeParentComponent: jest.fn(),
warnMetricStatus: {
id: 'metric1',
limit: 500,
acked: false,
},
license: {
IsLicensed: 'false',
},
enterpriseReady: false,
actions: {
closeModal: jest.fn(),
getStandardAnalytics: jest.fn(),
sendWarnMetricAck: jest.fn(),
requestTrialLicenseAndAckWarnMetric: jest.fn(),
getLicenseConfig: jest.fn(),
},
};
test('should match snapshot, init', () => {
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('error display', () => {
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...baseProps}/>,
);
wrapper.setState({serverError});
expect(wrapper).toMatchSnapshot();
});
test('should match state when onHide is called', () => {
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...baseProps}/>,
);
wrapper.setState({saving: true});
wrapper.instance().onHide();
expect(wrapper.state('saving')).toEqual(false);
});
test('should match state when onHideWithParent is called', () => {
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...baseProps}/>,
);
wrapper.setState({saving: true});
wrapper.instance().onHide();
expect(baseProps.closeParentComponent).toHaveBeenCalledTimes(1);
expect(wrapper.state('saving')).toEqual(false);
});
test('send ack on start trial button click', () => {
const props = {...baseProps};
props.enterpriseReady = true;
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...props}/>,
);
wrapper.setState({gettingTrial: false});
wrapper.find('.save-button').simulate('click');
expect(props.actions.requestTrialLicenseAndAckWarnMetric).toHaveBeenCalledTimes(1);
});
test('send ack on acknowledge button click', () => {
const props = {...baseProps};
props.enterpriseReady = false;
const wrapper = shallow<WarnMetricAckModal>(
<WarnMetricAckModal {...props}/>,
);
wrapper.setState({saving: false});
wrapper.find('.save-button').simulate('click');
expect(props.actions.sendWarnMetricAck).toHaveBeenCalledTimes(1);
});
test('should have called props.onHide when Modal.onExited is called', () => {
const props = {...baseProps};
const wrapper = shallow(
<WarnMetricAckModal {...props}/>,
);
wrapper.find(Modal).props().onExited!(document.createElement('div'));
expect(baseProps.actions.closeModal).toHaveBeenCalledTimes(1);
});
});