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

import AccountListItem from '../../../../account-list-item/account-list-item.container'
import SendDropdownList from '../../../send-dropdown-list/send-dropdown-list.component'

const propsMethodSpies = {
  closeDropdown: sinon.spy(),
  openDropdown: sinon.spy(),
  onSelect: sinon.spy(),
}

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

  beforeEach(() => {
    wrapper = shallow(<FromDropdown
      accounts={['mockAccount']}
      closeDropdown={propsMethodSpies.closeDropdown}
      dropdownOpen={false}
      onSelect={propsMethodSpies.onSelect}
      openDropdown={propsMethodSpies.openDropdown}
      selectedAccount={ { address: 'mockAddress' } }
    />, { context: { t: str => str + '_t' } })
  })

  afterEach(() => {
    propsMethodSpies.closeDropdown.resetHistory()
    propsMethodSpies.openDropdown.resetHistory()
    propsMethodSpies.onSelect.resetHistory()
  })

  describe('render', () => {
    it('should render a div with a .send-v2__from-dropdown class', () => {
      assert.equal(wrapper.find('.send-v2__from-dropdown').length, 1)
    })

    it('should render an AccountListItem as the first child of the .send-v2__from-dropdown div', () => {
      assert(wrapper.find('.send-v2__from-dropdown').childAt(0).is(AccountListItem))
    })

    it('should pass the correct props to AccountListItem', () => {
      const {
        account,
        handleClick,
        icon,
      } = wrapper.find('.send-v2__from-dropdown').childAt(0).props()
      assert.deepEqual(account, { address: 'mockAddress' })
      assert.deepEqual(
        icon,
        <i className={`fa fa-caret-down fa-lg`} style={ { color: '#dedede' } }/>
      )
      assert.equal(propsMethodSpies.openDropdown.callCount, 0)
      handleClick()
      assert.equal(propsMethodSpies.openDropdown.callCount, 1)
    })

    it('should not render a SendDropdownList when dropdownOpen is false', () => {
      assert.equal(wrapper.find(SendDropdownList).length, 0)
    })

    it('should render a SendDropdownList when dropdownOpen is true', () => {
      wrapper.setProps({ dropdownOpen: true })
      assert(wrapper.find(SendDropdownList).length, 1)
    })

    it('should pass the correct props to the SendDropdownList]', () => {
      wrapper.setProps({ dropdownOpen: true })
      const {
        accounts,
        closeDropdown,
        onSelect,
        activeAddress,
      } = wrapper.find(SendDropdownList).props()
      assert.deepEqual(accounts, ['mockAccount'])
      assert.equal(activeAddress, 'mockAddress')
      assert.equal(propsMethodSpies.closeDropdown.callCount, 0)
      closeDropdown()
      assert.equal(propsMethodSpies.closeDropdown.callCount, 1)
      assert.equal(propsMethodSpies.onSelect.callCount, 0)
      onSelect()
      assert.equal(propsMethodSpies.onSelect.callCount, 1)
    })
  })
})