summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-11-02 10:51:12 +0100
committerErik Larkö <erik@mullvad.net>2017-11-09 12:42:56 +0100
commitae8e86bb81cc722d9667c439d3508660398da707 (patch)
tree05a467e918755c290194df119d5977862d1e6f4b /test
parent01d617bab821f25412f4874354468afea30bd7b9 (diff)
downloadmullvadvpn-ae8e86bb81cc722d9667c439d3508660398da707.tar.xz
mullvadvpn-ae8e86bb81cc722d9667c439d3508660398da707.zip
Problem report
Diffstat (limited to 'test')
-rw-r--r--test/components/Support.spec.js58
1 files changed, 54 insertions, 4 deletions
diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js
index bcd871855b..2352cbcef2 100644
--- a/test/components/Support.spec.js
+++ b/test/components/Support.spec.js
@@ -1,6 +1,7 @@
// @flow
import { expect } from 'chai';
+import sinon from 'sinon';
import React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import Support from '../../app/components/Support';
@@ -12,7 +13,8 @@ describe('components/Support', () => {
const makeProps = (mergeProps: $Shape<SupportProps> = {}): SupportProps => {
const defaultProps: SupportProps = {
onClose: () => {},
- onViewLogs: () => {},
+ onViewLog: (_path) => {},
+ onCollectLog: () => Promise.resolve('/tmp/mullvad_problem_report.log'),
onSend: (_report) => {}
};
return Object.assign({}, defaultProps, mergeProps);
@@ -34,7 +36,7 @@ describe('components/Support', () => {
it('should call view logs callback', (done) => {
const props = makeProps({
- onViewLogs: () => done()
+ onViewLog: (_path) => done()
});
const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'support__form-view-logs');
Simulate.click(domNode);
@@ -47,7 +49,7 @@ describe('components/Support', () => {
const component = render(props);
- const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-description');
+ const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-message');
descriptionField.value = 'Lorem Ipsum';
Simulate.change(descriptionField);
@@ -59,7 +61,7 @@ describe('components/Support', () => {
it('should not call send callback when description is empty', () => {
const component = render(makeProps());
- const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-description');
+ const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-message');
descriptionField.value = '';
Simulate.change(descriptionField);
@@ -67,4 +69,52 @@ describe('components/Support', () => {
expect(sendButton.disabled).to.be.true;
});
+ it('should not collect report twice', (done) => {
+ const collectCallback = sinon.spy(() => Promise.resolve('non-falsy'));
+ const props = makeProps({
+ onCollectLog: collectCallback
+ });
+
+ const component = render(props);
+ const viewLogButton = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-view-logs');
+ Simulate.click(viewLogButton);
+
+ setTimeout(() => {
+ Simulate.click(viewLogButton);
+ });
+
+ setTimeout(() => {
+ try {
+ expect(collectCallback.callCount).to.equal(1);
+ done();
+ } catch (e) {
+ done(e);
+ }
+ });
+ });
+
+ it('should collect report on submission', (done) => {
+ const collectCallback = sinon.spy(() => Promise.resolve(''));
+ const props = makeProps({
+ onCollectLog: collectCallback,
+ onSend: (_report) => {
+ try {
+ expect(collectCallback.calledOnce).to.be.true;
+ done();
+ } catch (e) {
+ done(e);
+ }
+ }
+ });
+
+ const component = render(props);
+
+ const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-message');
+ descriptionField.value = 'Lorem Ipsum';
+ Simulate.change(descriptionField);
+
+ const sendButton = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-send');
+ Simulate.click(sendButton);
+ });
+
});