2017-11-02 18:28:41 +01:00
|
|
|
const assert = require('assert')
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const { createMockStore } = require('redux-test-utils')
|
2017-11-26 01:37:12 +01:00
|
|
|
const { shallowWithStore } = require('../../lib/shallow-with-store')
|
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',
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|