aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-component.test.js
blob: 54a92bd2d5df91cbafda4f6339ac0bd932447775 (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
import React from 'react'
import assert from 'assert'
import { shallow } from 'enzyme'
import sinon from 'sinon'
import SendGasRow from '../send-gas-row.component.js'

import SendRowWrapper from '../../send-row-wrapper/send-row-wrapper.component'
import GasFeeDisplay from '../gas-fee-display/gas-fee-display.component'

const propsMethodSpies = {
  showCustomizeGasModal: sinon.spy(),
}

describe('SendGasRow Component', function () {
  let wrapper

  beforeEach(() => {
    wrapper = shallow(<SendGasRow
      conversionRate={20}
      convertedCurrency={'mockConvertedCurrency'}
      gasFeeError={'mockGasFeeError'}
      gasLoadingError={false}
      gasTotal={'mockGasTotal'}
      showCustomizeGasModal={propsMethodSpies.showCustomizeGasModal}
    />, { context: { t: str => str + '_t' } })
  })

  afterEach(() => {
    propsMethodSpies.showCustomizeGasModal.resetHistory()
  })

  describe('render', () => {
    it('should render a SendRowWrapper component', () => {
      assert.equal(wrapper.find(SendRowWrapper).length, 1)
    })

    it('should pass the correct props to SendRowWrapper', () => {
      const {
        label,
        showError,
        errorType,
      } = wrapper.find(SendRowWrapper).props()

      assert.equal(label, 'gasFee_t:')
      assert.equal(showError, 'mockGasFeeError')
      assert.equal(errorType, 'gasFee')
    })

    it('should render a GasFeeDisplay as a child of the SendRowWrapper', () => {
      assert(wrapper.find(SendRowWrapper).childAt(0).is(GasFeeDisplay))
    })

    it('should render the GasFeeDisplay with the correct props', () => {
      const {
        conversionRate,
        convertedCurrency,
        gasLoadingError,
        gasTotal,
        onClick,
      } = wrapper.find(SendRowWrapper).childAt(0).props()
      assert.equal(conversionRate, 20)
      assert.equal(convertedCurrency, 'mockConvertedCurrency')
      assert.equal(gasLoadingError, false)
      assert.equal(gasTotal, 'mockGasTotal')
      assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 0)
      onClick()
      assert.equal(propsMethodSpies.showCustomizeGasModal.callCount, 1)
    })
  })
})