aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/ducks/tests/send-duck.test.js
blob: c06cf55d2a818e2cc7834087c17e2e00e32a46a0 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import assert from 'assert'

import SendReducer, {
  openFromDropdown,
  closeFromDropdown,
  openToDropdown,
  closeToDropdown,
  updateSendErrors,
} from '../send.duck.js'

describe('Send Duck', () => {
  const mockState = {
    send: {
      mockProp: 123,
    },
  }
  const initState = {
    fromDropdownOpen: false,
    toDropdownOpen: false,
    errors: {},
  }
  const OPEN_FROM_DROPDOWN = 'metamask/send/OPEN_FROM_DROPDOWN'
  const CLOSE_FROM_DROPDOWN = 'metamask/send/CLOSE_FROM_DROPDOWN'
  const OPEN_TO_DROPDOWN = 'metamask/send/OPEN_TO_DROPDOWN'
  const CLOSE_TO_DROPDOWN = 'metamask/send/CLOSE_TO_DROPDOWN'
  const UPDATE_SEND_ERRORS = 'metamask/send/UPDATE_SEND_ERRORS'

  describe('SendReducer()', () => {
    it('should initialize state', () => {
      assert.deepEqual(
        SendReducer({}),
        initState
      )
    })

    it('should return state unchanged if it does not match a dispatched actions type', () => {
      assert.deepEqual(
        SendReducer(mockState, {
          type: 'someOtherAction',
          value: 'someValue',
        }),
        Object.assign({}, mockState.send)
      )
    })

    it('should set fromDropdownOpen to true when receiving a OPEN_FROM_DROPDOWN action', () => {
      assert.deepEqual(
        SendReducer(mockState, {
          type: OPEN_FROM_DROPDOWN,
        }),
        Object.assign({fromDropdownOpen: true}, mockState.send)
      )
    })

    it('should return a new object (and not just modify the existing state object)', () => {
      assert.deepEqual(SendReducer(mockState), mockState.send)
      assert.notEqual(SendReducer(mockState), mockState.send)
    })

    it('should set fromDropdownOpen to false when receiving a CLOSE_FROM_DROPDOWN action', () => {
      assert.deepEqual(
        SendReducer(mockState, {
          type: CLOSE_FROM_DROPDOWN,
        }),
        Object.assign({fromDropdownOpen: false}, mockState.send)
      )
    })

    it('should set toDropdownOpen to true when receiving a OPEN_TO_DROPDOWN action', () => {
      assert.deepEqual(
        SendReducer(mockState, {
          type: OPEN_TO_DROPDOWN,
        }),
        Object.assign({toDropdownOpen: true}, mockState.send)
      )
    })

    it('should set toDropdownOpen to false when receiving a CLOSE_TO_DROPDOWN action', () => {
      assert.deepEqual(
        SendReducer(mockState, {
          type: CLOSE_TO_DROPDOWN,
        }),
        Object.assign({toDropdownOpen: false}, mockState.send)
      )
    })

    it('should extend send.errors with the value of a UPDATE_SEND_ERRORS action', () => {
      const modifiedMockState = Object.assign({}, mockState, {
        send: {
          errors: {
            someError: false,
          },
        },
      })
      assert.deepEqual(
        SendReducer(modifiedMockState, {
          type: UPDATE_SEND_ERRORS,
          value: { someOtherError: true },
        }),
        Object.assign({}, modifiedMockState.send, {
          errors: {
            someError: false,
            someOtherError: true,
          },
        })
      )
    })
  })

  describe('openFromDropdown', () => {
    assert.deepEqual(
      openFromDropdown(),
      { type: OPEN_FROM_DROPDOWN }
    )
  })

  describe('closeFromDropdown', () => {
    assert.deepEqual(
      closeFromDropdown(),
      { type: CLOSE_FROM_DROPDOWN }
    )
  })

  describe('openToDropdown', () => {
    assert.deepEqual(
      openToDropdown(),
      { type: OPEN_TO_DROPDOWN }
    )
  })

  describe('closeToDropdown', () => {
    assert.deepEqual(
      closeToDropdown(),
      { type: CLOSE_TO_DROPDOWN }
    )
  })

  describe('updateSendErrors', () => {
    assert.deepEqual(
      updateSendErrors('mockErrorObject'),
      { type: UPDATE_SEND_ERRORS, value: 'mockErrorObject' }
    )
  })

})