/ common / features / addressBook / reducer.spec.ts
reducer.spec.ts
 1  import * as actions from './actions';
 2  import * as reducer from './reducer';
 3  
 4  describe('addressBook: Reducer', () => {
 5    it('should set an address label', () => {
 6      expect(
 7        reducer.addressBookReducer(
 8          undefined,
 9          actions.setAddressLabel({
10            address: '0x0',
11            label: 'Foo'
12          })
13        )
14      ).toEqual({
15        ...reducer.INITIAL_STATE,
16        addresses: {
17          '0x0': 'Foo'
18        },
19        labels: {
20          Foo: '0x0'
21        }
22      });
23    });
24    it('should clear an address label', () => {
25      const firstState = reducer.addressBookReducer(
26        undefined,
27        actions.setAddressLabel({
28          address: '0x0',
29          label: 'Foo'
30        })
31      );
32  
33      expect(reducer.addressBookReducer(firstState, actions.clearAddressLabel('0x0'))).toEqual(
34        reducer.INITIAL_STATE
35      );
36    });
37    it('should set an address label entry', () => {
38      expect(
39        reducer.addressBookReducer(
40          undefined,
41          actions.setAddressLabelEntry({
42            id: '0',
43            address: '0x0',
44            temporaryAddress: ' 0x0a',
45            addressError: 'Derp',
46            label: 'Foo',
47            temporaryLabel: 'Food',
48            labelError: 'Derp'
49          })
50        )
51      ).toEqual({
52        ...reducer.INITIAL_STATE,
53        entries: {
54          0: {
55            id: '0',
56            address: '0x0',
57            temporaryAddress: ' 0x0a',
58            addressError: 'Derp',
59            label: 'Foo',
60            temporaryLabel: 'Food',
61            labelError: 'Derp'
62          }
63        }
64      });
65    });
66    it('should clear an address label entry', () => {
67      const firstState = reducer.addressBookReducer(
68        undefined,
69        actions.setAddressLabelEntry({
70          id: '0',
71          address: '0x0',
72          temporaryAddress: ' 0x0a',
73          addressError: 'Derp',
74          label: 'Foo',
75          temporaryLabel: 'Food',
76          labelError: 'Derp'
77        })
78      );
79      expect(reducer.addressBookReducer(firstState, actions.clearAddressLabelEntry('0'))).toEqual(
80        reducer.INITIAL_STATE
81      );
82    });
83  });