diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-11-23 12:39:11 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-11-23 12:39:11 +0100 |
| commit | 3b5ae5b7c7943fd83ee8c4b7dac3e13113f70e92 (patch) | |
| tree | fd6a05544f0a9514c917bb6b527b2f19fb6b0bcc /test | |
| parent | 3ca41569b1d61444d4a2bf0a0dc330fbc86435ca (diff) | |
| parent | 58e7c1c3028707d8b9b5a130a4ec84f6a1a7fd7e (diff) | |
| download | mullvadvpn-3b5ae5b7c7943fd83ee8c4b7dac3e13113f70e92.tar.xz mullvadvpn-3b5ae5b7c7943fd83ee8c4b7dac3e13113f70e92.zip | |
Merge branch 'previously-added-accounts'
Diffstat (limited to 'test')
| -rw-r--r-- | test/components/Account.spec.js | 2 | ||||
| -rw-r--r-- | test/components/Login.spec.js | 59 | ||||
| -rw-r--r-- | test/components/Settings.spec.js | 3 | ||||
| -rw-r--r-- | test/components/Support.spec.js | 1 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 8 | ||||
| -rw-r--r-- | test/mocks/redux.js | 21 |
6 files changed, 35 insertions, 59 deletions
diff --git a/test/components/Account.spec.js b/test/components/Account.spec.js index 4f574ae6d7..a8b8e3d501 100644 --- a/test/components/Account.spec.js +++ b/test/components/Account.spec.js @@ -11,6 +11,7 @@ import type { AccountProps } from '../../app/components/Account'; describe('components/Account', () => { const state: AccountReduxState = { accountToken: '1234', + accountHistory: [], expiry: (new Date('2038-01-01')).toISOString(), status: 'none', error: null @@ -59,6 +60,7 @@ describe('components/Account', () => { it('should display "out of time" message when account expired', () => { const expiredState: AccountReduxState = { accountToken: '1234', + accountHistory: [], expiry: (new Date('2001-01-01')).toISOString(), status: 'none', error: null diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js index 9918dc6e1c..f34d9ea405 100644 --- a/test/components/Login.spec.js +++ b/test/components/Login.spec.js @@ -8,68 +8,55 @@ import sinon from 'sinon'; 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 callback = sinon.spy(); + let onFirstChange = sinon.spy(); const props = { - onFirstChangeAfterFailure: callback, + account: Object.assign({}, defaultAccount, { + status: 'failed' + }), + onFirstChangeAfterFailure: onFirstChange, }; const component = renderWithProps( props ); const accountInput = component.find(AccountInput); - // Change the props to a failed state - component.setProps({ account: { - status: 'failed', - }}); - + accountInput.simulate('change', 'foo'); + expect(onFirstChange.calledOnce).to.be.true; - // Write something in the input field - setInputText(accountInput, 'foo'); - expect(callback.calledOnce).to.be.true; + onFirstChange.reset(); - - // Reset the test state - callback.reset(); - - // Write some other thing in the input field - setInputText(accountInput, 'bar'); - expect(callback.calledOnce).to.be.false; + accountInput.simulate('change', 'bar'); + expect(onFirstChange.calledOnce).to.be.false; }); - it('doesn\'t show the footer when logging in', () => { + it('does not show the footer when logging in', () => { const component = renderLoggingIn(); - const footer = component.find('.login-footer'); expect(footer.hasClass('login-footer--invisible')).to.be.true; }); it('shows the footer and account input when not logged in', () => { const component = renderNotLoggedIn(); - const footer = component.find('.login-footer'); expect(footer.hasClass('login-footer--invisible')).to.be.false; expect(component.find(AccountInput).exists()).to.be.true; }); - it('doesn\'t show the footer nor account input when logged in', () => { + it('does not show the footer nor account input when logged in', () => { const component = renderLoggedIn(); - const footer = component.find('.login-footer'); expect(footer.hasClass('login-footer--invisible')).to.be.true; - expect(component.find('.login-form__fields').hasClass('login-form__fields--invisible')).to.be.true; + expect(component.find('.login-form__fields')).to.have.length(0); }); it('logs in with the entered account number when clicking the login icon', (done) => { const component = renderNotLoggedIn(); component.setProps({ - account: { - accountToken: '12345', - }, + account: Object.assign({}, defaultAccount, { + accountToken: '12345' + }), onLogin: (an) => { try { expect(an).to.equal('12345'); @@ -80,15 +67,16 @@ describe('components/Login', () => { }, }); - component.find('.login-form__submit').simulate('click'); + component.find('.login-form__account-input-button').simulate('click'); }); }); const defaultAccount = { accountToken: null, + accountHistory: [], expiry: null, status: 'none', - error: null, + error: null }; const defaultProps = { @@ -98,7 +86,8 @@ const defaultProps = { onChange: () => {}, onFirstChangeAfterFailure: () => {}, onExternalLink: () => {}, - onAccountTokenChange: () => {}, + onAccountTokenChange: (_accountToken) => {}, + onRemoveAccountTokenFromHistory: (_accountToken) => {}, }; function renderLoggedIn() { @@ -125,11 +114,7 @@ function renderNotLoggedIn() { }); } -function renderWithProps(customProps): ShallowWrapper { +function renderWithProps(customProps) { const props = Object.assign({}, defaultProps, customProps); return shallow( <Login { ...props } /> ); } - -function setInputText(input: ShallowWrapper, text: string) { - input.simulate('change', text); -} diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js index 85fd72ece5..5d29aa0dd6 100644 --- a/test/components/Settings.spec.js +++ b/test/components/Settings.spec.js @@ -12,6 +12,7 @@ import type { SettingsProps } from '../../app/components/Settings'; describe('components/Settings', () => { const loggedOutAccountState: AccountReduxState = { accountToken: null, + accountHistory: [], expiry: null, status: 'none', error: null @@ -19,6 +20,7 @@ describe('components/Settings', () => { const loggedInAccountState: AccountReduxState = { accountToken: '1234', + accountHistory: [], expiry: (new Date('2038-01-01')).toISOString(), status: 'ok', error: null @@ -26,6 +28,7 @@ describe('components/Settings', () => { const unpaidAccountState: AccountReduxState = { accountToken: '1234', + accountHistory: [], expiry: (new Date('2001-01-01')).toISOString(), status: 'ok', error: null diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js index b5b9b3d24b..3251b08464 100644 --- a/test/components/Support.spec.js +++ b/test/components/Support.spec.js @@ -14,6 +14,7 @@ describe('components/Support', () => { const defaultProps: SupportProps = { account: { accountToken: null, + accountHistory: [], error: null, expiry: null, status: 'none', diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index 53ac487dd5..2bda0b3fd6 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -67,12 +67,16 @@ export function newMockIpc() { } }, - authenticate: (_secret: string) => Promise.resolve(), - setCloseConnectionHandler: (listener: () => void) => { connectionCloseListeners.push(listener); }, + authenticate: (_secret: string) => Promise.resolve(), + + getAccountHistory: () => Promise.resolve([]), + + removeAccountFromHistory: (_accountToken) => Promise.resolve(), + killWebSocket: () => { for(const l of connectionCloseListeners) { l(); diff --git a/test/mocks/redux.js b/test/mocks/redux.js index 5f0562c035..a652009645 100644 --- a/test/mocks/redux.js +++ b/test/mocks/redux.js @@ -1,23 +1,4 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; -const middlewares = [ thunk ]; -export const mockStore = configureMockStore(middlewares); - -export const filterMinorActions = (actions) => { - return actions.filter((action) => { - if(action.type === 'CONNECTION_CHANGE' && action.payload.clientIp) { - return false; - } - - if(action.type === 'CONNECTION_CHANGE' && action.payload.isOnline) { - return false; - } - - if(action.type === 'USER_LOGIN_CHANGE' && action.payload.city) { - return false; - } - - return true; - }); -}; +export const mockStore = configureMockStore([ thunk ]); |
