aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/pages/send/send-content/tests/send-content-component.test.js
blob: 451d2ea53a59b961e07eec9577270123284a190a (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
import React from 'react'
import assert from 'assert'
import { shallow } from 'enzyme'
import SendContent from '../send-content.component.js'

import PageContainerContent from '../../../../components/ui/page-container/page-container-content.component'
import SendAmountRow from '../send-amount-row/send-amount-row.container'
import SendGasRow from '../send-gas-row/send-gas-row.container'
import SendHexDataRow from '../send-hex-data-row/send-hex-data-row.container'
import SendAssetRow from '../send-asset-row/send-asset-row.container'
import Dialog from '../../../../components/ui/dialog'

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

  beforeEach(() => {
    wrapper = shallow(
      <SendContent
        showHexData={true}
      />,
      { context: { t: str => str + '_t' } }
    )
  })

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

    it('should render a div with a .send-v2__form class as a child of PageContainerContent', () => {
      const PageContainerContentChild = wrapper.find(PageContainerContent).children()
      PageContainerContentChild.is('div')
      PageContainerContentChild.is('.send-v2__form')
    })

    it('should render the correct row components as grandchildren of the PageContainerContent component', () => {
      const PageContainerContentChild = wrapper.find(PageContainerContent).children()
      assert(PageContainerContentChild.childAt(0).is(Dialog), 'row[0] should be Dialog')
      assert(PageContainerContentChild.childAt(1).is(SendAssetRow), 'row[1] should be SendAssetRow')
      assert(PageContainerContentChild.childAt(2).is(SendAmountRow), 'row[2] should be SendAmountRow')
      assert(PageContainerContentChild.childAt(3).is(SendGasRow), 'row[3] should be SendGasRow')
      assert(PageContainerContentChild.childAt(4).is(SendHexDataRow), 'row[4] should be SendHexDataRow')
    })

    it('should not render the SendHexDataRow if props.showHexData is false', () => {
      wrapper.setProps({ showHexData: false })
      const PageContainerContentChild = wrapper.find(PageContainerContent).children()
      assert(PageContainerContentChild.childAt(0).is(Dialog), 'row[0] should be Dialog')
      assert(PageContainerContentChild.childAt(1).is(SendAssetRow), 'row[1] should be SendAssetRow')
      assert(PageContainerContentChild.childAt(2).is(SendAmountRow), 'row[2] should be SendAmountRow')
      assert(PageContainerContentChild.childAt(3).is(SendGasRow), 'row[3] should be SendGasRow')
      assert.equal(PageContainerContentChild.childAt(4).exists(), false)
    })

    it('should not render the Dialog if addressBook contains "to" address', () => {
      wrapper.setProps({
        showHexData: false,
        to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
        addressBook: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
      })
      const PageContainerContentChild = wrapper.find(PageContainerContent).children()
      assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
      assert(PageContainerContentChild.childAt(1).is(SendAmountRow), 'row[2] should be SendAmountRow')
      assert(PageContainerContentChild.childAt(2).is(SendGasRow), 'row[3] should be SendGasRow')
      assert.equal(PageContainerContentChild.childAt(3).exists(), false)
    })

    it('should not render the Dialog if ownedAccounts contains "to" address', () => {
      wrapper.setProps({
        showHexData: false,
        to: '0x80F061544cC398520615B5d3e7A3BedD70cd4510',
        addressBook: [],
        ownedAccounts: [{ address: '0x80F061544cC398520615B5d3e7A3BedD70cd4510', name: 'dinodan' }],
      })
      const PageContainerContentChild = wrapper.find(PageContainerContent).children()
      assert(PageContainerContentChild.childAt(0).is(SendAssetRow), 'row[1] should be SendAssetRow')
      assert(PageContainerContentChild.childAt(1).is(SendAmountRow), 'row[2] should be SendAmountRow')
      assert(PageContainerContentChild.childAt(2).is(SendGasRow), 'row[3] should be SendGasRow')
      assert.equal(PageContainerContentChild.childAt(3).exists(), false)
    })
  })

  it('should not render the asset dropdown if token length is 0 ', () => {
    wrapper.setProps({ tokens: [] })
    const PageContainerContentChild = wrapper.find(PageContainerContent).children()
    assert(PageContainerContentChild.childAt(1).is(SendAssetRow))
    assert(PageContainerContentChild.childAt(1).find('send-v2__asset-dropdown__single-asset'), true)
  })
})