aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/currency-display/tests/currency-display.container.test.js
blob: b9f98c5433de1d5be719e85cb002490576fa8b92 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import assert from 'assert'
import proxyquire from 'proxyquire'

let mapStateToProps, mergeProps

proxyquire('../currency-display.container.js', {
  'react-redux': {
    connect: (ms, md, mp) => {
      mapStateToProps = ms
      mergeProps = mp
      return () => ({})
    },
  },
})

describe('CurrencyDisplay container', () => {
  describe('mapStateToProps()', () => {
    it('should return the correct props', () => {
      const mockState = {
        metamask: {
          conversionRate: 280.45,
          currentCurrency: 'usd',
        },
      }

      assert.deepEqual(mapStateToProps(mockState), {
        conversionRate: 280.45,
        currentCurrency: 'usd',
      })
    })
  })

  describe('mergeProps()', () => {
    it('should return the correct props', () => {
      const mockStateProps = {
        conversionRate: 280.45,
        currentCurrency: 'usd',
      }

      const tests = [
        {
          props: {
            value: '0x2386f26fc10000',
            numberOfDecimals: 2,
            currency: 'usd',
          },
          result: {
            displayValue: '$2.80 USD',
          },
        },
        {
          props: {
            value: '0x2386f26fc10000',
          },
          result: {
            displayValue: '$2.80 USD',
          },
        },
        {
          props: {
            value: '0x1193461d01595930',
            currency: 'ETH',
            numberOfDecimals: 3,
          },
          result: {
            displayValue: '1.266 ETH',
          },
        },
        {
          props: {
            value: '0x1193461d01595930',
            currency: 'ETH',
            numberOfDecimals: 3,
            hideLabel: true,
          },
          result: {
            displayValue: '1.266',
          },
        },
        {
          props: {
            value: '0x3b9aca00',
            currency: 'ETH',
            denomination: 'GWEI',
            hideLabel: true,
          },
          result: {
            displayValue: '1',
          },
        },
        {
          props: {
            value: '0x3b9aca00',
            currency: 'ETH',
            denomination: 'WEI',
            hideLabel: true,
          },
          result: {
            displayValue: '1000000000',
          },
        },
        {
          props: {
            value: '0x3b9aca00',
            currency: 'ETH',
            numberOfDecimals: 100,
            hideLabel: true,
          },
          result: {
            displayValue: '1e-9',
          },
        },
      ]

      tests.forEach(({ props, result }) => {
        assert.deepEqual(mergeProps(mockStateProps, {}, { ...props }), result)
      })
    })
  })
})