2018-10-17 01:03:29 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
|
|
|
|
let mapStateToProps, mergeProps
|
|
|
|
|
|
|
|
proxyquire('../user-preferenced-currency-display.container.js', {
|
|
|
|
'react-redux': {
|
|
|
|
connect: (ms, md, mp) => {
|
|
|
|
mapStateToProps = ms
|
|
|
|
mergeProps = mp
|
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('UserPreferencedCurrencyDisplay container', () => {
|
|
|
|
describe('mapStateToProps()', () => {
|
|
|
|
it('should return the correct props', () => {
|
|
|
|
const mockState = {
|
|
|
|
metamask: {
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
preferences: {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(mapStateToProps(mockState), {
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
2018-10-17 01:03:29 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('mergeProps()', () => {
|
|
|
|
it('should return the correct props', () => {
|
|
|
|
const mockDispatchProps = {}
|
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
stateProps: {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
|
|
|
ownProps: {
|
|
|
|
type: 'PRIMARY',
|
|
|
|
},
|
|
|
|
result: {
|
|
|
|
currency: 'ETH',
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
numberOfDecimals: 6,
|
|
|
|
prefix: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stateProps: {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: false,
|
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
|
|
|
ownProps: {
|
|
|
|
type: 'PRIMARY',
|
|
|
|
},
|
|
|
|
result: {
|
|
|
|
currency: undefined,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
numberOfDecimals: 2,
|
|
|
|
prefix: undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stateProps: {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
|
|
|
ownProps: {
|
|
|
|
type: 'SECONDARY',
|
|
|
|
fiatNumberOfDecimals: 4,
|
|
|
|
fiatPrefix: '-',
|
|
|
|
},
|
|
|
|
result: {
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
currency: undefined,
|
|
|
|
numberOfDecimals: 4,
|
|
|
|
prefix: '-',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stateProps: {
|
2018-10-26 10:26:43 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: false,
|
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
|
|
|
ownProps: {
|
|
|
|
type: 'SECONDARY',
|
|
|
|
fiatNumberOfDecimals: 4,
|
|
|
|
numberOfDecimals: 3,
|
|
|
|
fiatPrefix: 'a',
|
|
|
|
prefix: 'b',
|
|
|
|
},
|
|
|
|
result: {
|
|
|
|
currency: 'ETH',
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: 'ETH',
|
2018-10-17 01:03:29 +02:00
|
|
|
numberOfDecimals: 3,
|
|
|
|
prefix: 'b',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
tests.forEach(({ stateProps, ownProps, result }) => {
|
|
|
|
assert.deepEqual(mergeProps({ ...stateProps }, mockDispatchProps, { ...ownProps }), {
|
|
|
|
...result,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|