summaryrefslogtreecommitdiffhomepage
path: root/test/routing.spec.js
blob: 5b546e88513d54e8837d954b369a5be3beb75133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { expect } from 'chai';

import { filterIpUpdateActions, mockBackend, mockState, mockStore } from './mocks/backend';
import userActions from '../app/actions/user';
import mapBackendEventsToRouter from '../app/lib/backend-routing';
import { LoginState } from '../app/enums';

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'));
  });

});