diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-01 16:13:10 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-05 12:11:55 +0200 |
| commit | ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087 (patch) | |
| tree | b1f7754eb50896ab3681e35fa4e08be642b940c9 /test | |
| parent | 5852c980980de53e00d76a0bdb4b41bf5c0f5b39 (diff) | |
| download | mullvadvpn-ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087.tar.xz mullvadvpn-ca2f6fbfcad7b73d4ea63ef46cb1cab943ec9087.zip | |
Add formatted source code
Diffstat (limited to 'test')
| -rw-r--r-- | test/auth.spec.js | 20 | ||||
| -rw-r--r-- | test/autologin.spec.js | 81 | ||||
| -rw-r--r-- | test/components/Account.spec.js | 23 | ||||
| -rw-r--r-- | test/components/AccountInput.spec.js | 37 | ||||
| -rw-r--r-- | test/components/Connect.spec.js | 19 | ||||
| -rw-r--r-- | test/components/HeaderBar.spec.js | 10 | ||||
| -rw-r--r-- | test/components/Login.spec.js | 13 | ||||
| -rw-r--r-- | test/components/Preferences.spec.js | 6 | ||||
| -rw-r--r-- | test/components/SelectLocation.spec.js | 69 | ||||
| -rw-r--r-- | test/components/Settings.spec.js | 42 | ||||
| -rw-r--r-- | test/components/Support.spec.js | 20 | ||||
| -rw-r--r-- | test/components/Switch.spec.js | 44 | ||||
| -rw-r--r-- | test/connect.spec.js | 28 | ||||
| -rw-r--r-- | test/helpers/IpcChain.js | 2 | ||||
| -rw-r--r-- | test/helpers/dom-events.js | 4 | ||||
| -rw-r--r-- | test/helpers/ipc-helpers.js | 13 | ||||
| -rw-r--r-- | test/ipc.spec.js | 46 | ||||
| -rw-r--r-- | test/keyframe-animation.spec.js | 23 | ||||
| -rw-r--r-- | test/login.spec.js | 51 | ||||
| -rw-r--r-- | test/logout.spec.js | 27 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 73 | ||||
| -rw-r--r-- | test/mocks/redux.js | 2 | ||||
| -rw-r--r-- | test/relay-settings-builder.spec.js | 106 | ||||
| -rw-r--r-- | test/transition-rule.spec.js | 15 |
24 files changed, 378 insertions, 396 deletions
diff --git a/test/auth.spec.js b/test/auth.spec.js index c3fd78c83d..effc3473cb 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -1,12 +1,16 @@ // @flow import { expect } from 'chai'; -import { setupIpcAndStore, setupBackendAndStore, failFast, checkNextTick } from './helpers/ipc-helpers'; +import { + setupIpcAndStore, + setupBackendAndStore, + failFast, + checkNextTick, +} from './helpers/ipc-helpers'; import { IpcChain } from './helpers/IpcChain'; import { Backend } from '../app/lib/backend'; describe('authentication', () => { - it('authenticates before ipc call if unauthenticated', (done) => { const { store, mockIpc } = setupIpcAndStore(); const credentials = { @@ -14,20 +18,18 @@ describe('authentication', () => { connectionString: '', }; - const chain = new IpcChain(mockIpc); - chain.require('authenticate') - .withInputValidation( secret => { + chain + .require('authenticate') + .withInputValidation((secret) => { expect(secret).to.equal(credentials.sharedSecret); }) .done(); - chain.require('connect') - .done(); + chain.require('connect').done(); chain.onSuccessOrFailure(done); - const backend = new Backend(store, credentials, mockIpc); backend.connect(); }); @@ -41,13 +43,11 @@ describe('authentication', () => { return Promise.resolve(); }; - mockIpc.killWebSocket(); failFast(() => { expect(authCount).to.equal(0); }, done); - backend.connect(); checkNextTick(() => { expect(authCount).to.equal(1); diff --git a/test/autologin.spec.js b/test/autologin.spec.js index c8fd6c170c..debacc6c60 100644 --- a/test/autologin.spec.js +++ b/test/autologin.spec.js @@ -5,18 +5,19 @@ import { setupBackendAndStore, setupBackendAndMockStore, getLocation } from './h import { IpcChain } from './helpers/IpcChain'; describe('autologin', () => { - it('should send get_account then get_account_data if an account is set', (done) => { const { mockIpc, backend } = setupBackendAndStore(); const randomAccountToken = '12345'; const chain = new IpcChain(mockIpc); - chain.require('getAccount') + chain + .require('getAccount') .withReturnValue(randomAccountToken) .done(); - chain.require('getAccountData') + chain + .require('getAccountData') .withInputValidation((num) => { expect(num).to.equal(randomAccountToken); }) @@ -32,11 +33,12 @@ describe('autologin', () => { mockIpc.getAccount = () => new Promise((_, reject) => reject('NO_ACCOUNT')); - return backend.autologin() - .then( () => { + return backend + .autologin() + .then(() => { expect(getLocation(store)).to.equal('/'); }) - .catch( (e) => { + .catch((e) => { if (e !== 'NO_ACCOUNT') { throw e; } @@ -46,14 +48,15 @@ describe('autologin', () => { it('should redirect to the login page for non-existing accounts', () => { const { store, backend, mockIpc } = setupBackendAndMockStore(); - mockIpc.getAccount = () => new Promise(r => r('123')); + mockIpc.getAccount = () => new Promise((r) => r('123')); mockIpc.getAccountData = () => new Promise((_, reject) => reject('NO_ACCOUNT')); - return backend.autologin() - .then( () => { + return backend + .autologin() + .then(() => { expect(getLocation(store)).to.equal('/'); }) - .catch( (e) => { + .catch((e) => { if (e !== 'NO_ACCOUNT') { throw e; } @@ -65,9 +68,10 @@ describe('autologin', () => { mockIpc.getAccount = () => Promise.resolve(null); - return backend.autologin() - .catch( () => {}) // ignore errors - .then( () => { + return backend + .autologin() + .catch(() => {}) // ignore errors + .then(() => { const state = store.getState().account; expect(state.status).to.equal('none'); @@ -79,12 +83,13 @@ describe('autologin', () => { it('should mark the state as not logged in for non-existing accounts', () => { const { store, backend, mockIpc } = setupBackendAndStore(); - mockIpc.getAccount = () => new Promise(r => r('123')); + mockIpc.getAccount = () => new Promise((r) => r('123')); mockIpc.getAccountData = () => new Promise((_, reject) => reject('NO ACCOUNT')); - return backend.autologin() - .catch( () => {}) // ignore errors - .then( () => { + return backend + .autologin() + .catch(() => {}) // ignore errors + .then(() => { const state = store.getState().account; expect(state.status).to.equal('none'); @@ -94,31 +99,35 @@ describe('autologin', () => { it('should put the account data in the state for existing accounts', () => { const { store, backend, mockIpc } = setupBackendAndStore(); - mockIpc.getAccount = () => new Promise(r => r('123')); - mockIpc.getAccountData = () => new Promise(r => r({ - expiry: '2001-01-01T00:00:00Z', - })); + mockIpc.getAccount = () => new Promise((r) => r('123')); + mockIpc.getAccountData = () => + new Promise((r) => + r({ + expiry: '2001-01-01T00:00:00Z', + }), + ); - return backend.autologin() - .then( () => { - const state = store.getState().account; - expect(state.status).to.equal('ok'); - expect(state.accountToken).to.equal('123'); - expect(state.expiry).to.equal('2001-01-01T00:00:00Z'); - }); + return backend.autologin().then(() => { + const state = store.getState().account; + expect(state.status).to.equal('ok'); + expect(state.accountToken).to.equal('123'); + expect(state.expiry).to.equal('2001-01-01T00:00:00Z'); + }); }); it('should redirect to /connect for existing accounts', () => { const { store, backend, mockIpc } = setupBackendAndMockStore(); - mockIpc.getAccount = () => new Promise(r => r('123')); - mockIpc.getAccountData = () => new Promise(r => r({ - expiry: '2001-01-01T00:00:00Z', - })); + mockIpc.getAccount = () => new Promise((r) => r('123')); + mockIpc.getAccountData = () => + new Promise((r) => + r({ + expiry: '2001-01-01T00:00:00Z', + }), + ); - return backend.autologin() - .then( () => { - expect(getLocation(store)).to.equal('/connect'); - }); + return backend.autologin().then(() => { + expect(getLocation(store)).to.equal('/connect'); + }); }); }); diff --git a/test/components/Account.spec.js b/test/components/Account.spec.js index ccdb1d2117..c9d0891022 100644 --- a/test/components/Account.spec.js +++ b/test/components/Account.spec.js @@ -13,9 +13,9 @@ describe('components/Account', () => { const state: AccountReduxState = { accountToken: '1234', accountHistory: [], - expiry: (new Date('2038-01-01')).toISOString(), + expiry: new Date('2038-01-01').toISOString(), status: 'none', - error: null + error: null, }; const makeProps = (state: AccountReduxState, mergeProps: $Shape<AccountProps>): AccountProps => { @@ -23,14 +23,14 @@ describe('components/Account', () => { account: state, onClose: () => {}, onLogout: () => {}, - onBuyMore: () => {} + onBuyMore: () => {}, }; return Object.assign({}, defaultProps, mergeProps); }; it('should call close callback', (done) => { const props = makeProps(state, { - onClose: () => done() + onClose: () => done(), }); const component = getComponent(render(props), 'account__close'); click(component); @@ -38,7 +38,7 @@ describe('components/Account', () => { it('should call logout callback', (done) => { const props = makeProps(state, { - onLogout: () => done() + onLogout: () => done(), }); const component = getComponent(render(props), 'account__logout'); click(component); @@ -46,7 +46,7 @@ describe('components/Account', () => { it('should call "buy more" callback', (done) => { const props = makeProps(state, { - onBuyMore: () => done() + onBuyMore: () => done(), }); const component = getComponent(render(props), 'account__buymore'); click(component); @@ -56,9 +56,9 @@ describe('components/Account', () => { const expiredState: AccountReduxState = { accountToken: '1234', accountHistory: [], - expiry: (new Date('2001-01-01')).toISOString(), + expiry: new Date('2001-01-01').toISOString(), status: 'none', - error: null + error: null, }; const props = makeProps(expiredState, {}); const component = getComponent(render(props), 'account__out_of_time'); @@ -70,17 +70,14 @@ describe('components/Account', () => { const component = getComponent(render(props), 'account__out_of_time'); expect(component).to.have.length(0); }); - }); function render(props) { - return shallow( - <Account {...props} /> - ); + return shallow(<Account {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function click(component) { diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js index a10326bc17..25f2e366b7 100644 --- a/test/components/AccountInput.spec.js +++ b/test/components/AccountInput.spec.js @@ -18,17 +18,15 @@ describe('components/AccountInput', () => { const defaultProps: AccountInputProps = { value: '', onEnter: null, - onChange: null + onChange: null, }; const props = Object.assign({}, defaultProps, mergeProps); - return shallow( - <AccountInput {...props} /> - ); + return shallow(<AccountInput {...props} />); }; it('should call onEnter', (done) => { const component = render({ - onEnter: () => done() + onEnter: () => done(), }); keyPress(getInputRef(component), createKeyEvent('Enter')); }); @@ -38,7 +36,7 @@ describe('components/AccountInput', () => { onChange: (val) => { expect(val).to.be.equal('1'); done(); - } + }, }); keyPress(getInputRef(component), createKeyEvent('1')); }); @@ -58,10 +56,10 @@ describe('components/AccountInput', () => { '111', '11', '1', - '' + '', ]; - for(const value of cases) { + for (const value of cases) { const component = render({ value }); expect(getInputRef(component).prop('value')).to.be.equal(value); } @@ -73,7 +71,7 @@ describe('components/AccountInput', () => { onChange: (val) => { expect(val).to.be.equal('123'); done(); - } + }, }); keyPress(getInputRef(component), createKeyEvent('Backspace')); }); @@ -84,7 +82,7 @@ describe('components/AccountInput', () => { onChange: (val) => { expect(val).to.be.equal('234'); done(); - } + }, }); component.setState({ selectionRange: [1, 1] }, () => { keyPress(getInputRef(component), createKeyEvent('Backspace')); @@ -97,7 +95,7 @@ describe('components/AccountInput', () => { onChange: (val) => { expect(val).to.be.empty; done(); - } + }, }); component.setState({ selectionRange: [0, 8] }, () => { keyPress(getInputRef(component), createKeyEvent('Backspace')); @@ -110,7 +108,7 @@ describe('components/AccountInput', () => { onChange: (val) => { expect(val).to.be.equal('12349999'); done(); - } + }, }); component.setState({ selectionRange: [4, 8] }, () => { keyPress(getInputRef(component), createKeyEvent('Backspace')); @@ -119,7 +117,7 @@ describe('components/AccountInput', () => { it('should replace selection', (done) => { const component = render({ - value: '0000' + value: '0000', }); component.setState({ selectionRange: [1, 3] }, () => { @@ -136,7 +134,7 @@ describe('components/AccountInput', () => { it('should keep selection in the back', (done) => { const component = render({ value: '' }); - for(let i = 0; i < 12; i++) { + for (let i = 0; i < 12; i++) { keyPress(getInputRef(component), createKeyEvent('1')); } @@ -149,9 +147,9 @@ describe('components/AccountInput', () => { it('should advance selection on insertion', (done) => { const component = render({ - value: '0000' + value: '0000', }); - component.setState({ selectionRange: [1, 1]}, () => { + component.setState({ selectionRange: [1, 1] }, () => { keyPress(getInputRef(component), createKeyEvent('1')); component.setState({}, () => { @@ -164,7 +162,7 @@ describe('components/AccountInput', () => { it('should not do anything when nothing to remove', (done) => { const component = render({ - value: '0000' + value: '0000', }); component.setState({ selectionRange: [0, 0] }, () => { keyPress(getInputRef(component), createKeyEvent('Backspace')); @@ -176,13 +174,12 @@ describe('components/AccountInput', () => { }); }); }); - }); function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function keyPress(component, key) { component.prop('onKeyPress')(key); -}
\ No newline at end of file +} diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js index 59079082c5..64771248b6 100644 --- a/test/components/Connect.spec.js +++ b/test/components/Connect.spec.js @@ -9,13 +9,12 @@ import Connect from '../../app/components/Connect'; import type { ConnectProps } from '../../app/components/Connect'; describe('components/Connect', () => { - it('shows unsecured hints when disconnected', () => { const component = renderWithProps({ connection: { ...defaultProps.connection, status: 'disconnected', - } + }, }); const header = getComponent(component, 'header'); @@ -31,7 +30,7 @@ describe('components/Connect', () => { connection: { ...defaultProps.connection, status: 'connected', - } + }, }); const header = getComponent(component, 'header'); @@ -49,7 +48,7 @@ describe('components/Connect', () => { status: 'connecting', country: 'Norway', city: 'Oslo', - } + }, }); const countryAndCity = getComponent(component, 'location'); const ipAddr = getComponent(component, 'ipAddress'); @@ -67,7 +66,7 @@ describe('components/Connect', () => { country: 'Norway', city: 'Oslo', ip: '4.3.2.1', - } + }, }); const countryAndCity = getComponent(component, 'location'); const ipAddr = getComponent(component, 'ipAddress'); @@ -85,7 +84,7 @@ describe('components/Connect', () => { country: 'Norway', city: 'Oslo', ip: '4.3.2.1', - } + }, }); const countryAndCity = getComponent(component, 'location'); const ipAddr = getComponent(component, 'ipAddress'); @@ -101,7 +100,7 @@ describe('components/Connect', () => { connection: { ...defaultProps.connection, status: 'disconnected', - } + }, }); const connectButton = getComponent(component, 'secureConnection'); @@ -131,9 +130,9 @@ const defaultProps: ConnectProps = { function renderWithProps(customProps: $Shape<ConnectProps>) { const props = { ...defaultProps, ...customProps }; - return shallow( <Connect { ...props } /> ); + return shallow(<Connect {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); -}
\ No newline at end of file + return container.findWhere((n) => n.prop('testName') === testName); +} diff --git a/test/components/HeaderBar.spec.js b/test/components/HeaderBar.spec.js index e4ebb09429..44731646d2 100644 --- a/test/components/HeaderBar.spec.js +++ b/test/components/HeaderBar.spec.js @@ -8,7 +8,6 @@ import HeaderBar from '../../app/components/HeaderBar'; require('../setup/enzyme'); describe('components/HeaderBar', () => { - it('should display headerbar', () => { const component = render({ hidden: false, @@ -44,22 +43,19 @@ describe('components/HeaderBar', () => { it('should call settings callback', (done) => { const component = render({ showSettings: true, - onSettings: () => done(), + onSettings: () => done(), }); const settingsButton = getComponent(component, 'headerbar__settings'); click(settingsButton); }); - }); function render(props) { - return shallow( - <HeaderBar {...props} /> - ); + return shallow(<HeaderBar {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function hasChild(container, testName) { diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js index f8f4af54de..355e566d11 100644 --- a/test/components/Login.spec.js +++ b/test/components/Login.spec.js @@ -9,17 +9,16 @@ import Login from '../../app/components/Login'; import AccountInput from '../../app/components/AccountInput'; describe('components/Login', () => { - it('notifies on the first change after failure', () => { let onFirstChange = sinon.spy(); const props = { account: Object.assign({}, defaultAccount, { - status: 'failed' + status: 'failed', }), onFirstChangeAfterFailure: onFirstChange, }; - const component = renderWithProps( props ); + const component = renderWithProps(props); const accountInput = component.find(AccountInput); accountInput.simulate('change', 'foo'); @@ -61,7 +60,7 @@ describe('components/Login', () => { const component = renderNotLoggedIn(); component.setProps({ account: Object.assign({}, defaultAccount, { - accountToken: '12345' + accountToken: '12345', }), onLogin: (an) => { try { @@ -82,7 +81,7 @@ const defaultAccount = { accountHistory: [], expiry: null, status: 'none', - error: null + error: null, }; const defaultProps = { @@ -122,11 +121,11 @@ function renderNotLoggedIn() { function renderWithProps(customProps) { const props = Object.assign({}, defaultProps, customProps); - return shallow( <Login { ...props } /> ); + return shallow(<Login {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function click(component) { diff --git a/test/components/Preferences.spec.js b/test/components/Preferences.spec.js index cad039df32..833a123538 100644 --- a/test/components/Preferences.spec.js +++ b/test/components/Preferences.spec.js @@ -8,15 +8,13 @@ import Preferences from '../../app/components/Preferences'; require('../setup/enzyme'); describe('components/Preferences', () => { - it('Should call close handler', (done) => { const props = makeProps({ onClose: done }); - const component = shallow(<Preferences { ...props } />); + const component = shallow(<Preferences {...props} />); const button = component.find({ testName: 'closeButton' }); expect(button).to.have.length(1); button.simulate('press'); }); - }); function makeProps(props) { @@ -24,6 +22,6 @@ function makeProps(props) { onClose: () => {}, onChangeAllowLan: () => {}, allowLan: false, - ...props + ...props, }; } diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js index 4e2265c6dd..8310d52b97 100644 --- a/test/components/SelectLocation.spec.js +++ b/test/components/SelectLocation.spec.js @@ -15,47 +15,53 @@ describe('components/SelectLocation', () => { location: 'any', protocol: 'any', port: 'any', - } + }, }, - relayLocations: [{ - name: 'Sweden', - code: 'se', - hasActiveRelays: true, - cities: [{ - name: 'Malmö', - code: 'mma', - latitude: 0, - longitude: 0, + relayLocations: [ + { + name: 'Sweden', + code: 'se', hasActiveRelays: true, - }, { - name: 'Stockholm', - code: 'sto', - latitude: 0, - longitude: 0, - hasActiveRelays: true, - }], - }], + cities: [ + { + name: 'Malmö', + code: 'mma', + latitude: 0, + longitude: 0, + hasActiveRelays: true, + }, + { + name: 'Stockholm', + code: 'sto', + latitude: 0, + longitude: 0, + hasActiveRelays: true, + }, + ], + }, + ], allowLan: false, }; - const makeProps = (state: SettingsReduxState, mergeProps: $Shape<SelectLocationProps>): SelectLocationProps => { + const makeProps = ( + state: SettingsReduxState, + mergeProps: $Shape<SelectLocationProps>, + ): SelectLocationProps => { const defaultProps: SelectLocationProps = { settings: state, onClose: () => {}, - onSelect: (_server) => {} + onSelect: (_server) => {}, }; return Object.assign({}, defaultProps, mergeProps); }; const render = (props: SelectLocationProps) => { - return shallow( - <SelectLocation { ...props } /> - ); + return shallow(<SelectLocation {...props} />); }; it('should call close callback', (done) => { const props = makeProps(state, { - onClose: () => done() + onClose: () => done(), }); const node = getComponent(render(props), 'close'); click(node); @@ -66,13 +72,13 @@ describe('components/SelectLocation', () => { onSelect: (location) => { try { expect(location).to.deep.equal({ - country: 'se' + country: 'se', }); done(); - } catch(e) { + } catch (e) { done(e); } - } + }, }); const elements = getComponent(render(props), 'country'); expect(elements).to.have.length(1); @@ -84,23 +90,22 @@ describe('components/SelectLocation', () => { onSelect: (location) => { try { expect(location).to.deep.equal({ - city: ['se', 'mma'] + city: ['se', 'mma'], }); done(); - } catch(e) { + } catch (e) { done(e); } - } + }, }); const elements = getComponent(render(props), 'city'); expect(elements).to.have.length(2); click(elements.at(0)); }); - }); function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function click(component) { diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js index 8f0e4a73d4..447b0b50db 100644 --- a/test/components/Settings.spec.js +++ b/test/components/Settings.spec.js @@ -17,23 +17,23 @@ describe('components/Settings', () => { accountHistory: [], expiry: null, status: 'none', - error: null + error: null, }; const loggedInAccountState: AccountReduxState = { accountToken: '1234', accountHistory: [], - expiry: (new Date('2038-01-01')).toISOString(), + expiry: new Date('2038-01-01').toISOString(), status: 'ok', - error: null + error: null, }; const unpaidAccountState: AccountReduxState = { accountToken: '1234', accountHistory: [], - expiry: (new Date('2001-01-01')).toISOString(), + expiry: new Date('2001-01-01').toISOString(), status: 'ok', - error: null + error: null, }; const settingsState: SettingsReduxState = { @@ -48,7 +48,11 @@ describe('components/Settings', () => { allowLan: false, }; - const makeProps = (anAccountState: AccountReduxState, aSettingsState: SettingsReduxState, mergeProps: $Shape<SettingsProps> = {}): SettingsProps => { + const makeProps = ( + anAccountState: AccountReduxState, + aSettingsState: SettingsReduxState, + mergeProps: $Shape<SettingsProps> = {}, + ): SettingsProps => { const defaultProps: SettingsProps = { account: anAccountState, settings: aSettingsState, @@ -59,7 +63,7 @@ describe('components/Settings', () => { onViewSupport: () => {}, onViewAdvancedSettings: () => {}, onViewPreferences: () => {}, - onExternalLink: (_type) => {} + onExternalLink: (_type) => {}, }; return Object.assign({}, defaultProps, mergeProps); }; @@ -120,7 +124,7 @@ describe('components/Settings', () => { it('should call close callback', (done) => { const props = makeProps(loggedOutAccountState, settingsState, { - onClose: () => done() + onClose: () => done(), }); const component = getComponent(render(props), 'settings__close'); click(component); @@ -128,7 +132,7 @@ describe('components/Settings', () => { it('should call quit callback', (done) => { const props = makeProps(loggedOutAccountState, settingsState, { - onQuit: () => done() + onQuit: () => done(), }); const component = getComponent(render(props), 'settings__quit'); click(component); @@ -136,7 +140,7 @@ describe('components/Settings', () => { it('should call account callback', (done) => { const props = makeProps(loggedInAccountState, settingsState, { - onViewAccount: () => done() + onViewAccount: () => done(), }); const component = getComponent(render(props), 'settings__account_paid_until_button'); click(component); @@ -144,7 +148,7 @@ describe('components/Settings', () => { it('should call advanced settings callback', (done) => { const props = makeProps(loggedInAccountState, settingsState, { - onViewAdvancedSettings: () => done() + onViewAdvancedSettings: () => done(), }); const component = getComponent(render(props), 'settings__advanced'); click(component); @@ -152,7 +156,7 @@ describe('components/Settings', () => { it('should call preferences callback', (done) => { const props = makeProps(loggedInAccountState, settingsState, { - onViewPreferences: () => done() + onViewPreferences: () => done(), }); const component = getComponent(render(props), 'settings__preferences'); click(component); @@ -160,7 +164,7 @@ describe('components/Settings', () => { it('should call support callback', (done) => { const props = makeProps(loggedInAccountState, settingsState, { - onViewSupport: () => done() + onViewSupport: () => done(), }); const component = getComponent(render(props), 'settings__view_support'); click(component); @@ -171,25 +175,21 @@ describe('components/Settings', () => { const props = makeProps(loggedOutAccountState, settingsState, { onExternalLink: (type) => { collectedExternalLinkTypes.push(type); - } + }, }); const container = getComponent(render(props), 'settings__external_link'); - container.find({ testName: 'settings__external_link' }) - .forEach((element) => click(element)); + container.find({ testName: 'settings__external_link' }).forEach((element) => click(element)); expect(collectedExternalLinkTypes).to.include.ordered.members(['faq', 'guides']); }); - }); function render(props) { - return shallow( - <Settings {...props} /> - ); + return shallow(<Settings {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function click(component) { diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js index a1a953fa2c..a968db974f 100644 --- a/test/components/Support.spec.js +++ b/test/components/Support.spec.js @@ -10,7 +10,6 @@ import sinon from 'sinon'; import type { SupportProps } from '../../app/components/Support'; describe('components/Support', () => { - const makeProps = (mergeProps: $Shape<SupportProps> = {}): SupportProps => { const defaultProps: SupportProps = { account: { @@ -23,14 +22,14 @@ describe('components/Support', () => { onClose: () => {}, onViewLog: (_path) => {}, onCollectLog: () => Promise.resolve('/tmp/mullvad_problem_report.log'), - onSend: (_report) => {} + onSend: (_report) => {}, }; return Object.assign({}, defaultProps, mergeProps); }; it('should call close callback', (done) => { const props = makeProps({ - onClose: () => done() + onClose: () => done(), }); const component = getComponent(render(props), 'support__close'); click(component); @@ -38,7 +37,7 @@ describe('components/Support', () => { it('should call view logs callback', (done) => { const props = makeProps({ - onViewLog: (_path) => done() + onViewLog: (_path) => done(), }); const component = getComponent(render(props), 'support__view_logs'); click(component); @@ -46,7 +45,7 @@ describe('components/Support', () => { it('should call send callback when description filled in', (done) => { const props = makeProps({ - onSend: (_report) => done() + onSend: (_report) => done(), }); const component = render(props); @@ -68,7 +67,7 @@ describe('components/Support', () => { it('should not collect report twice', (done) => { const collectCallback = sinon.spy(() => Promise.resolve('non-falsy')); const props = makeProps({ - onCollectLog: collectCallback + onCollectLog: collectCallback, }); const viewLogButton = getComponent(render(props), 'support__view_logs'); @@ -99,7 +98,7 @@ describe('components/Support', () => { } catch (e) { done(e); } - } + }, }); const component = render(props); @@ -108,17 +107,14 @@ describe('components/Support', () => { const sendButton = getComponent(component, 'support__send_logs'); click(sendButton); }); - }); function render(props) { - return shallow( - <Support {...props} /> - ); + return shallow(<Support {...props} />); } function getComponent(container, testName) { - return container.findWhere( n => n.prop('testName') === testName); + return container.findWhere((n) => n.prop('testName') === testName); } function click(component) { diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js index eaac6dc08c..e1242d74df 100644 --- a/test/components/Switch.spec.js +++ b/test/components/Switch.spec.js @@ -7,16 +7,15 @@ import ReactTestUtils, { Simulate } from 'react-dom/test-utils'; import Switch from '../../app/components/Switch'; describe('components/Switch', () => { - let container: ?HTMLElement; function renderIntoDocument(instance: React.Element<*>): React.Component<*, *> { - if(container) { + if (container) { throw new Error('Unmount previously rendered component first.'); } container = document.createElement('div'); - if(!document.documentElement) { + if (!document.documentElement) { throw new Error('document.documentElement cannot be null.'); } @@ -27,7 +26,7 @@ describe('components/Switch', () => { // unmount container and clean up DOM afterEach(() => { - if(container) { + if (container) { ReactDOM.unmountComponentAtNode(container); container = null; } @@ -38,12 +37,10 @@ describe('components/Switch', () => { expect(isOn).to.be.true; done(); }; - const component = renderIntoDocument( - <Switch isOn={ false } onChange={ onChange } /> - ); + const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />); const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input'); // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 }); Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 }); Simulate.change(domNode, { target: { checked: true } }); @@ -55,12 +52,10 @@ describe('components/Switch', () => { expect(isOn).to.be.false; done(); }; - const component = renderIntoDocument( - <Switch isOn={ true } onChange={ onChange } /> - ); + const component = renderIntoDocument(<Switch isOn={true} onChange={onChange} />); const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input'); // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 }); Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 }); Simulate.change(domNode, { target: { checked: false } }); @@ -72,12 +67,10 @@ describe('components/Switch', () => { expect(isOn).to.be.true; done(); }; - const component = renderIntoDocument( - <Switch isOn={ false } onChange={ onChange } /> - ); + const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />); const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input'); // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 }); } @@ -91,13 +84,11 @@ describe('components/Switch', () => { expect(isOn).to.be.false; done(); }; - const component = renderIntoDocument( - <Switch isOn={ true } onChange={ onChange } /> - ); + const component = renderIntoDocument(<Switch isOn={true} onChange={onChange} />); const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input'); // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { Simulate.mouseDown(domNode, { clientX: 150, clientY: 0 }); } @@ -111,13 +102,11 @@ describe('components/Switch', () => { throw new Error('onChange should not be called on timeout.'); }; - const component = renderIntoDocument( - <Switch isOn={ false } onChange={ onChange } /> - ); + const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />); const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input'); // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 }); } @@ -127,15 +116,14 @@ describe('components/Switch', () => { try { // See: https://github.com/facebook/flow/pull/5841 - if(domNode) { + if (domNode) { // should not trigger onChange() Simulate.change(domNode); } done(); - } catch(e) { + } catch (e) { done(e); } }, 1000); }); - -});
\ No newline at end of file +}); diff --git a/test/connect.spec.js b/test/connect.spec.js index 056e1bfe15..0b5b33be53 100644 --- a/test/connect.spec.js +++ b/test/connect.spec.js @@ -5,20 +5,17 @@ import connectionActions from '../app/redux/connection/actions'; import { setupBackendAndStore, checkNextTick } from './helpers/ipc-helpers'; describe('connect', () => { - - it('should set the connection state to \'disconnected\' on failed attempts', (done) => { + it("should set the connection state to 'disconnected' on failed attempts", (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); mockIpc.connect = () => new Promise((_, reject) => reject('Some error')); store.dispatch(connectionActions.connected()); - expect(store.getState().connection.status).not.to.equal('disconnected'); store.dispatch(connectionActions.connect(backend)); - checkNextTick(() => { expect(store.getState().connection.status).to.equal('disconnected'); }, done); @@ -27,41 +24,40 @@ describe('connect', () => { it('should update the state with the server address', () => { const { store, backend } = setupBackendAndStore(); - return backend.connect() - .then( () => { - const state = store.getState().connection; - expect(state.status).to.equal('connecting'); - }); + return backend.connect().then(() => { + const state = store.getState().connection; + expect(state.status).to.equal('connecting'); + }); }); - it('should correctly deduce \'connected\' from backend states', (done) => { + it("should correctly deduce 'connected' from backend states", (done) => { const { store, mockIpc } = setupBackendAndStore(); - checkNextTick( () => { + checkNextTick(() => { expect(store.getState().connection.status).not.to.equal('connected'); mockIpc.sendNewState({ state: 'secured', target_state: 'secured' }); expect(store.getState().connection.status).to.equal('connected'); }, done); }); - it('should correctly deduce \'connecting\' from backend states', (done) => { + it("should correctly deduce 'connecting' from backend states", (done) => { const { store, mockIpc } = setupBackendAndStore(); - checkNextTick( () => { + checkNextTick(() => { expect(store.getState().connection.status).not.to.equal('connecting'); mockIpc.sendNewState({ state: 'unsecured', target_state: 'secured' }); expect(store.getState().connection.status).to.equal('connecting'); }, done); }); - it('should correctly deduce \'disconnected\' from backend states', (done) => { + it("should correctly deduce 'disconnected' from backend states", (done) => { const { store, mockIpc } = setupBackendAndStore(); store.dispatch(connectionActions.connected()); - checkNextTick( () => { + checkNextTick(() => { expect(store.getState().connection.status).not.to.equal('disconnected'); mockIpc.sendNewState({ state: 'unsecured', target_state: 'unsecured' }); expect(store.getState().connection.status).to.equal('disconnected'); }, done); }); -});
\ No newline at end of file +}); diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js index 4e3ddea79e..44a1c7b0d7 100644 --- a/test/helpers/IpcChain.js +++ b/test/helpers/IpcChain.js @@ -25,7 +25,7 @@ export class IpcChain { _addStep<R>(step: StepBuilder<R>) { const me = this; this._mockIpc[step.ipcCall] = function() { - return new Promise(r => me._stepPromiseCallback(step, r, arguments)); + return new Promise((r) => me._stepPromiseCallback(step, r, arguments)); }; } diff --git a/test/helpers/dom-events.js b/test/helpers/dom-events.js index 6d5b069e08..2d8b4be3cf 100644 --- a/test/helpers/dom-events.js +++ b/test/helpers/dom-events.js @@ -12,11 +12,11 @@ const keycodes = { '0': { which: 48, keyCode: 48 }, Tab: { which: 9, keyCode: 9 }, Enter: { which: 13, keyCode: 13 }, - Backspace: { which: 8, keyCode: 8 } + Backspace: { which: 8, keyCode: 8 }, }; export type Keycode = $Keys<typeof keycodes>; export function createKeyEvent(key: Keycode): Object { - return Object.assign({}, { key }, keycodes[key], {preventDefault: () => {}}); //preventDefault is needed to mock key events for onKeyPress in AccountInput + return Object.assign({}, { key }, keycodes[key], { preventDefault: () => {} }); //preventDefault is needed to mock key events for onKeyPress in AccountInput } diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js index 3f8307ccf3..4466c06eb2 100644 --- a/test/helpers/ipc-helpers.js +++ b/test/helpers/ipc-helpers.js @@ -19,7 +19,6 @@ export function setupIpcAndStore() { } export function setupBackendAndStore() { - const { store, mockIpc } = setupIpcAndStore(); const credentials = { @@ -69,7 +68,6 @@ export function checkNextTick(fn: Check, done: DoneCallback) { }, 1); } - // In async tests where we want to test a chain of IPC messages // we can only invoke `done` for the last message. This function // is for the intermediate messages. @@ -77,7 +75,7 @@ export function failFast(fn: Check, done: DoneCallback): boolean { try { fn(); return false; - } catch(e) { + } catch (e) { done(e); return true; } @@ -89,17 +87,18 @@ export function failFastNextTick(fn: Check, done: DoneCallback) { } type MockStore = { - getActions: () => Array<{type: string, payload: Object}>, -} + getActions: () => Array<{ type: string, payload: Object }>, +}; // Parses the action log to find out which URL we most recently navigated to // Note that this cannot be done with the real redux store, but rather must be // done with the mock store. export function getLocation(store: MockStore): ?string { - const navigations = store.getActions().filter(action => action.type === '@@router/CALL_HISTORY_METHOD'); + const navigations = store + .getActions() + .filter((action) => action.type === '@@router/CALL_HISTORY_METHOD'); if (navigations.length === 0) { return null; } return navigations[navigations.length - 1].payload.args[0]; } - diff --git a/test/ipc.spec.js b/test/ipc.spec.js index 6e02ab94b1..15009bb639 100644 --- a/test/ipc.spec.js +++ b/test/ipc.spec.js @@ -7,16 +7,14 @@ import assert from 'assert'; import type { JsonRpcMessage } from '../app/lib/jsonrpc-ws-ipc.js'; describe('The IPC server', () => { - it('should send as soon as the websocket connects', () => { const { ws, ipc } = setupIpc(); ws.close(); let sent = false; - const p = ipc.send('hello') - .then(() => { - expect(sent).to.be.true; - }); + const p = ipc.send('hello').then(() => { + expect(sent).to.be.true; + }); ws.on('hello', (msg) => { sent = true; @@ -34,11 +32,10 @@ describe('The IPC server', () => { ws.replyFail(msg.id, 'Method not found', -32601); }); - return ipc.send('WHAT_IS_THIS') - .catch((e) => { - expect(e.code).to.equal(-32601); - expect(e.message).to.contain('Method not found'); - }); + return ipc.send('WHAT_IS_THIS').catch((e) => { + expect(e.code).to.equal(-32601); + expect(e.message).to.contain('Method not found'); + }); }); it('should route reply to correct promise', () => { @@ -46,15 +43,15 @@ describe('The IPC server', () => { ws.on('a message', (msg) => ws.replyOk(msg.id, 'a reply')); - const decoy = ipc.send('a decoy', [], 1) + const decoy = ipc + .send('a decoy', [], 1) .then(() => assert(false, 'Should not be called')) - .catch(e => { + .catch((e) => { if (e.name !== 'TimeOutError') { throw e; } }); - const message = ipc.send('a message', [], 1) - .then((reply) => expect(reply).to.equal('a reply')); + const message = ipc.send('a message', [], 1).then((reply) => expect(reply).to.equal('a reply')); return Promise.all([message, decoy]); }); @@ -62,11 +59,10 @@ describe('The IPC server', () => { it('should timeout if no response is returned', () => { const { ipc } = setupIpc(); - return ipc.send('a message', [], 1) - .catch((e) => { - expect(e.name).to.equal('TimeOutError'); - expect(e.message).to.contain('timed out'); - }); + return ipc.send('a message', [], 1).catch((e) => { + expect(e.name).to.equal('TimeOutError'); + expect(e.message).to.contain('timed out'); + }); }); it('should route notifications', (done) => { @@ -82,21 +78,22 @@ describe('The IPC server', () => { }; ws.on('event_subscribe', (msg) => ws.replyOk(msg.id, 1)); - ipc.on('event', eventListener) + ipc + .on('event', eventListener) .then(() => { - ws.reply(jsonrpc.notification('event', {subscription:1, result: 'an event!'})); + ws.reply(jsonrpc.notification('event', { subscription: 1, result: 'an event!' })); }) .catch((e) => done(e)); }); }); function mockWebsocket() { - const ws : any = { + const ws: any = { listeners: {}, readyState: 1, }; - ws.on = (event, listener) => ws.listeners[event] = listener; + ws.on = (event, listener) => (ws.listeners[event] = listener); ws.send = (data) => { const listener = ws.listeners[data.method]; if (listener) { @@ -116,7 +113,7 @@ function mockWebsocket() { }; ws.reply = (msg: JsonRpcMessage) => { - ws.onmessage({data: JSON.stringify(msg)}); + ws.onmessage({ data: JSON.stringify(msg) }); }; ws.replyOk = (id: string, msg) => { ws.reply(jsonrpc.success(id, msg || '')); @@ -135,4 +132,3 @@ function setupIpc() { ipc: new Ipc('1.2.3.4', ws.factory), }; } - diff --git a/test/keyframe-animation.spec.js b/test/keyframe-animation.spec.js index 539efb858c..5153719497 100644 --- a/test/keyframe-animation.spec.js +++ b/test/keyframe-animation.spec.js @@ -50,7 +50,7 @@ describe('lib/keyframe-animation', function() { animation.play({ startFrame: 2, - endFrame: 4 + endFrame: 4, }); }); @@ -67,7 +67,7 @@ describe('lib/keyframe-animation', function() { animation.reverse = true; animation.play({ startFrame: 4, - endFrame: 2 + endFrame: 2, }); }); @@ -87,7 +87,7 @@ describe('lib/keyframe-animation', function() { animation.play({ beginFromCurrentState: true, startFrame: 3, - endFrame: 4 + endFrame: 4, }); }); @@ -108,7 +108,7 @@ describe('lib/keyframe-animation', function() { animation.play({ beginFromCurrentState: true, startFrame: 3, - endFrame: 4 + endFrame: 4, }); }); @@ -128,7 +128,7 @@ describe('lib/keyframe-animation', function() { animation.play({ beginFromCurrentState: true, startFrame: 1, - endFrame: 2 + endFrame: 2, }); }); @@ -149,7 +149,7 @@ describe('lib/keyframe-animation', function() { animation.play({ beginFromCurrentState: true, startFrame: 1, - endFrame: 3 + endFrame: 3, }); }); @@ -173,7 +173,7 @@ describe('lib/keyframe-animation', function() { const expectedFrames = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]; animation.onFrame = () => { - if(seq.length === expectedFrames.length) { + if (seq.length === expectedFrames.length) { animation.stop(); expect(seq).to.be.deep.equal(expectedFrames); done(); @@ -192,7 +192,7 @@ describe('lib/keyframe-animation', function() { const expectedFrames = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0]; animation.onFrame = () => { - if(seq.length === expectedFrames.length) { + if (seq.length === expectedFrames.length) { animation.stop(); expect(seq).to.be.deep.equal(expectedFrames); done(); @@ -212,7 +212,7 @@ describe('lib/keyframe-animation', function() { const expectedFrames = [0, 1, 2, 3, 4, 3, 2, 1, 0]; animation.onFrame = () => { - if(seq.length === expectedFrames.length) { + if (seq.length === expectedFrames.length) { animation.stop(); expect(seq).to.be.deep.equal(expectedFrames); done(); @@ -232,7 +232,7 @@ describe('lib/keyframe-animation', function() { const expectedFrames = [4, 3, 2, 1, 0, 1, 2, 3, 4]; animation.onFrame = () => { - if(seq.length === expectedFrames.length) { + if (seq.length === expectedFrames.length) { animation.stop(); expect(seq).to.be.deep.equal(expectedFrames); done(); @@ -246,5 +246,4 @@ describe('lib/keyframe-animation', function() { animation.alternate = true; animation.play(); }); - -});
\ No newline at end of file +}); diff --git a/test/login.spec.js b/test/login.spec.js index 1efe89ae38..acb38db2eb 100644 --- a/test/login.spec.js +++ b/test/login.spec.js @@ -1,23 +1,31 @@ // @flow import { expect } from 'chai'; -import { setupBackendAndStore, setupBackendAndMockStore, checkNextTick, getLocation, failFast, check } from './helpers/ipc-helpers'; +import { + setupBackendAndStore, + setupBackendAndMockStore, + checkNextTick, + getLocation, + failFast, + check, +} from './helpers/ipc-helpers'; import { IpcChain } from './helpers/IpcChain'; import accountActions from '../app/redux/account/actions'; describe('Logging in', () => { - it('should validate the account number and then set it in the backend', (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); const chain = new IpcChain(mockIpc); - chain.require('getAccountData') + chain + .require('getAccountData') .withInputValidation((an) => { expect(an).to.equal('123'); }) .done(); - chain.require('setAccount') + chain + .require('setAccount') .withInputValidation((an) => { expect(an).to.equal('123'); }) @@ -30,26 +38,28 @@ describe('Logging in', () => { it('should put the account data in the state', () => { const { store, backend, mockIpc } = setupBackendAndStore(); - mockIpc.getAccountData = () => new Promise(r => r({ - expiry: '2001-01-01T00:00:00Z', - })); + mockIpc.getAccountData = () => + new Promise((r) => + r({ + expiry: '2001-01-01T00:00:00Z', + }), + ); - return backend.login('123') - .then( () => { - const state = store.getState().account; - expect(state.status).to.equal('ok'); - expect(state.accountToken).to.equal('123'); - expect(state.expiry).to.equal('2001-01-01T00:00:00Z'); - }); + return backend.login('123').then(() => { + const state = store.getState().account; + expect(state.status).to.equal('ok'); + expect(state.accountToken).to.equal('123'); + expect(state.expiry).to.equal('2001-01-01T00:00:00Z'); + }); }); it('should indicate failure for non-existing accounts', (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); - mockIpc.getAccountData = (_num) => new Promise((_, reject) => { - reject('NO SUCH ACCOUNT'); - }); - + mockIpc.getAccountData = (_num) => + new Promise((_, reject) => { + reject('NO SUCH ACCOUNT'); + }); store.dispatch(accountActions.login(backend, '123')); @@ -66,20 +76,15 @@ describe('Logging in', () => { store.dispatch(accountActions.login(backend, '123')); setTimeout(() => { - failFast(() => { expect(getLocation(store)).not.to.equal('/connect'); }, done); - }, 100); - setTimeout(() => { - check(() => { expect(getLocation(store)).to.equal('/connect'); }, done); - }, 1100); }); }); diff --git a/test/logout.spec.js b/test/logout.spec.js index 0e295aef9b..c7ed45adb2 100644 --- a/test/logout.spec.js +++ b/test/logout.spec.js @@ -1,35 +1,41 @@ // @flow import { expect } from 'chai'; -import { setupBackendAndStore, setupBackendAndMockStore, getLocation, checkNextTick, failFastNextTick } from './helpers/ipc-helpers'; +import { + setupBackendAndStore, + setupBackendAndMockStore, + getLocation, + checkNextTick, + failFastNextTick, +} from './helpers/ipc-helpers'; import { IpcChain } from './helpers/IpcChain'; import accountActions from '../app/redux/account/actions'; describe('logging out', () => { - it('should set the account to null and then disconnect', (done) => { const { mockIpc, backend } = setupBackendAndStore(); const chain = new IpcChain(mockIpc); - chain.require('setAccount') + chain + .require('setAccount') .withInputValidation((num) => { expect(num).to.be.null; }) .done(); - chain.require('disconnect') - .done(); + chain.require('disconnect').done(); chain.onSuccessOrFailure(done); backend.logout(); }); - it('should remove the account number from the store', (done) => { - const { store, backend, mockIpc } = setupBackendAndStore(); - mockIpc.getAccountData = () => new Promise(r => r({ - expiry: '2001-01-01T00:00:00.000Z', - })); + mockIpc.getAccountData = () => + new Promise((r) => + r({ + expiry: '2001-01-01T00:00:00.000Z', + }), + ); const action: any = accountActions.login(backend, '123'); store.dispatch(action); @@ -53,7 +59,6 @@ describe('logging out', () => { }, done); }); - it('should redirect to / on logout', (done) => { const { store, backend } = setupBackendAndMockStore(); diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index 900e149c33..cd8dc9fbac 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -11,22 +11,22 @@ interface MockIpc { } export function newMockIpc() { - const stateListeners = []; const connectionCloseListeners = []; const mockIpc: IpcFacade & MockIpc = { - setConnectionString: (_str: string) => {}, - getAccountData: (accountToken) => Promise.resolve({ - accountToken: accountToken, - expiry: '', - }), + getAccountData: (accountToken) => + Promise.resolve({ + accountToken: accountToken, + expiry: '', + }), - getRelayLocations: () => Promise.resolve({ - countries: [], - }), + getRelayLocations: () => + Promise.resolve({ + countries: [], + }), getAccount: () => Promise.resolve('1111'), @@ -34,17 +34,18 @@ export function newMockIpc() { updateRelaySettings: () => Promise.resolve(), - getRelaySettings: () => Promise.resolve({ - custom_tunnel_endpoint: { - host: 'www.example.com', - tunnel: { - openvpn: { - port: 1301, - protocol: 'udp', - } - } - }, - }), + getRelaySettings: () => + Promise.resolve({ + custom_tunnel_endpoint: { + host: 'www.example.com', + tunnel: { + openvpn: { + port: 1301, + protocol: 'udp', + }, + }, + }, + }), setAllowLan: (_allowLan: boolean) => Promise.resolve(), @@ -56,26 +57,28 @@ export function newMockIpc() { shutdown: () => Promise.resolve(), - getLocation: () => Promise.resolve({ - ip: '', - country: '', - city: '', - latitude: 0.0, - longitude: 0.0, - mullvad_exit_ip: false, - }), + getLocation: () => + Promise.resolve({ + ip: '', + country: '', + city: '', + latitude: 0.0, + longitude: 0.0, + mullvad_exit_ip: false, + }), - getState: () => Promise.resolve({ - state: 'unsecured', - target_state:'unsecured', - }), + getState: () => + Promise.resolve({ + state: 'unsecured', + target_state: 'unsecured', + }), registerStateListener: (listener: (BackendState) => void) => { stateListeners.push(listener); }, sendNewState: (state: BackendState) => { - for(const l of stateListeners) { + for (const l of stateListeners) { l(state); } }, @@ -91,10 +94,10 @@ export function newMockIpc() { removeAccountFromHistory: (_accountToken) => Promise.resolve(), killWebSocket: () => { - for(const l of connectionCloseListeners) { + for (const l of connectionCloseListeners) { l(); } - } + }, }; return mockIpc; diff --git a/test/mocks/redux.js b/test/mocks/redux.js index a652009645..bbab7b17f4 100644 --- a/test/mocks/redux.js +++ b/test/mocks/redux.js @@ -1,4 +1,4 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; -export const mockStore = configureMockStore([ thunk ]); +export const mockStore = configureMockStore([thunk]); diff --git a/test/relay-settings-builder.spec.js b/test/relay-settings-builder.spec.js index 3f27d2df23..a2d69ceca6 100644 --- a/test/relay-settings-builder.spec.js +++ b/test/relay-settings-builder.spec.js @@ -4,89 +4,87 @@ import { expect } from 'chai'; import RelaySettingsBuilder from '../app/lib/relay-settings-builder'; describe('Relay settings builder', () => { - it('should set location to any', () => { expect( RelaySettingsBuilder.normal() - .location - .any() - .build() + .location.any() + .build(), ).to.deep.equal({ normal: { - location: 'any' - } + location: 'any', + }, }); }); it('should bound location to city', () => { expect( RelaySettingsBuilder.normal() - .location.city('se', 'mma').build() + .location.city('se', 'mma') + .build(), ).to.deep.equal({ normal: { location: { only: { - city: ['se', 'mma'] - } - } - } + city: ['se', 'mma'], + }, + }, + }, }); }); it('should bound location to country', () => { expect( RelaySettingsBuilder.normal() - .location.country('se').build() + .location.country('se') + .build(), ).to.deep.equal({ normal: { location: { - only: { country: 'se' } - } - } + only: { country: 'se' }, + }, + }, }); }); it('should set openvpn settings to any', () => { expect( RelaySettingsBuilder.normal() - .tunnel.openvpn(openvpn => { - openvpn.port.any() - .protocol.any(); + .tunnel.openvpn((openvpn) => { + openvpn.port.any().protocol.any(); }) - .build() + .build(), ).to.deep.equal({ normal: { tunnel: { only: { openvpn: { port: 'any', - protocol: 'any' - } - } - } - } + protocol: 'any', + }, + }, + }, + }, }); }); it('should set openvpn settings to exact values', () => { expect( RelaySettingsBuilder.normal() - .tunnel.openvpn(openvpn => { - openvpn.port.exact(80) - .protocol.exact('tcp'); + .tunnel.openvpn((openvpn) => { + openvpn.port.exact(80).protocol.exact('tcp'); }) - .build() + .build(), ).to.deep.equal({ normal: { tunnel: { only: { openvpn: { port: { only: 80 }, - protocol: { only: 'tcp' } - } - } - } - } + protocol: { only: 'tcp' }, + }, + }, + }, + }, }); }); @@ -94,35 +92,35 @@ describe('Relay settings builder', () => { expect( RelaySettingsBuilder.normal() .location.fromRaw('any') - .build() + .build(), ).to.deep.equal({ normal: { - location: 'any' - } + location: 'any', + }, }); expect( RelaySettingsBuilder.normal() - .location.fromRaw({ country: 'se'}) - .build() + .location.fromRaw({ country: 'se' }) + .build(), ).to.deep.equal({ normal: { location: { - only: { country: 'se' } - } - } + only: { country: 'se' }, + }, + }, }); expect( RelaySettingsBuilder.normal() - .location.fromRaw({ city: ['se', 'mma']}) - .build() + .location.fromRaw({ city: ['se', 'mma'] }) + .build(), ).to.deep.equal({ normal: { location: { - only: { city: ['se', 'mma'] } - } - } + only: { city: ['se', 'mma'] }, + }, + }, }); }); @@ -131,21 +129,19 @@ describe('Relay settings builder', () => { RelaySettingsBuilder.custom() .host('se2.mullvad.net') .tunnel.openvpn((openvpn) => { - openvpn.port(80) - .protocol('tcp'); + openvpn.port(80).protocol('tcp'); }) - .build() + .build(), ).to.deep.equal({ custom_tunnel_endpoint: { host: 'se2.mullvad.net', tunnel: { openvpn: { port: 80, - protocol: 'tcp' - } - } - } + protocol: 'tcp', + }, + }, + }, }); }); - -});
\ No newline at end of file +}); diff --git a/test/transition-rule.spec.js b/test/transition-rule.spec.js index 647517ca5d..00fffff01e 100644 --- a/test/transition-rule.spec.js +++ b/test/transition-rule.spec.js @@ -5,7 +5,7 @@ import TransitionRule from '../app/lib/transition-rule'; describe('TransitionRule', () => { const testTransition = { forward: { name: 'forward', duration: 0.25 }, - backward: { name: 'backward', duration: 0.25 } + backward: { name: 'backward', duration: 0.25 }, }; it('should match wildcard rule', () => { @@ -13,12 +13,12 @@ describe('TransitionRule', () => { expect(rule.match(null, '/route')).to.deep.equal({ direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 } + descriptor: { name: 'forward', duration: 0.25 }, }); expect(rule.match('/somewhere', '/route')).to.deep.equal({ direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 } + descriptor: { name: 'forward', duration: 0.25 }, }); }); @@ -27,7 +27,7 @@ describe('TransitionRule', () => { expect(rule.match('/route', '/other')).to.deep.equal({ direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 } + descriptor: { name: 'backward', duration: 0.25 }, }); }); @@ -39,7 +39,7 @@ describe('TransitionRule', () => { expect(rule.match('/route1', '/route2')).to.deep.equal({ direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 } + descriptor: { name: 'forward', duration: 0.25 }, }); }); @@ -51,8 +51,7 @@ describe('TransitionRule', () => { expect(rule.match('/route2', '/route1')).to.deep.equal({ direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 } + descriptor: { name: 'backward', duration: 0.25 }, }); }); - -});
\ No newline at end of file +}); |
