2018-08-16 04:18:01 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
let mapStateToProps, mergeProps
|
2018-08-16 04:18:01 +02:00
|
|
|
|
|
|
|
proxyquire('../currency-display.container.js', {
|
|
|
|
'react-redux': {
|
2018-10-17 01:03:29 +02:00
|
|
|
connect: (ms, md, mp) => {
|
2018-08-16 04:18:01 +02:00
|
|
|
mapStateToProps = ms
|
2018-10-17 01:03:29 +02:00
|
|
|
mergeProps = mp
|
2018-08-16 04:18:01 +02:00
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('CurrencyDisplay container', () => {
|
|
|
|
describe('mapStateToProps()', () => {
|
|
|
|
it('should return the correct props', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
|
|
|
conversionRate: 280.45,
|
|
|
|
currentCurrency: 'usd',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
assert.deepEqual(mapStateToProps(mockState), {
|
|
|
|
conversionRate: 280.45,
|
|
|
|
currentCurrency: 'usd',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('mergeProps()', () => {
|
|
|
|
it('should return the correct props', () => {
|
|
|
|
const mockStateProps = {
|
|
|
|
conversionRate: 280.45,
|
|
|
|
currentCurrency: 'usd',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 04:18:01 +02:00
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x2386f26fc10000',
|
|
|
|
numberOfDecimals: 2,
|
|
|
|
currency: 'usd',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
result: {
|
2018-10-21 13:12:40 +02:00
|
|
|
displayValue: '$2.80',
|
|
|
|
suffix: 'USD',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x2386f26fc10000',
|
2018-10-30 12:15:38 +01:00
|
|
|
currency: 'usd',
|
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
result: {
|
2018-10-21 13:12:40 +02:00
|
|
|
displayValue: '$2.80',
|
|
|
|
suffix: 'USD',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x1193461d01595930',
|
|
|
|
currency: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
numberOfDecimals: 3,
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-21 13:12:40 +02:00
|
|
|
displayValue: '1.266',
|
|
|
|
suffix: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-16 04:18:01 +02:00
|
|
|
},
|
|
|
|
},
|
2018-08-31 21:14:06 +02:00
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x1193461d01595930',
|
|
|
|
currency: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
numberOfDecimals: 3,
|
|
|
|
hideLabel: true,
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
displayValue: '1.266',
|
2018-10-21 13:12:40 +02:00
|
|
|
suffix: undefined,
|
2018-08-31 21:14:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x3b9aca00',
|
|
|
|
currency: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
denomination: 'GWEI',
|
|
|
|
hideLabel: true,
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
displayValue: '1',
|
2018-10-21 13:12:40 +02:00
|
|
|
suffix: undefined,
|
2018-08-31 21:14:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x3b9aca00',
|
|
|
|
currency: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
denomination: 'WEI',
|
|
|
|
hideLabel: true,
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
displayValue: '1000000000',
|
2018-10-21 13:12:40 +02:00
|
|
|
suffix: undefined,
|
2018-08-31 21:14:06 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
props: {
|
|
|
|
value: '0x3b9aca00',
|
|
|
|
currency: 'ETH',
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
numberOfDecimals: 100,
|
|
|
|
hideLabel: true,
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-30 12:15:38 +01:00
|
|
|
nativeCurrency: 'ETH',
|
2018-08-31 21:14:06 +02:00
|
|
|
displayValue: '1e-9',
|
2018-10-21 13:12:40 +02:00
|
|
|
suffix: undefined,
|
2018-08-31 21:14:06 +02:00
|
|
|
},
|
|
|
|
},
|
2018-08-16 04:18:01 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
tests.forEach(({ props, result }) => {
|
2018-10-17 01:03:29 +02:00
|
|
|
assert.deepEqual(mergeProps(mockStateProps, {}, { ...props }), result)
|
2018-08-16 04:18:01 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|