aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/gas-customization/gas-modal-page-container/basic-tab-content/tests/basic-tab-content-component.test.js
blob: 25abdd997bf2bf7c7d8ad68fb933808559c0075e (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
import React from 'react'
import assert from 'assert'
import { shallow } from 'enzyme'
import BasicTabContent from '../basic-tab-content.component'

import GasPriceButtonGroup from '../../../gas-price-button-group/'
import Loading from '../../../../loading-screen'

const mockGasPriceButtonGroupProps = {
  buttonDataLoading: false,
  className: 'gas-price-button-group',
  gasButtonInfo: [
    {
      feeInPrimaryCurrency: '$0.52',
      feeInSecondaryCurrency: '0.0048 ETH',
      timeEstimate: '~ 1 min 0 sec',
      priceInHexWei: '0xa1b2c3f',
    },
    {
      feeInPrimaryCurrency: '$0.39',
      feeInSecondaryCurrency: '0.004 ETH',
      timeEstimate: '~ 1 min 30 sec',
      priceInHexWei: '0xa1b2c39',
    },
    {
      feeInPrimaryCurrency: '$0.30',
      feeInSecondaryCurrency: '0.00354 ETH',
      timeEstimate: '~ 2 min 1 sec',
      priceInHexWei: '0xa1b2c30',
    },
  ],
  handleGasPriceSelection: newPrice => console.log('NewPrice: ', newPrice),
  noButtonActiveByDefault: true,
  showCheck: true,
}

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

  beforeEach(() => {
    wrapper = shallow(<BasicTabContent
      gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
    />)
  })

  describe('render', () => {
    it('should have a title', () => {
      assert(wrapper.find('.basic-tab-content').childAt(0).hasClass('basic-tab-content__title'))
    })

    it('should render a GasPriceButtonGroup compenent', () => {
      assert.equal(wrapper.find(GasPriceButtonGroup).length, 1)
    })

    it('should pass correct props to GasPriceButtonGroup', () => {
      const {
        buttonDataLoading,
        className,
        gasButtonInfo,
        handleGasPriceSelection,
        noButtonActiveByDefault,
        showCheck,
      } = wrapper.find(GasPriceButtonGroup).props()
      assert.equal(wrapper.find(GasPriceButtonGroup).length, 1)
      assert.equal(buttonDataLoading, mockGasPriceButtonGroupProps.buttonDataLoading)
      assert.equal(className, mockGasPriceButtonGroupProps.className)
      assert.equal(noButtonActiveByDefault, mockGasPriceButtonGroupProps.noButtonActiveByDefault)
      assert.equal(showCheck, mockGasPriceButtonGroupProps.showCheck)
      assert.deepEqual(gasButtonInfo, mockGasPriceButtonGroupProps.gasButtonInfo)
      assert.equal(JSON.stringify(handleGasPriceSelection), JSON.stringify(mockGasPriceButtonGroupProps.handleGasPriceSelection))
    })

    it('should render a loading component instead of the GasPriceButtonGroup if gasPriceButtonGroupProps.loading is true', () => {
      wrapper.setProps({
        gasPriceButtonGroupProps: { ...mockGasPriceButtonGroupProps, loading: true },
      })

      assert.equal(wrapper.find(GasPriceButtonGroup).length, 0)
      assert.equal(wrapper.find(Loading).length, 1)
    })
  })
})