summaryrefslogtreecommitdiffhomepage
path: root/test/components
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-06-27 16:29:08 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-07-03 13:37:54 +0200
commitf687d36e6dd8bbab9b6bfc312a5f01244c54be31 (patch)
treef77ea199a86003d8d781b88a60c67a2346125b0f /test/components
parent00224ef4d8bb10d6b7ef019be2d443a87242093d (diff)
downloadmullvadvpn-f687d36e6dd8bbab9b6bfc312a5f01244c54be31.tar.xz
mullvadvpn-f687d36e6dd8bbab9b6bfc312a5f01244c54be31.zip
Fix Login tests
Diffstat (limited to 'test/components')
-rw-r--r--test/components/Login.spec.js102
1 files changed, 29 insertions, 73 deletions
diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js
index ce7f347acf..f3cbc24de1 100644
--- a/test/components/Login.spec.js
+++ b/test/components/Login.spec.js
@@ -2,32 +2,16 @@
import * as React from 'react';
import { shallow } from 'enzyme';
-
import Login from '../../app/components/Login';
-import AccountInput from '../../app/components/AccountInput';
describe('components/Login', () => {
- it('notifies on the first change after failure', () => {
- const onFirstChange = spy();
- const props = {
- account: Object.assign({}, defaultAccount, {
- status: 'failed',
- }),
- onFirstChangeAfterFailure: onFirstChange,
- };
-
- const component = renderWithProps(props);
- const accountInput = component.find(AccountInput);
-
- accountInput.simulate('change', 'foo');
- expect(onFirstChange).to.have.been.called.once;
-
- accountInput.simulate('change', 'bar');
- expect(onFirstChange).to.have.been.called.once;
- });
it('does not show the footer when logging in', () => {
- const component = renderLoggingIn();
+ const component = shallow(
+ <Login { ...{ ...defaultProps,
+ loginState: 'logging in'
+ }} />
+ );
const visibleFooters = getComponent(component, 'footerVisibility true');
const invisibleFooters = getComponent(component, 'footerVisibility false');
expect(visibleFooters.length).to.equal(0);
@@ -35,7 +19,9 @@ describe('components/Login', () => {
});
it('shows the footer and account input when not logged in', () => {
- const component = renderNotLoggedIn();
+ const component = shallow(
+ <Login {...defaultProps} />
+ );
const visibleFooters = getComponent(component, 'footerVisibility true');
const invisibleFooters = getComponent(component, 'footerVisibility false');
expect(visibleFooters.length).to.equal(1);
@@ -44,7 +30,11 @@ describe('components/Login', () => {
});
it('does not show the footer nor account input when logged in', () => {
- const component = renderLoggedIn();
+ const component = shallow(
+ <Login {...{ ...defaultProps,
+ loginState: 'ok'
+ }} />
+ );
const visibleFooters = getComponent(component, 'footerVisibility true');
const invisibleFooters = getComponent(component, 'footerVisibility false');
expect(visibleFooters.length).to.equal(0);
@@ -53,14 +43,14 @@ describe('components/Login', () => {
});
it('logs in with the entered account number when clicking the login icon', (done) => {
- const component = renderNotLoggedIn();
+ const component = shallow(
+ <Login {...defaultProps } />
+ );
component.setProps({
- account: Object.assign({}, defaultAccount, {
- accountToken: '12345',
- }),
- onLogin: (an) => {
+ accountToken: '12345',
+ login: (accountToken) => {
try {
- expect(an).to.equal('12345');
+ expect(accountToken).to.equal('12345');
done();
} catch (e) {
done(e);
@@ -72,54 +62,20 @@ describe('components/Login', () => {
});
});
-const defaultAccount = {
+const defaultProps = {
accountToken: null,
accountHistory: [],
- expiry: null,
- status: 'none',
- error: null,
+ loginError: null,
+ loginState: 'none',
+ openSettings: () => {},
+ openExternalLink: (_type) => {},
+ login: (_accountToken) => {},
+ resetLoginError: () => {},
+ updateAccountToken: (_accountToken) => {},
+ fetchAccountTokenHistory: () => Promise.resolve(),
+ removeAccountTokenFromHistory: (_accountToken) => Promise.resolve(),
};
-const defaultProps = {
- account: defaultAccount,
- onLogin: () => {},
- onSettings: () => {},
- onChange: () => {},
- onFirstChangeAfterFailure: () => {},
- onExternalLink: () => {},
- onAccountTokenChange: (_accountToken) => {},
- onRemoveAccountTokenFromHistory: (_accountToken) => {},
-};
-
-function renderLoggedIn() {
- return renderWithProps({
- account: Object.assign(defaultAccount, {
- status: 'ok',
- }),
- });
-}
-
-function renderLoggingIn() {
- return renderWithProps({
- account: Object.assign(defaultAccount, {
- status: 'logging in',
- }),
- });
-}
-
-function renderNotLoggedIn() {
- return renderWithProps({
- account: Object.assign(defaultAccount, {
- status: 'none',
- }),
- });
-}
-
-function renderWithProps(customProps) {
- const props = Object.assign({}, defaultProps, customProps);
- return shallow(<Login {...props} />);
-}
-
function getComponent(container, testName) {
return container.findWhere((n) => n.prop('testName') === testName);
}