You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.4 KiB
106 lines
2.4 KiB
6 years ago
|
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: {
|
||
|
preferences: {
|
||
|
useETHAsPrimaryCurrency: true,
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
assert.deepEqual(mapStateToProps(mockState), {
|
||
|
useETHAsPrimaryCurrency: true,
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
|
||
|
describe('mergeProps()', () => {
|
||
|
it('should return the correct props', () => {
|
||
|
const mockDispatchProps = {}
|
||
|
|
||
|
const tests = [
|
||
|
{
|
||
|
stateProps: {
|
||
|
useETHAsPrimaryCurrency: true,
|
||
|
},
|
||
|
ownProps: {
|
||
|
type: 'PRIMARY',
|
||
|
},
|
||
|
result: {
|
||
|
currency: 'ETH',
|
||
|
numberOfDecimals: 6,
|
||
|
prefix: undefined,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
stateProps: {
|
||
|
useETHAsPrimaryCurrency: false,
|
||
|
},
|
||
|
ownProps: {
|
||
|
type: 'PRIMARY',
|
||
|
},
|
||
|
result: {
|
||
|
currency: undefined,
|
||
|
numberOfDecimals: 2,
|
||
|
prefix: undefined,
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
stateProps: {
|
||
|
useETHAsPrimaryCurrency: true,
|
||
|
},
|
||
|
ownProps: {
|
||
|
type: 'SECONDARY',
|
||
|
fiatNumberOfDecimals: 4,
|
||
|
fiatPrefix: '-',
|
||
|
},
|
||
|
result: {
|
||
|
currency: undefined,
|
||
|
numberOfDecimals: 4,
|
||
|
prefix: '-',
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
stateProps: {
|
||
|
useETHAsPrimaryCurrency: false,
|
||
|
},
|
||
|
ownProps: {
|
||
|
type: 'SECONDARY',
|
||
|
fiatNumberOfDecimals: 4,
|
||
|
numberOfDecimals: 3,
|
||
|
fiatPrefix: 'a',
|
||
|
prefix: 'b',
|
||
|
},
|
||
|
result: {
|
||
|
currency: 'ETH',
|
||
|
numberOfDecimals: 3,
|
||
|
prefix: 'b',
|
||
|
},
|
||
|
},
|
||
|
]
|
||
|
|
||
|
tests.forEach(({ stateProps, ownProps, result }) => {
|
||
|
assert.deepEqual(mergeProps({ ...stateProps }, mockDispatchProps, { ...ownProps }), {
|
||
|
...result,
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
})
|