diff options
| author | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-01 12:18:34 +0000 |
|---|---|---|
| committer | Andrej Mihajlov <and@codeispoetry.ru> | 2017-03-01 12:18:34 +0000 |
| commit | f2387c73988fac583adf0f9d4ee69e1d85c8d75b (patch) | |
| tree | f9f4e72af4a0fdbf0a610aa1ad8f07c96f6dab35 /test | |
| parent | 61b84e23036b3dbd032ce65b2a6021f531eaed03 (diff) | |
| download | mullvadvpn-f2387c73988fac583adf0f9d4ee69e1d85c8d75b.tar.xz mullvadvpn-f2387c73988fac583adf0f9d4ee69e1d85c8d75b.zip | |
Add routing tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/routing.spec.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/routing.spec.js b/test/routing.spec.js new file mode 100644 index 0000000000..aaedfa7f1f --- /dev/null +++ b/test/routing.spec.js @@ -0,0 +1,56 @@ +import { expect } from 'chai'; + +import { filterIpUpdateActions, mockBackend, mockState, mockStore } from './support'; +import userActions from '../app/actions/user'; +import mapBackendEventsToRouter from '../app/lib/backend-routing'; +import { LoginState } from '../app/constants'; + +describe('routing', function() { + this.timeout(10000); + + it('should redirect to login screen on logout', () => { + const expectedActions = [ + { type: '@@router/CALL_HISTORY_METHOD', payload: { method: 'replace', args: [ '/' ] } } + ]; + + let state = Object.assign(mockState(), { + user: { + account: '1111234567890', + status: LoginState.ok + } + }); + + const store = mockStore(state); + const backend = mockBackend(store); + mapBackendEventsToRouter(backend, store); + + store.dispatch(userActions.logout(backend)); + + const storeActions = filterIpUpdateActions(store.getActions()); + expect(storeActions).deep.equal(expectedActions); + }); + + it('should redirect to connect screen on login', (done) => { + const expectedActions = [ + { type: '@@router/CALL_HISTORY_METHOD', payload: { method: 'replace', args: [ '/connect' ] } } + ]; + + let state = Object.assign(mockState(), { + user: { + account: '1111234567890', + status: LoginState.none + } + }); + const store = mockStore(state); + const backend = mockBackend(store); + mapBackendEventsToRouter(backend, store); + + store.subscribe(() => { + const storeActions = filterIpUpdateActions(store.getActions()); + expect(storeActions).deep.equal(expectedActions); + done(); + }); + store.dispatch(userActions.login(backend, '1111234567890')); + }); + +}); |
