2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SendRowWrapper from '../send-row-wrapper/send-row-wrapper.component';
|
|
|
|
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input';
|
2022-03-16 23:15:03 +01:00
|
|
|
import { ASSET_TYPES } from '../../../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SendAmountRow from './send-amount-row.component';
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
import AmountMaxButton from './amount-max-button/amount-max-button';
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('SendAmountRow Component', () => {
|
|
|
|
describe('updateAmount', () => {
|
|
|
|
it('should call updateSendAmount', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
instance,
|
|
|
|
propsMethodSpies: { updateSendAmount },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = shallowRenderSendAmountRow();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(updateSendAmount.callCount).toStrictEqual(0);
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
instance.handleChange('someAmount');
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
updateSendAmount.calledOnceWithExactly('someAmount'),
|
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a SendRowWrapper component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.find(SendRowWrapper)).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct props to SendRowWrapper', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow();
|
2020-11-03 00:41:28 +01:00
|
|
|
const { errorType, label, showError } = wrapper
|
|
|
|
.find(SendRowWrapper)
|
2021-02-04 19:15:23 +01:00
|
|
|
.props();
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(errorType).toStrictEqual('amount');
|
|
|
|
expect(label).toStrictEqual('amount_t:');
|
|
|
|
expect(showError).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render an AmountMaxButton as the first child of the SendRowWrapper', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
wrapper.find(SendRowWrapper).childAt(0).is(AmountMaxButton),
|
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render a UserPreferencedTokenInput as the second child of the SendRowWrapper', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find(SendRowWrapper).childAt(1).is(UserPreferencedTokenInput),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render the UserPreferencedTokenInput with the correct props', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
const { wrapper } = shallowRenderSendAmountRow();
|
2020-11-03 00:41:28 +01:00
|
|
|
const { onChange, error, value } = wrapper
|
|
|
|
.find(SendRowWrapper)
|
|
|
|
.childAt(1)
|
2021-02-04 19:15:23 +01:00
|
|
|
.props();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(error).toStrictEqual(false);
|
|
|
|
expect(value).toStrictEqual('mockAmount');
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
onChange('mockNewAmount');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-02-05 14:15:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function shallowRenderSendAmountRow() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const updateSendAmount = sinon.spy();
|
2020-11-03 00:41:28 +01:00
|
|
|
const wrapper = shallow(
|
2020-02-05 14:15:46 +01:00
|
|
|
<SendAmountRow
|
|
|
|
amount="mockAmount"
|
|
|
|
inError={false}
|
2021-06-23 23:35:25 +02:00
|
|
|
asset={{
|
|
|
|
type: ASSET_TYPES.TOKEN,
|
|
|
|
balance: 'mockTokenBalance',
|
|
|
|
details: { address: 'mockTokenAddress' },
|
|
|
|
}}
|
2020-02-05 14:15:46 +01:00
|
|
|
updateSendAmount={updateSendAmount}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{ context: { t: (str) => `${str}_t` } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const instance = wrapper.instance();
|
2020-02-05 14:15:46 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
instance,
|
|
|
|
wrapper,
|
|
|
|
propsMethodSpies: {
|
|
|
|
updateSendAmount,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-05 14:15:46 +01:00
|
|
|
}
|