2018-05-14 11:25:03 +02:00
|
|
|
import assert from 'assert'
|
2020-08-18 21:18:25 +02:00
|
|
|
import React from 'react'
|
2018-05-14 11:25:03 +02:00
|
|
|
import { shallow } from 'enzyme'
|
|
|
|
import sinon from 'sinon'
|
2020-08-14 13:46:45 +02:00
|
|
|
import SendAmountRow from '../send-amount-row.component'
|
2018-05-14 11:25:03 +02:00
|
|
|
|
|
|
|
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-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { updateSendAmountError },
|
|
|
|
} = shallowRenderSendAmountRow()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(updateSendAmountError.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2018-05-14 11:25:03 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
updateSendAmountError.calledOnceWithExactly({
|
|
|
|
amount: 'someAmount',
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 7,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
|
|
|
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-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { updateGasFeeError },
|
|
|
|
} = shallowRenderSendAmountRow()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(updateGasFeeError.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2018-06-29 19:19:40 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.ok(
|
|
|
|
updateGasFeeError.calledOnceWithExactly({
|
|
|
|
balance: 'mockBalance',
|
|
|
|
conversionRate: 7,
|
|
|
|
gasTotal: 'mockGasTotal',
|
|
|
|
primaryCurrency: 'mockPrimaryCurrency',
|
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
|
|
|
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-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
wrapper,
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { updateGasFeeError },
|
|
|
|
} = shallowRenderSendAmountRow()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
wrapper.setProps({ sendToken: null })
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(updateGasFeeError.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2018-06-29 19:19:40 +02:00
|
|
|
instance.validateAmount('someAmount')
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(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 () {
|
|
|
|
it('should call setMaxModeTo', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { setMaxModeTo },
|
|
|
|
} = shallowRenderSendAmountRow()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(setMaxModeTo.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
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-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { updateSendAmount },
|
|
|
|
} = shallowRenderSendAmountRow()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(updateSendAmount.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
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()
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(wrapper.find(SendRowWrapper).length, 1)
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
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()
|
2020-11-03 00:41:28 +01:00
|
|
|
const { errorType, label, showError } = wrapper
|
|
|
|
.find(SendRowWrapper)
|
|
|
|
.props()
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(errorType, 'amount')
|
|
|
|
assert.strictEqual(label, 'amount_t:')
|
|
|
|
assert.strictEqual(showError, false)
|
2018-05-14 11:25:03 +02:00
|
|
|
})
|
|
|
|
|
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()
|
|
|
|
|
2020-11-03 00:41:28 +01: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 () {
|
2018-05-14 11:25:03 +02:00
|
|
|
const {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper,
|
|
|
|
instanceSpies: { updateGas, updateAmount, validateAmount },
|
|
|
|
} = shallowRenderSendAmountRow()
|
|
|
|
const { onChange, error, value } = wrapper
|
|
|
|
.find(SendRowWrapper)
|
|
|
|
.childAt(1)
|
|
|
|
.props()
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(error, false)
|
|
|
|
assert.strictEqual(value, 'mockAmount')
|
|
|
|
assert.strictEqual(updateGas.callCount, 0)
|
|
|
|
assert.strictEqual(updateAmount.callCount, 0)
|
|
|
|
assert.strictEqual(validateAmount.callCount, 0)
|
2020-02-05 14:15:46 +01:00
|
|
|
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function shallowRenderSendAmountRow() {
|
2020-02-05 14:15:46 +01:00
|
|
|
const setMaxModeTo = sinon.spy()
|
|
|
|
const updateGasFeeError = sinon.spy()
|
|
|
|
const updateSendAmount = sinon.spy()
|
|
|
|
const updateSendAmountError = sinon.spy()
|
2020-11-03 00:41:28 +01:00
|
|
|
const wrapper = shallow(
|
2020-02-05 14:15:46 +01:00
|
|
|
<SendAmountRow
|
|
|
|
amount="mockAmount"
|
|
|
|
balance="mockBalance"
|
|
|
|
conversionRate={7}
|
|
|
|
convertedCurrency="mockConvertedCurrency"
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
inError={false}
|
|
|
|
primaryCurrency="mockPrimaryCurrency"
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken={{ address: 'mockTokenAddress' }}
|
2020-02-05 14:15:46 +01:00
|
|
|
setMaxModeTo={setMaxModeTo}
|
|
|
|
tokenBalance="mockTokenBalance"
|
|
|
|
updateGasFeeError={updateGasFeeError}
|
|
|
|
updateSendAmount={updateSendAmount}
|
|
|
|
updateSendAmountError={updateSendAmountError}
|
2020-08-14 13:47:02 +02:00
|
|
|
updateGas={() => undefined}
|
2020-11-03 00:41:28 +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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|