2018-05-14 11:25:03 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import SendAmountRow from '../send-amount-row.component.js'
|
|
|
|
|
|
|
|
import SendRowWrapper from '../../send-row-wrapper/send-row-wrapper.component'
|
|
|
|
import AmountMaxButton from '../amount-max-button/amount-max-button.container'
|
2019-04-17 21:15:13 +02:00
|
|
|
import UserPreferencedTokenInput from '../../../../../components/app/user-preferenced-token-input'
|
2018-05-14 11:25:03 +02:00
|
|
|
|
|
|
|
describe('SendAmountRow Component', function () {
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('validateAmount', function () {
|
|
|
|
it('should call updateSendAmountError with the correct params', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { instance, propsMethodSpies: { updateSendAmountError } } = shallowRenderSendAmountRow()
|
|
|
|
|
|
|
|
assert.equal(updateSendAmountError.callCount, 0)
|
|
|
|
|
2018-05-14 11:25:03 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.ok(updateSendAmountError.calledOnceWithExactly({
|
|
|
|
amount: 'someAmount',
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 7,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
2020-02-05 14:15:46 +01:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
|
|
|
}))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call updateGasFeeError if sendToken is truthy', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { instance, propsMethodSpies: { updateGasFeeError } } = shallowRenderSendAmountRow()
|
|
|
|
|
|
|
|
assert.equal(updateGasFeeError.callCount, 0)
|
|
|
|
|
2018-06-29 19:19:40 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.ok(updateGasFeeError.calledOnceWithExactly({
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 7,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
2020-02-05 14:15:46 +01:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
|
|
|
}))
|
2018-06-29 19:19:40 +02:00
|
|
|
})
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
it('should call not updateGasFeeError if sendToken is falsey', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper, instance, propsMethodSpies: { updateGasFeeError } } = shallowRenderSendAmountRow()
|
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
wrapper.setProps({ sendToken: null })
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.equal(updateGasFeeError.callCount, 0)
|
|
|
|
|
2018-06-29 19:19:40 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.equal(updateGasFeeError.callCount, 0)
|
2018-06-29 19:19:40 +02:00
|
|
|
})
|
|
|
|
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateAmount', function () {
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call setMaxModeTo', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { instance, propsMethodSpies: { setMaxModeTo } } = shallowRenderSendAmountRow()
|
|
|
|
|
|
|
|
assert.equal(setMaxModeTo.callCount, 0)
|
|
|
|
|
2018-05-28 18:41:23 +02:00
|
|
|
instance.updateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.ok(setMaxModeTo.calledOnceWithExactly(false))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call updateSendAmount', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { instance, propsMethodSpies: { updateSendAmount } } = shallowRenderSendAmountRow()
|
|
|
|
|
|
|
|
assert.equal(updateSendAmount.callCount, 0)
|
|
|
|
|
2018-05-28 18:41:23 +02:00
|
|
|
instance.updateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.ok(updateSendAmount.calledOnceWithExactly('someAmount'))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render a SendRowWrapper component', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow()
|
|
|
|
|
2018-05-14 11:25:03 +02:00
|
|
|
assert.equal(wrapper.find(SendRowWrapper).length, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should pass the correct props to SendRowWrapper', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow()
|
2018-05-14 11:25:03 +02:00
|
|
|
const {
|
|
|
|
errorType,
|
|
|
|
label,
|
|
|
|
showError,
|
|
|
|
} = wrapper.find(SendRowWrapper).props()
|
|
|
|
|
|
|
|
assert.equal(errorType, 'amount')
|
|
|
|
assert.equal(label, 'amount_t:')
|
|
|
|
assert.equal(showError, false)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render an AmountMaxButton as the first child of the SendRowWrapper', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow()
|
|
|
|
|
2018-05-14 11:25:03 +02:00
|
|
|
assert(wrapper.find(SendRowWrapper).childAt(0).is(AmountMaxButton))
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render a UserPreferencedTokenInput as the second child of the SendRowWrapper', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow()
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
assert(wrapper.find(SendRowWrapper).childAt(1).is(UserPreferencedTokenInput))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render the UserPreferencedTokenInput with the correct props', function () {
|
2020-02-05 14:15:46 +01:00
|
|
|
const { wrapper, instanceSpies: { updateGas, updateAmount, validateAmount } } = shallowRenderSendAmountRow()
|
2018-05-14 11:25:03 +02:00
|
|
|
const {
|
2018-05-28 18:41:23 +02:00
|
|
|
onChange,
|
2018-10-17 01:03:29 +02:00
|
|
|
error,
|
2018-05-14 11:25:03 +02:00
|
|
|
value,
|
|
|
|
} = wrapper.find(SendRowWrapper).childAt(1).props()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
assert.equal(error, false)
|
2018-05-14 11:25:03 +02:00
|
|
|
assert.equal(value, 'mockAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
assert.equal(updateGas.callCount, 0)
|
|
|
|
assert.equal(updateAmount.callCount, 0)
|
|
|
|
assert.equal(validateAmount.callCount, 0)
|
|
|
|
|
2020-01-10 15:23:54 +01:00
|
|
|
onChange('mockNewAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
assert.ok(updateGas.calledOnceWithExactly('mockNewAmount'))
|
|
|
|
assert.ok(updateAmount.calledOnceWithExactly('mockNewAmount'))
|
|
|
|
assert.ok(validateAmount.calledOnceWithExactly('mockNewAmount'))
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
function shallowRenderSendAmountRow () {
|
|
|
|
const setMaxModeTo = sinon.spy()
|
|
|
|
const updateGasFeeError = sinon.spy()
|
|
|
|
const updateSendAmount = sinon.spy()
|
|
|
|
const updateSendAmountError = sinon.spy()
|
|
|
|
const wrapper = shallow((
|
|
|
|
<SendAmountRow
|
|
|
|
amount="mockAmount"
|
|
|
|
balance="mockBalance"
|
|
|
|
conversionRate={7}
|
|
|
|
convertedCurrency="mockConvertedCurrency"
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
inError={false}
|
|
|
|
primaryCurrency="mockPrimaryCurrency"
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken={ { address: 'mockTokenAddress' } }
|
2020-02-05 14:15:46 +01:00
|
|
|
setMaxModeTo={setMaxModeTo}
|
|
|
|
tokenBalance="mockTokenBalance"
|
|
|
|
updateGasFeeError={updateGasFeeError}
|
|
|
|
updateSendAmount={updateSendAmount}
|
|
|
|
updateSendAmountError={updateSendAmountError}
|
|
|
|
updateGas={() => {}}
|
|
|
|
/>
|
2020-02-15 21:34:12 +01:00
|
|
|
), { context: { t: (str) => str + '_t' } })
|
2020-02-05 14:15:46 +01:00
|
|
|
const instance = wrapper.instance()
|
|
|
|
const updateAmount = sinon.spy(instance, 'updateAmount')
|
|
|
|
const updateGas = sinon.spy(instance, 'updateGas')
|
|
|
|
const validateAmount = sinon.spy(instance, 'validateAmount')
|
|
|
|
|
|
|
|
return {
|
|
|
|
instance,
|
|
|
|
wrapper,
|
|
|
|
propsMethodSpies: {
|
|
|
|
setMaxModeTo,
|
|
|
|
updateGasFeeError,
|
|
|
|
updateSendAmount,
|
|
|
|
updateSendAmountError,
|
|
|
|
},
|
|
|
|
instanceSpies: {
|
|
|
|
updateAmount,
|
|
|
|
updateGas,
|
|
|
|
validateAmount,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|