summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-08-15 13:38:02 +0200
committerErik Larkö <erik@mullvad.net>2017-08-16 14:22:23 +0200
commitca6a2f8965b517bd5d5df512796d4ceeda637d79 (patch)
tree5bc58525834fa92ff625395953f880a5ae0fec3b /test
parent61c56110c3c2d550966edab662405c2f6d84c05b (diff)
downloadmullvadvpn-ca6a2f8965b517bd5d5df512796d4ceeda637d79.tar.xz
mullvadvpn-ca6a2f8965b517bd5d5df512796d4ceeda637d79.zip
Add test for components/Login onFirstChangeAfterFailure
Diffstat (limited to 'test')
-rw-r--r--test/components/Login.spec.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js
new file mode 100644
index 0000000000..0f82102d4e
--- /dev/null
+++ b/test/components/Login.spec.js
@@ -0,0 +1,64 @@
+// @flow
+
+import { expect } from 'chai';
+import React from 'react';
+import { shallow } from 'enzyme';
+import Login from '../../app/components/Login';
+import AccountInput from '../../app/components/AccountInput';
+
+import type { ShallowWrapper } from 'enzyme';
+
+describe('components/Login', () => {
+
+ it('notifies on the first change after failure', () => {
+
+ let cbCalled = false;
+ const props = {
+ onFirstChangeAfterFailure: () => { cbCalled=true; },
+ };
+
+ const component = renderWithProps( props );
+ const accountInput = component.find(AccountInput);
+
+ // Change the props to a failed state
+ component.setProps({ account: {
+ status: 'failed',
+ }});
+
+
+ // Write something in the input field
+ setInputText(accountInput, 'foo');
+ expect(cbCalled).to.be.true;
+
+
+ // Reset the test state
+ cbCalled = false;
+
+ // Write some other thing in the input field
+ setInputText(accountInput, 'bar');
+ expect(cbCalled).to.be.false;
+ });
+
+});
+
+function renderWithProps(customProps): ShallowWrapper {
+ const defaultProps = {
+ account: {accountNumber: null,
+ paidUntil: null,
+ status: 'none',
+ error: null,
+ },
+ onLogin: () => {},
+ onSettings: () => {},
+ onChange: () => {},
+ onFirstChangeAfterFailure: () => {},
+ onExternalLink: () => {},
+ };
+ const props = Object.assign({}, defaultProps, customProps);
+
+ return shallow( <Login { ...props } /> );
+}
+
+function setInputText(input: ShallowWrapper, text: string) {
+ input.simulate('change', {target: {value: text}});
+}