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
|
// @flow
import * as React from 'react';
import Support from '../../app/components/Support';
import { shallow } from 'enzyme';
import type { SupportProps } from '../../app/components/Support';
describe('components/Support', () => {
it('should call close callback', () => {
const props = makeProps({ onClose: spy() });
const component = shallow(<Support {...props} />);
const closeButton = component.find({ testName: 'support__close' });
click(closeButton);
expect(props.onClose).to.have.been.called.once;
});
it('should call view logs callback', async () => {
const props = makeProps({ viewLog: spy() });
const component = shallow(<Support {...props} />);
const viewButton = component.find({ testName: 'support__view_logs' });
await click(viewButton);
expect(props.viewLog).to.have.been.called.once;
});
it('should call send callback when description filled in', async () => {
const props = makeProps({
defaultEmail: 'foo',
defaultMessage: 'abc',
sendProblemReport: spy((_report) => Promise.resolve()),
});
const component = shallow(<Support {...props} />);
const sendButton = component.find({ testName: 'support__send_logs' });
expect(sendButton.prop('disabled')).to.be.false;
await click(sendButton);
expect(props.sendProblemReport).to.have.been.called.once;
});
it('should not call send callback when description is empty', () => {
const props = makeProps({ defaultMessage: '' });
const component = shallow(<Support {...props} />);
const sendButton = component.find({ testName: 'support__send_logs' });
expect(sendButton.prop('disabled')).to.be.true;
});
it('should not collect report twice', async () => {
const props = makeProps({
collectProblemReport: spy(() => Promise.resolve('/path/to/problem/report')),
});
const component = shallow(<Support {...props} />);
const viewButton = component.find({ testName: 'support__view_logs' });
await Promise.all([click(viewButton), click(viewButton)]);
expect(props.collectProblemReport).to.have.been.called.once;
});
it('should collect report on submission', async () => {
const props = makeProps({
defaultMessage: '',
defaultEmail: 'foo',
collectProblemReport: spy(() => Promise.resolve('/path/to/problem/report')),
sendProblemReport: spy(() => Promise.resolve()),
});
const component = shallow(<Support {...props} />);
const sendButton = component.find({ testName: 'support__send_logs' });
await click(sendButton);
expect(props.collectProblemReport).to.have.been.called.once;
expect(props.sendProblemReport).to.have.been.called.once;
});
it('should save the report form on change', () => {
const props = makeProps({
defaultEmail: 'email@domain',
defaultMessage: 'test message',
sendProblemReport: () => Promise.reject(new Error('Simulation')),
saveReportForm: spy(),
});
const component = shallow(<Support {...props} />);
const input = component.find({ testName: 'support__form_message' });
input.simulate('changeText', 'new message');
expect(props.saveReportForm).to.have.been.called.once;
});
it('should clear the report form upon successful submission', async () => {
const props = makeProps({
defaultEmail: 'email@domain',
defaultMessage: 'test message',
sendProblemReport: () => Promise.resolve(),
clearReportForm: spy(),
});
const component = shallow(<Support {...props} />);
const sendButton = component.find({ testName: 'support__send_logs' });
await click(sendButton);
expect(props.clearReportForm).to.have.been.called.once;
});
});
function makeProps(mergeProps: $Shape<SupportProps> = {}): SupportProps {
const defaultProps: SupportProps = {
defaultEmail: '',
defaultMessage: '',
accountHistory: [],
onClose: () => {},
viewLog: (_path) => {},
collectProblemReport: () => Promise.resolve('/path/to/problem/report'),
sendProblemReport: (_report) => Promise.resolve(),
saveReportForm: (_form) => {},
clearReportForm: () => {},
};
return { ...defaultProps, ...mergeProps };
}
function click(component) {
return component.prop('onPress')();
}
|