summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-10-14 16:41:51 +0200
committerAndrej Mihajlov <and@mullvad.net>2017-10-19 14:16:38 +0200
commitcf1c89302d93f4ed8ec7ec0f2c2897df9707997f (patch)
tree627d0eb275acf65c41ee162ee93431565d02c9ed /test
parent688796d784bfcc8a5a6deb4b4d749aafa728499c (diff)
downloadmullvadvpn-cf1c89302d93f4ed8ec7ec0f2c2897df9707997f.tar.xz
mullvadvpn-cf1c89302d93f4ed8ec7ec0f2c2897df9707997f.zip
Add tests for Support component
Diffstat (limited to 'test')
-rw-r--r--test/components/Support.spec.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js
new file mode 100644
index 0000000000..bcd871855b
--- /dev/null
+++ b/test/components/Support.spec.js
@@ -0,0 +1,70 @@
+// @flow
+
+import { expect } from 'chai';
+import React from 'react';
+import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
+import Support from '../../app/components/Support';
+
+import type { SupportProps } from '../../app/components/Support';
+
+describe('components/Support', () => {
+
+ const makeProps = (mergeProps: $Shape<SupportProps> = {}): SupportProps => {
+ const defaultProps: SupportProps = {
+ onClose: () => {},
+ onViewLogs: () => {},
+ onSend: (_report) => {}
+ };
+ return Object.assign({}, defaultProps, mergeProps);
+ };
+
+ const render = (props: SupportProps): Support => {
+ return ReactTestUtils.renderIntoDocument(
+ <Support { ...props } />
+ );
+ };
+
+ it('should call close callback', (done) => {
+ const props = makeProps({
+ onClose: () => done()
+ });
+ const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'support__close');
+ Simulate.click(domNode);
+ });
+
+ it('should call view logs callback', (done) => {
+ const props = makeProps({
+ onViewLogs: () => done()
+ });
+ const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'support__form-view-logs');
+ Simulate.click(domNode);
+ });
+
+ it('should call send callback when description filled in', (done) => {
+ const props = makeProps({
+ onSend: (_report) => done()
+ });
+
+ const component = render(props);
+
+ const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-description');
+ descriptionField.value = 'Lorem Ipsum';
+ Simulate.change(descriptionField);
+
+ const sendButton = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-send');
+ expect(sendButton.disabled).to.be.false;
+ Simulate.click(sendButton);
+ });
+
+ it('should not call send callback when description is empty', () => {
+ const component = render(makeProps());
+
+ const descriptionField = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-description');
+ descriptionField.value = '';
+ Simulate.change(descriptionField);
+
+ const sendButton = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'support__form-send');
+ expect(sendButton.disabled).to.be.true;
+ });
+
+});