/ common / features / deterministicWallets / reducer.spec.ts
reducer.spec.ts
 1  import { TokenValue } from 'libs/units';
 2  import configuredStore from 'features/store';
 3  import * as types from './types';
 4  import * as actions from './actions';
 5  import * as reducer from './reducer';
 6  
 7  configuredStore.getState();
 8  
 9  describe('deterministicWallets reducer', () => {
10    const tokenValues: types.ITokenValues = {
11      OMG: {
12        value: TokenValue('0'),
13        decimal: 16
14      }
15    };
16  
17    const wallet: types.DeterministicWalletData = {
18      index: 0,
19      address: 'address',
20      value: TokenValue('0'),
21      tokenValues
22    };
23  
24    it('should handle DW_SET_WALLETS', () => {
25      const wallets = [wallet];
26      expect(
27        reducer.deterministicWalletsReducer(undefined, actions.setDeterministicWallets(wallets))
28      ).toEqual({
29        ...reducer.INITIAL_STATE,
30        wallets
31      });
32    });
33  
34    it('should handle DW_SET_DESIRED_TOKEN', () => {
35      const desiredToken = 'OMG';
36      expect(
37        reducer.deterministicWalletsReducer(undefined, actions.setDesiredToken(desiredToken))
38      ).toEqual({
39        ...reducer.INITIAL_STATE,
40        desiredToken
41      });
42    });
43  
44    it('should handle DW_UPDATE_WALLET', () => {
45      const wallet1 = {
46        ...wallet,
47        address: 'wallet1'
48      };
49      const wallet2 = {
50        ...wallet,
51        address: 'wallet2'
52      };
53      const wallets = [wallet1, wallet2];
54      const state = reducer.deterministicWalletsReducer(
55        undefined,
56        actions.setDeterministicWallets(wallets)
57      );
58  
59      const wallet2Update = {
60        ...wallet,
61        index: 100,
62        address: 'wallet2',
63        value: TokenValue('100')
64      };
65  
66      expect(
67        reducer.deterministicWalletsReducer(state, actions.updateDeterministicWallet(wallet2Update))
68      ).toEqual({
69        ...reducer.INITIAL_STATE,
70        wallets: [wallet1, wallet2Update]
71      });
72    });
73  });