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.
214 lines
6.3 KiB
214 lines
6.3 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import SendRowWrapper from '../send-row-wrapper/send-row-wrapper.component';
|
||
|
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input';
|
||
|
import SendAmountRow from './send-amount-row.component';
|
||
7 years ago
|
|
||
4 years ago
|
import AmountMaxButton from './amount-max-button/amount-max-button.container';
|
||
7 years ago
|
|
||
4 years ago
|
describe('SendAmountRow Component', () => {
|
||
|
describe('validateAmount', () => {
|
||
|
it('should call updateSendAmountError with the correct params', () => {
|
||
4 years ago
|
const {
|
||
|
instance,
|
||
|
propsMethodSpies: { updateSendAmountError },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateSendAmountError.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
instance.validateAmount('someAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
updateSendAmountError.calledOnceWithExactly({
|
||
|
amount: 'someAmount',
|
||
|
balance: 'mockBalance',
|
||
|
conversionRate: 7,
|
||
|
gasTotal: 'mockGasTotal',
|
||
|
primaryCurrency: 'mockPrimaryCurrency',
|
||
|
sendToken: { address: 'mockTokenAddress' },
|
||
|
tokenBalance: 'mockTokenBalance',
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call updateGasFeeError if sendToken is truthy', () => {
|
||
4 years ago
|
const {
|
||
|
instance,
|
||
|
propsMethodSpies: { updateGasFeeError },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateGasFeeError.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
instance.validateAmount('someAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
updateGasFeeError.calledOnceWithExactly({
|
||
|
balance: 'mockBalance',
|
||
|
conversionRate: 7,
|
||
|
gasTotal: 'mockGasTotal',
|
||
|
primaryCurrency: 'mockPrimaryCurrency',
|
||
|
sendToken: { address: 'mockTokenAddress' },
|
||
|
tokenBalance: 'mockTokenBalance',
|
||
|
}),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call not updateGasFeeError if sendToken is falsey', () => {
|
||
4 years ago
|
const {
|
||
|
wrapper,
|
||
|
instance,
|
||
|
propsMethodSpies: { updateGasFeeError },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
wrapper.setProps({ sendToken: null });
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateGasFeeError.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
instance.validateAmount('someAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateGasFeeError.callCount).toStrictEqual(0);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('updateAmount', () => {
|
||
|
it('should call setMaxModeTo', () => {
|
||
4 years ago
|
const {
|
||
|
instance,
|
||
|
propsMethodSpies: { setMaxModeTo },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(setMaxModeTo.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
instance.updateAmount('someAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(setMaxModeTo.calledOnceWithExactly(false)).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call updateSendAmount', () => {
|
||
4 years ago
|
const {
|
||
|
instance,
|
||
|
propsMethodSpies: { updateSendAmount },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateSendAmount.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
instance.updateAmount('someAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
|
updateSendAmount.calledOnceWithExactly('someAmount'),
|
||
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
it('should render a SendRowWrapper component', () => {
|
||
4 years ago
|
const { wrapper } = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(wrapper.find(SendRowWrapper)).toHaveLength(1);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should pass the correct props to SendRowWrapper', () => {
|
||
4 years ago
|
const { wrapper } = shallowRenderSendAmountRow();
|
||
4 years ago
|
const { errorType, label, showError } = wrapper
|
||
|
.find(SendRowWrapper)
|
||
4 years ago
|
.props();
|
||
7 years ago
|
|
||
4 years ago
|
expect(errorType).toStrictEqual('amount');
|
||
|
expect(label).toStrictEqual('amount_t:');
|
||
|
expect(showError).toStrictEqual(false);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render an AmountMaxButton as the first child of the SendRowWrapper', () => {
|
||
4 years ago
|
const { wrapper } = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
|
wrapper.find(SendRowWrapper).childAt(0).is(AmountMaxButton),
|
||
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render a UserPreferencedTokenInput as the second child of the SendRowWrapper', () => {
|
||
4 years ago
|
const { wrapper } = shallowRenderSendAmountRow();
|
||
5 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
wrapper.find(SendRowWrapper).childAt(1).is(UserPreferencedTokenInput),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render the UserPreferencedTokenInput with the correct props', () => {
|
||
7 years ago
|
const {
|
||
4 years ago
|
wrapper,
|
||
|
instanceSpies: { updateGas, updateAmount, validateAmount },
|
||
4 years ago
|
} = shallowRenderSendAmountRow();
|
||
4 years ago
|
const { onChange, error, value } = wrapper
|
||
|
.find(SendRowWrapper)
|
||
|
.childAt(1)
|
||
4 years ago
|
.props();
|
||
5 years ago
|
|
||
4 years ago
|
expect(error).toStrictEqual(false);
|
||
|
expect(value).toStrictEqual('mockAmount');
|
||
|
expect(updateGas.callCount).toStrictEqual(0);
|
||
|
expect(updateAmount.callCount).toStrictEqual(0);
|
||
|
expect(validateAmount.callCount).toStrictEqual(0);
|
||
5 years ago
|
|
||
4 years ago
|
onChange('mockNewAmount');
|
||
5 years ago
|
|
||
4 years ago
|
expect(updateGas.calledOnceWithExactly('mockNewAmount')).toStrictEqual(
|
||
|
true,
|
||
|
);
|
||
|
expect(updateAmount.calledOnceWithExactly('mockNewAmount')).toStrictEqual(
|
||
|
true,
|
||
|
);
|
||
|
expect(
|
||
|
validateAmount.calledOnceWithExactly('mockNewAmount'),
|
||
|
).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
function shallowRenderSendAmountRow() {
|
||
4 years ago
|
const setMaxModeTo = sinon.spy();
|
||
|
const updateGasFeeError = sinon.spy();
|
||
|
const updateSendAmount = sinon.spy();
|
||
|
const updateSendAmountError = sinon.spy();
|
||
4 years ago
|
const wrapper = shallow(
|
||
5 years ago
|
<SendAmountRow
|
||
|
amount="mockAmount"
|
||
|
balance="mockBalance"
|
||
|
conversionRate={7}
|
||
|
convertedCurrency="mockConvertedCurrency"
|
||
|
gasTotal="mockGasTotal"
|
||
|
inError={false}
|
||
|
primaryCurrency="mockPrimaryCurrency"
|
||
4 years ago
|
sendToken={{ address: 'mockTokenAddress' }}
|
||
5 years ago
|
setMaxModeTo={setMaxModeTo}
|
||
|
tokenBalance="mockTokenBalance"
|
||
|
updateGasFeeError={updateGasFeeError}
|
||
|
updateSendAmount={updateSendAmount}
|
||
|
updateSendAmountError={updateSendAmountError}
|
||
4 years ago
|
updateGas={() => undefined}
|
||
4 years ago
|
/>,
|
||
|
{ context: { t: (str) => `${str}_t` } },
|
||
4 years ago
|
);
|
||
|
const instance = wrapper.instance();
|
||
|
const updateAmount = sinon.spy(instance, 'updateAmount');
|
||
|
const updateGas = sinon.spy(instance, 'updateGas');
|
||
|
const validateAmount = sinon.spy(instance, 'validateAmount');
|
||
5 years ago
|
|
||
|
return {
|
||
|
instance,
|
||
|
wrapper,
|
||
|
propsMethodSpies: {
|
||
|
setMaxModeTo,
|
||
|
updateGasFeeError,
|
||
|
updateSendAmount,
|
||
|
updateSendAmountError,
|
||
|
},
|
||
|
instanceSpies: {
|
||
|
updateAmount,
|
||
|
updateGas,
|
||
|
validateAmount,
|
||
|
},
|
||
4 years ago
|
};
|
||
5 years ago
|
}
|