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.
201 lines
6.6 KiB
201 lines
6.6 KiB
7 years ago
|
import assert from 'assert'
|
||
|
import proxyquire from 'proxyquire'
|
||
|
import sinon from 'sinon'
|
||
|
|
||
|
let mapStateToProps
|
||
|
let mapDispatchToProps
|
||
6 years ago
|
let mergeProps
|
||
7 years ago
|
|
||
|
const actionSpies = {
|
||
|
showModal: sinon.spy(),
|
||
6 years ago
|
setGasPrice: sinon.spy(),
|
||
6 years ago
|
setGasTotal: sinon.spy(),
|
||
|
setGasLimit: sinon.spy(),
|
||
6 years ago
|
}
|
||
|
|
||
|
const sendDuckSpies = {
|
||
|
showGasButtonGroup: sinon.spy(),
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
const gasDuckSpies = {
|
||
|
resetCustomData: sinon.spy(),
|
||
6 years ago
|
setCustomGasPrice: sinon.spy(),
|
||
|
setCustomGasLimit: sinon.spy(),
|
||
6 years ago
|
}
|
||
|
|
||
7 years ago
|
proxyquire('../send-gas-row.container.js', {
|
||
|
'react-redux': {
|
||
6 years ago
|
connect: (ms, md, mp) => {
|
||
7 years ago
|
mapStateToProps = ms
|
||
|
mapDispatchToProps = md
|
||
6 years ago
|
mergeProps = mp
|
||
7 years ago
|
return () => ({})
|
||
|
},
|
||
|
},
|
||
6 years ago
|
'../../../../selectors/selectors': {
|
||
6 years ago
|
getCurrentEthBalance: (s) => `mockCurrentEthBalance:${s}`,
|
||
|
getAdvancedInlineGasShown: (s) => `mockAdvancedInlineGasShown:${s}`,
|
||
6 years ago
|
getSelectedToken: () => false,
|
||
6 years ago
|
},
|
||
7 years ago
|
'../../send.selectors.js': {
|
||
|
getConversionRate: (s) => `mockConversionRate:${s}`,
|
||
7 years ago
|
getCurrentCurrency: (s) => `mockConvertedCurrency:${s}`,
|
||
7 years ago
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
||
6 years ago
|
getGasPrice: (s) => `mockGasPrice:${s}`,
|
||
6 years ago
|
getGasLimit: (s) => `mockGasLimit:${s}`,
|
||
|
getSendAmount: (s) => `mockSendAmount:${s}`,
|
||
|
},
|
||
|
'../../send.utils.js': {
|
||
|
isBalanceSufficient: ({
|
||
|
amount,
|
||
|
gasTotal,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
}) => `${amount}:${gasTotal}:${balance}:${conversionRate}`,
|
||
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
||
7 years ago
|
},
|
||
7 years ago
|
'./send-gas-row.selectors.js': {
|
||
|
getGasLoadingError: (s) => `mockGasLoadingError:${s}`,
|
||
|
gasFeeIsInError: (s) => `mockGasFeeError:${s}`,
|
||
6 years ago
|
getGasButtonGroupShown: (s) => `mockGetGasButtonGroupShown:${s}`,
|
||
7 years ago
|
},
|
||
6 years ago
|
'../../../../store/actions': actionSpies,
|
||
|
'../../../../selectors/custom-gas': {
|
||
6 years ago
|
getBasicGasEstimateLoadingStatus: (s) => `mockBasicGasEstimateLoadingStatus:${s}`,
|
||
6 years ago
|
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => `mockGasButtonInfo:${s}`,
|
||
6 years ago
|
getDefaultActiveButtonIndex: (gasButtonInfo, gasPrice) => gasButtonInfo.length + gasPrice.length,
|
||
|
},
|
||
6 years ago
|
'../../../../ducks/send/send.duck': sendDuckSpies,
|
||
|
'../../../../ducks/gas/gas.duck': gasDuckSpies,
|
||
7 years ago
|
})
|
||
|
|
||
|
describe('send-gas-row container', () => {
|
||
|
|
||
|
describe('mapStateToProps()', () => {
|
||
|
|
||
|
it('should map the correct properties to props', () => {
|
||
|
assert.deepEqual(mapStateToProps('mockState'), {
|
||
|
conversionRate: 'mockConversionRate:mockState',
|
||
|
convertedCurrency: 'mockConvertedCurrency:mockState',
|
||
|
gasTotal: 'mockGasTotal:mockState',
|
||
7 years ago
|
gasFeeError: 'mockGasFeeError:mockState',
|
||
7 years ago
|
gasLoadingError: 'mockGasLoadingError:mockState',
|
||
6 years ago
|
gasPriceButtonGroupProps: {
|
||
|
buttonDataLoading: `mockBasicGasEstimateLoadingStatus:mockState`,
|
||
|
defaultActiveButtonIndex: 1,
|
||
|
newActiveButtonIndex: 49,
|
||
|
gasButtonInfo: `mockGasButtonInfo:mockState`,
|
||
|
},
|
||
|
gasButtonGroupShown: `mockGetGasButtonGroupShown:mockState`,
|
||
6 years ago
|
advancedInlineGasShown: 'mockAdvancedInlineGasShown:mockState',
|
||
6 years ago
|
gasLimit: 'mockGasLimit:mockState',
|
||
|
gasPrice: 'mockGasPrice:mockState',
|
||
6 years ago
|
insufficientBalance: false,
|
||
7 years ago
|
})
|
||
|
})
|
||
|
|
||
|
})
|
||
|
|
||
|
describe('mapDispatchToProps()', () => {
|
||
|
let dispatchSpy
|
||
|
let mapDispatchToPropsObject
|
||
|
|
||
|
beforeEach(() => {
|
||
|
dispatchSpy = sinon.spy()
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
|
||
6 years ago
|
actionSpies.setGasTotal.resetHistory()
|
||
7 years ago
|
})
|
||
|
|
||
|
describe('showCustomizeGasModal()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.showCustomizeGasModal()
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert.deepEqual(
|
||
|
actionSpies.showModal.getCall(0).args[0],
|
||
6 years ago
|
{ name: 'CUSTOMIZE_GAS', hideBasic: true }
|
||
7 years ago
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
describe('setGasPrice()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
6 years ago
|
mapDispatchToPropsObject.setGasPrice('mockNewPrice', 'mockLimit')
|
||
6 years ago
|
assert(dispatchSpy.calledThrice)
|
||
6 years ago
|
assert(actionSpies.setGasPrice.calledOnce)
|
||
6 years ago
|
assert.equal(actionSpies.setGasPrice.getCall(0).args[0], 'mockNewPrice')
|
||
|
assert.equal(gasDuckSpies.setCustomGasPrice.getCall(0).args[0], 'mockNewPrice')
|
||
6 years ago
|
assert(actionSpies.setGasTotal.calledOnce)
|
||
6 years ago
|
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockLimitmockNewPrice')
|
||
6 years ago
|
})
|
||
|
})
|
||
|
|
||
|
describe('setGasLimit()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.setGasLimit('mockNewLimit', 'mockPrice')
|
||
6 years ago
|
assert(dispatchSpy.calledThrice)
|
||
6 years ago
|
assert(actionSpies.setGasLimit.calledOnce)
|
||
6 years ago
|
assert.equal(actionSpies.setGasLimit.getCall(0).args[0], 'mockNewLimit')
|
||
|
assert.equal(gasDuckSpies.setCustomGasLimit.getCall(0).args[0], 'mockNewLimit')
|
||
6 years ago
|
assert(actionSpies.setGasTotal.calledOnce)
|
||
6 years ago
|
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockNewLimitmockPrice')
|
||
6 years ago
|
})
|
||
|
})
|
||
|
|
||
|
describe('showGasButtonGroup()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.showGasButtonGroup()
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(sendDuckSpies.showGasButtonGroup.calledOnce)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
describe('resetCustomData()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.resetCustomData()
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(gasDuckSpies.resetCustomData.calledOnce)
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
})
|
||
|
|
||
|
describe('mergeProps', () => {
|
||
|
let stateProps
|
||
|
let dispatchProps
|
||
|
let ownProps
|
||
|
|
||
|
beforeEach(() => {
|
||
|
stateProps = {
|
||
|
gasPriceButtonGroupProps: {
|
||
|
someGasPriceButtonGroupProp: 'foo',
|
||
|
anotherGasPriceButtonGroupProp: 'bar',
|
||
|
},
|
||
|
someOtherStateProp: 'baz',
|
||
|
}
|
||
|
dispatchProps = {
|
||
|
setGasPrice: sinon.spy(),
|
||
|
someOtherDispatchProp: sinon.spy(),
|
||
|
}
|
||
|
ownProps = { someOwnProp: 123 }
|
||
|
})
|
||
|
|
||
|
it('should return the expected props when isConfirm is true', () => {
|
||
|
const result = mergeProps(stateProps, dispatchProps, ownProps)
|
||
|
|
||
|
assert.equal(result.someOtherStateProp, 'baz')
|
||
|
assert.equal(result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp, 'foo')
|
||
|
assert.equal(result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp, 'bar')
|
||
|
assert.equal(result.someOwnProp, 123)
|
||
|
|
||
|
assert.equal(dispatchProps.setGasPrice.callCount, 0)
|
||
|
result.gasPriceButtonGroupProps.handleGasPriceSelection()
|
||
|
assert.equal(dispatchProps.setGasPrice.callCount, 1)
|
||
|
|
||
|
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 0)
|
||
|
result.someOtherDispatchProp()
|
||
|
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 1)
|
||
|
})
|
||
7 years ago
|
})
|
||
|
|
||
|
})
|