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.
126 lines
3.9 KiB
126 lines
3.9 KiB
7 years ago
|
import assert from 'assert'
|
||
|
import proxyquire from 'proxyquire'
|
||
|
import sinon from 'sinon'
|
||
|
|
||
|
let mapStateToProps
|
||
|
let mapDispatchToProps
|
||
|
|
||
|
const actionSpies = {
|
||
|
setMaxModeTo: sinon.spy(),
|
||
|
updateSendAmount: sinon.spy(),
|
||
|
}
|
||
|
const duckActionSpies = {
|
||
|
updateSendErrors: sinon.spy(),
|
||
|
}
|
||
|
|
||
|
proxyquire('../send-amount-row.container.js', {
|
||
|
'react-redux': {
|
||
|
connect: (ms, md) => {
|
||
|
mapStateToProps = ms
|
||
|
mapDispatchToProps = md
|
||
|
return () => ({})
|
||
|
},
|
||
|
},
|
||
|
'../../send.selectors': {
|
||
|
getAmountConversionRate: (s) => `mockAmountConversionRate:${s}`,
|
||
|
getConversionRate: (s) => `mockConversionRate:${s}`,
|
||
7 years ago
|
getCurrentCurrency: (s) => `mockConvertedCurrency:${s}`,
|
||
7 years ago
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
||
|
getPrimaryCurrency: (s) => `mockPrimaryCurrency:${s}`,
|
||
|
getSelectedToken: (s) => `mockSelectedToken:${s}`,
|
||
|
getSendAmount: (s) => `mockAmount:${s}`,
|
||
|
getSendFromBalance: (s) => `mockBalance:${s}`,
|
||
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
||
|
},
|
||
|
'./send-amount-row.selectors': { sendAmountIsInError: (s) => `mockInError:${s}` },
|
||
7 years ago
|
'../../send.utils': {
|
||
|
getAmountErrorObject: (mockDataObject) => ({ ...mockDataObject, mockChange: true }),
|
||
|
getGasFeeErrorObject: (mockDataObject) => ({ ...mockDataObject, mockGasFeeErrorChange: true }),
|
||
|
},
|
||
7 years ago
|
'../../../../actions': actionSpies,
|
||
7 years ago
|
'../../../../ducks/send.duck': duckActionSpies,
|
||
7 years ago
|
})
|
||
|
|
||
|
describe('send-amount-row container', () => {
|
||
|
|
||
|
describe('mapStateToProps()', () => {
|
||
|
|
||
|
it('should map the correct properties to props', () => {
|
||
|
assert.deepEqual(mapStateToProps('mockState'), {
|
||
|
amount: 'mockAmount:mockState',
|
||
|
amountConversionRate: 'mockAmountConversionRate:mockState',
|
||
|
balance: 'mockBalance:mockState',
|
||
|
conversionRate: 'mockConversionRate:mockState',
|
||
|
convertedCurrency: 'mockConvertedCurrency:mockState',
|
||
|
gasTotal: 'mockGasTotal:mockState',
|
||
|
inError: 'mockInError:mockState',
|
||
|
primaryCurrency: 'mockPrimaryCurrency:mockState',
|
||
|
selectedToken: 'mockSelectedToken:mockState',
|
||
|
tokenBalance: 'mockTokenBalance:mockState',
|
||
|
})
|
||
|
})
|
||
|
|
||
|
})
|
||
|
|
||
|
describe('mapDispatchToProps()', () => {
|
||
|
let dispatchSpy
|
||
|
let mapDispatchToPropsObject
|
||
|
|
||
|
beforeEach(() => {
|
||
|
dispatchSpy = sinon.spy()
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
|
||
7 years ago
|
duckActionSpies.updateSendErrors.resetHistory()
|
||
7 years ago
|
})
|
||
|
|
||
|
describe('setMaxModeTo()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.setMaxModeTo('mockBool')
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(actionSpies.setMaxModeTo.calledOnce)
|
||
|
assert.equal(
|
||
|
actionSpies.setMaxModeTo.getCall(0).args[0],
|
||
|
'mockBool'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
describe('updateSendAmount()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.updateSendAmount('mockAmount')
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(actionSpies.updateSendAmount.calledOnce)
|
||
|
assert.equal(
|
||
|
actionSpies.updateSendAmount.getCall(0).args[0],
|
||
|
'mockAmount'
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
describe('updateGasFeeError()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.updateGasFeeError({ some: 'data' })
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(duckActionSpies.updateSendErrors.calledOnce)
|
||
|
assert.deepEqual(
|
||
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
||
|
{ some: 'data', mockGasFeeErrorChange: true }
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
describe('updateSendAmountError()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
|
mapDispatchToPropsObject.updateSendAmountError({ some: 'data' })
|
||
|
assert(dispatchSpy.calledOnce)
|
||
|
assert(duckActionSpies.updateSendErrors.calledOnce)
|
||
|
assert.deepEqual(
|
||
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
||
|
{ some: 'data', mockChange: true }
|
||
|
)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
})
|
||
|
|
||
|
})
|