aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js
blob: 4067265b5247388a3ef2568f3d362ec9a8ac22c5 (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
import assert from 'assert'
import proxyquire from 'proxyquire'
import sinon from 'sinon'

let mapStateToProps
let mapDispatchToProps

const actionSpies = {
  hideModal: sinon.spy(),
}

const customGasActionSpies = {
  setCustomGasPrice: sinon.spy(),
  setCustomGasLimit: sinon.spy(),
}

proxyquire('../gas-modal-page-container.container.js', {
  'react-redux': {
    connect: (ms, md) => {
      mapStateToProps = ms
      mapDispatchToProps = md
      return () => ({})
    },
  },
  '../../../selectors/custom-gas': {
    getCustomGasPrice: (s) => `mockGasPrice:${s}`,
    getCustomGasLimit: (s) => `mockGasLimit:${s}`,
    getBasicGasEstimateLoadingStatus: (s) => `mockBasicGasEstimateLoadingStatus:${s}`,
    getRenderableBasicEstimateData: (s) => `mockRenderableBasicEstimateData:${s}`,
  },
  '../../../actions': actionSpies,
  '../../../ducks/gas.duck': customGasActionSpies,
})

describe('gas-modal-page-container container', () => {

  describe('mapStateToProps()', () => {

    it('should map the correct properties to props', () => {
      assert.equal(mapStateToProps('mockState').customGasPrice, 'mockGasPrice:mockState')
      assert.equal(mapStateToProps('mockState').customGasLimit, 'mockGasLimit:mockState')
      assert.equal(mapStateToProps('mockState').gasPriceButtonGroupProps.buttonDataLoading, 'mockBasicGasEstimateLoadingStatus:mockState')
      assert.equal(mapStateToProps('mockState').gasPriceButtonGroupProps.gasButtonInfo, 'mockRenderableBasicEstimateData:mockState')
    })

  })

  describe('mapDispatchToProps()', () => {
    let dispatchSpy
    let mapDispatchToPropsObject

    beforeEach(() => {
      dispatchSpy = sinon.spy()
      mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
    })

    describe('hideModal()', () => {
      it('should dispatch a hideModal action', () => {
        mapDispatchToPropsObject.hideModal()
        assert(dispatchSpy.calledOnce)
        assert(actionSpies.hideModal.calledOnce)
      })
    })

    describe('updateCustomGasPrice()', () => {
      it('should dispatch a setCustomGasPrice action', () => {
        mapDispatchToPropsObject.updateCustomGasPrice()
        assert(dispatchSpy.calledOnce)
        assert(customGasActionSpies.setCustomGasPrice.calledOnce)
      })
    })

    describe('updateCustomGasLimit()', () => {
      it('should dispatch a setCustomGasLimit action', () => {
        mapDispatchToPropsObject.updateCustomGasLimit()
        assert(dispatchSpy.calledOnce)
        assert(customGasActionSpies.setCustomGasLimit.calledOnce)
      })
    })

  })

})