diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/connect.spec.js | 34 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 84 |
2 files changed, 73 insertions, 45 deletions
diff --git a/test/connect.spec.js b/test/connect.spec.js index 20b182107a..56fdb76afc 100644 --- a/test/connect.spec.js +++ b/test/connect.spec.js @@ -23,19 +23,6 @@ describe('connect', () => { store.dispatch(connectionActions.connect(backend, 'example.com')); }); - it('should update the state with the connection info once connection is established', (done) => { - const { store, backend } = setupBackendAndStore(); - - store.dispatch(connectionActions.connect(backend, 'example.com')); - - checkNextTick( () => { - const state = store.getState().connection; - - expect(state.status).to.equal('connected'); - expect(state.serverAddress).to.equal('example.com'); - }, done); - }); - it('should set the connection state to \'disconnected\' on failed attempts', (done) => { const { store, mockIpc, backend } = setupBackendAndStore(); @@ -55,5 +42,26 @@ describe('connect', () => { expect(store.getState().connection.status).to.equal('disconnected'); }, done); }); + + it('should update the store on \'secured\' state from the backend', () => { + const { store, mockIpc } = setupBackendAndStore(); + + expect(store.getState().connection.status).not.to.equal('connected'); + mockIpc.sendNewState('secured'); + expect(store.getState().connection.status).to.equal('connected'); + + }); + + it('should update the store on \'unsecured\' state from the backend', () => { + const { store, mockIpc } = setupBackendAndStore(); + store.dispatch(connectionActions.connectionChange({ + status: 'connected', + })); + + expect(store.getState().connection.status).not.to.equal('disconnected'); + mockIpc.sendNewState('unsecured'); + expect(store.getState().connection.status).to.equal('disconnected'); + + }); }); diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index bb1a872454..3225fe9ed9 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -1,37 +1,57 @@ // @flow -import type { IpcFacade } from '../../app/lib/ipc-facade'; +import type { IpcFacade, BackendState } from '../../app/lib/ipc-facade'; -export function newMockIpc() { - return Object.assign({}, mockIpc); +interface MockIpc { + sendNewState: (BackendState) => void; + -getAccountData: *; + -connect: *; } -const mockIpc: IpcFacade = { +export function newMockIpc() { + + const stateListeners = []; - getAccountData: () => { - return new Promise(r => r({ - paid_until: '', - })); - }, - setAccount: () => { - return new Promise(r => r()); - }, - setCountry: () => { - return new Promise(r => r()); - }, - connect: () => { - return new Promise(r => r()); - }, - disconnect: () => { - return new Promise(r => r()); - }, - getIp: () => { - return new Promise(r => r('1.2.3.4')); - }, - getLocation: () => { - return new Promise(r => r({ - city: '', - country: '', - latlong: [], - })); - }, -}; + const mockIpc: IpcFacade & MockIpc = { + + getAccountData: () => { + return new Promise(r => r({ + paid_until: '', + })); + }, + setAccount: () => { + return new Promise(r => r()); + }, + setCountry: () => { + return new Promise(r => r()); + }, + connect: () => { + return new Promise(r => r()); + }, + disconnect: () => { + return new Promise(r => r()); + }, + getIp: () => { + return new Promise(r => r('1.2.3.4')); + }, + getLocation: () => { + return new Promise(r => r({ + city: '', + country: '', + latlong: [], + })); + }, + getState: () => { + return new Promise(r => r('unsecured')); + }, + registerStateListener: (listener: (BackendState) => void) => { + stateListeners.push(listener); + }, + sendNewState: (state: BackendState) => { + for(const l of stateListeners) { + l(state); + } + }, + }; + + return mockIpc; +} |
