2017-11-02 18:28:41 +01:00
|
|
|
const assert = require('assert')
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const { createMockStore } = require('redux-test-utils')
|
2018-09-24 18:28:04 +02:00
|
|
|
const { shallowWithStore } = require('../../lib/render-helpers')
|
2017-11-02 18:28:41 +01:00
|
|
|
const BalanceComponent = require('../../../ui/app/components/balance-component')
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
|
|
|
accounts: { abc: {} },
|
|
|
|
network: 1,
|
|
|
|
selectedAddress: 'abc',
|
2018-07-03 00:49:33 +02:00
|
|
|
},
|
2017-11-02 18:28:41 +01:00
|
|
|
}
|
2017-08-08 14:15:30 +02:00
|
|
|
|
|
|
|
describe('BalanceComponent', function () {
|
|
|
|
let balanceComponent
|
2017-11-02 18:28:41 +01:00
|
|
|
let store
|
|
|
|
let component
|
2017-08-08 14:15:30 +02:00
|
|
|
beforeEach(function () {
|
2017-11-02 18:28:41 +01:00
|
|
|
store = createMockStore(mockState)
|
|
|
|
component = shallowWithStore(h(BalanceComponent), store)
|
|
|
|
balanceComponent = component.dive()
|
2017-08-08 14:15:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows token balance and convert to fiat value based on conversion rate', function () {
|
|
|
|
const formattedBalance = '1.23 ETH'
|
|
|
|
|
2017-11-02 18:28:41 +01:00
|
|
|
const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false)
|
|
|
|
const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 2)
|
2017-08-08 14:15:30 +02:00
|
|
|
|
|
|
|
assert.equal('1.23 ETH', tokenBalance)
|
|
|
|
assert.equal(2.46, fiatDisplayNumber)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows only the token balance when conversion rate is not available', function () {
|
|
|
|
const formattedBalance = '1.23 ETH'
|
|
|
|
|
2017-11-02 18:28:41 +01:00
|
|
|
const tokenBalance = balanceComponent.instance().getTokenBalance(formattedBalance, false)
|
|
|
|
const fiatDisplayNumber = balanceComponent.instance().getFiatDisplayNumber(formattedBalance, 0)
|
2017-08-08 14:15:30 +02:00
|
|
|
|
|
|
|
assert.equal('1.23 ETH', tokenBalance)
|
|
|
|
assert.equal('N/A', fiatDisplayNumber)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|