diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 15:07:37 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-08-15 17:39:38 +0200 |
| commit | 71592249b2dd669b6f24f37bfb7b0f4e43b74998 (patch) | |
| tree | a6097dc7e5d94d06e99c65fdfe160e824395f50c /test/components/Support.spec.js | |
| parent | e84e87f4ce5a8c242f756566cdc6fb59a45f7bea (diff) | |
| download | mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.tar.xz mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.zip | |
Add workspaces
Diffstat (limited to 'test/components/Support.spec.js')
| -rw-r--r-- | test/components/Support.spec.js | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js deleted file mode 100644 index 23172d3403..0000000000 --- a/test/components/Support.spec.js +++ /dev/null @@ -1,122 +0,0 @@ -// @flow - -import * as React from 'react'; -import Support from '../../app/components/Support'; -import { shallow } from 'enzyme'; -import type { SupportProps } from '../../app/components/Support'; -import { BackBarItem } from '../../app/components/NavigationBar'; - -describe('components/Support', () => { - it('should call close callback', () => { - const props = makeProps({ onClose: spy() }); - const component = shallow(<Support {...props} />); - - const closeButton = component.find(BackBarItem).dive(); - closeButton.simulate('press'); - - 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')(); -} |
