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.
256 lines
8.2 KiB
256 lines
8.2 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import { CONFIRM_TRANSACTION_ROUTE } from '../../../helpers/constants/routes';
|
||
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer';
|
||
|
import SendFooter from './send-footer.component';
|
||
7 years ago
|
|
||
4 years ago
|
describe('SendFooter Component', () => {
|
||
4 years ago
|
let wrapper;
|
||
7 years ago
|
|
||
5 years ago
|
const propsMethodSpies = {
|
||
|
addToAddressBookIfNew: sinon.spy(),
|
||
|
clearSend: sinon.spy(),
|
||
|
sign: sinon.spy(),
|
||
|
update: sinon.spy(),
|
||
4 years ago
|
mostRecentOverviewPage: '/',
|
||
4 years ago
|
};
|
||
5 years ago
|
const historySpies = {
|
||
|
push: sinon.spy(),
|
||
4 years ago
|
};
|
||
|
const MOCK_EVENT = { preventDefault: () => undefined };
|
||
5 years ago
|
|
||
4 years ago
|
beforeAll(() => {
|
||
4 years ago
|
sinon.spy(SendFooter.prototype, 'onCancel');
|
||
|
sinon.spy(SendFooter.prototype, 'onSubmit');
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<SendFooter
|
||
|
addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
|
||
|
amount="mockAmount"
|
||
|
clearSend={propsMethodSpies.clearSend}
|
||
|
disabled
|
||
|
editingTransactionId="mockEditingTransactionId"
|
||
|
errors={{}}
|
||
4 years ago
|
from={{ address: 'mockAddress', balance: 'mockBalance' }}
|
||
5 years ago
|
gasLimit="mockGasLimit"
|
||
|
gasPrice="mockGasPrice"
|
||
|
gasTotal="mockGasTotal"
|
||
|
history={historySpies}
|
||
|
inError={false}
|
||
5 years ago
|
sendToken={{ mockProp: 'mockSendTokenProp' }}
|
||
5 years ago
|
sign={propsMethodSpies.sign}
|
||
|
to="mockTo"
|
||
|
toAccounts={['mockAccount']}
|
||
|
tokenBalance="mockTokenBalance"
|
||
5 years ago
|
unapprovedTxs={{}}
|
||
5 years ago
|
update={propsMethodSpies.update}
|
||
|
sendErrors={{}}
|
||
5 years ago
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
||
4 years ago
|
noGasPrice={false}
|
||
4 years ago
|
/>,
|
||
|
{ context: { t: (str) => str, metricsEvent: () => ({}) } },
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
propsMethodSpies.clearSend.resetHistory();
|
||
|
propsMethodSpies.addToAddressBookIfNew.resetHistory();
|
||
|
propsMethodSpies.clearSend.resetHistory();
|
||
|
propsMethodSpies.sign.resetHistory();
|
||
|
propsMethodSpies.update.resetHistory();
|
||
|
historySpies.push.resetHistory();
|
||
|
SendFooter.prototype.onCancel.resetHistory();
|
||
|
SendFooter.prototype.onSubmit.resetHistory();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterAll(() => {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('onCancel', () => {
|
||
|
it('should call clearSend', () => {
|
||
|
expect(propsMethodSpies.clearSend.callCount).toStrictEqual(0);
|
||
4 years ago
|
wrapper.instance().onCancel();
|
||
4 years ago
|
expect(propsMethodSpies.clearSend.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call history.push', () => {
|
||
|
expect(historySpies.push.callCount).toStrictEqual(0);
|
||
4 years ago
|
wrapper.instance().onCancel();
|
||
4 years ago
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
||
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(
|
||
4 years ago
|
'mostRecentOverviewPage',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('formShouldBeDisabled()', () => {
|
||
7 years ago
|
const config = {
|
||
|
'should return true if inError is truthy': {
|
||
|
inError: true,
|
||
|
expectedResult: true,
|
||
5 years ago
|
gasIsLoading: false,
|
||
7 years ago
|
},
|
||
|
'should return true if gasTotal is falsy': {
|
||
|
inError: false,
|
||
5 years ago
|
gasTotal: '',
|
||
7 years ago
|
expectedResult: true,
|
||
5 years ago
|
gasIsLoading: false,
|
||
7 years ago
|
},
|
||
7 years ago
|
'should return true if to is truthy': {
|
||
|
to: '0xsomevalidAddress',
|
||
|
inError: false,
|
||
5 years ago
|
gasTotal: '',
|
||
7 years ago
|
expectedResult: true,
|
||
5 years ago
|
gasIsLoading: false,
|
||
7 years ago
|
},
|
||
5 years ago
|
'should return true if sendToken is truthy and tokenBalance is falsy': {
|
||
|
sendToken: { mockProp: 'mockSendTokenProp' },
|
||
5 years ago
|
tokenBalance: '',
|
||
7 years ago
|
expectedResult: true,
|
||
5 years ago
|
gasIsLoading: false,
|
||
|
},
|
||
|
'should return true if gasIsLoading is truthy but all other params are falsy': {
|
||
|
inError: false,
|
||
5 years ago
|
gasTotal: '',
|
||
5 years ago
|
sendToken: null,
|
||
5 years ago
|
tokenBalance: '',
|
||
5 years ago
|
expectedResult: true,
|
||
|
gasIsLoading: true,
|
||
7 years ago
|
},
|
||
|
'should return false if inError is false and all other params are truthy': {
|
||
|
inError: false,
|
||
|
gasTotal: '0x123',
|
||
5 years ago
|
sendToken: { mockProp: 'mockSendTokenProp' },
|
||
5 years ago
|
tokenBalance: '123',
|
||
7 years ago
|
expectedResult: false,
|
||
5 years ago
|
gasIsLoading: false,
|
||
7 years ago
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
Object.entries(config).forEach(([description, obj]) => {
|
||
4 years ago
|
it(`${description}`, () => {
|
||
4 years ago
|
wrapper.setProps(obj);
|
||
4 years ago
|
expect(wrapper.instance().formShouldBeDisabled()).toStrictEqual(
|
||
4 years ago
|
obj.expectedResult,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('onSubmit', () => {
|
||
|
it('should call addToAddressBookIfNew with the correct params', () => {
|
||
4 years ago
|
wrapper.instance().onSubmit(MOCK_EVENT);
|
||
4 years ago
|
expect(propsMethodSpies.addToAddressBookIfNew.calledOnce).toStrictEqual(
|
||
|
true,
|
||
4 years ago
|
);
|
||
4 years ago
|
expect(
|
||
|
propsMethodSpies.addToAddressBookIfNew.getCall(0).args,
|
||
|
).toStrictEqual(['mockTo', ['mockAccount']]);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call props.update if editingTransactionId is truthy', async () => {
|
||
4 years ago
|
await wrapper.instance().onSubmit(MOCK_EVENT);
|
||
4 years ago
|
expect(propsMethodSpies.update.calledOnce).toStrictEqual(true);
|
||
|
expect(propsMethodSpies.update.getCall(0).args[0]).toStrictEqual({
|
||
4 years ago
|
data: undefined,
|
||
|
amount: 'mockAmount',
|
||
|
editingTransactionId: 'mockEditingTransactionId',
|
||
|
from: 'mockAddress',
|
||
|
gas: 'mockGasLimit',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
sendToken: { mockProp: 'mockSendTokenProp' },
|
||
|
to: 'mockTo',
|
||
|
unapprovedTxs: {},
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not call props.sign if editingTransactionId is truthy', () => {
|
||
|
expect(propsMethodSpies.sign.callCount).toStrictEqual(0);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call props.sign if editingTransactionId is falsy', async () => {
|
||
4 years ago
|
wrapper.setProps({ editingTransactionId: null });
|
||
|
await wrapper.instance().onSubmit(MOCK_EVENT);
|
||
4 years ago
|
expect(propsMethodSpies.sign.calledOnce).toStrictEqual(true);
|
||
|
expect(propsMethodSpies.sign.getCall(0).args[0]).toStrictEqual({
|
||
4 years ago
|
data: undefined,
|
||
|
amount: 'mockAmount',
|
||
|
from: 'mockAddress',
|
||
|
gas: 'mockGasLimit',
|
||
|
gasPrice: 'mockGasPrice',
|
||
|
sendToken: { mockProp: 'mockSendTokenProp' },
|
||
|
to: 'mockTo',
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should not call props.update if editingTransactionId is falsy', () => {
|
||
|
expect(propsMethodSpies.update.callCount).toStrictEqual(0);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call history.push', async () => {
|
||
4 years ago
|
await wrapper.instance().onSubmit(MOCK_EVENT);
|
||
4 years ago
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
||
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(
|
||
4 years ago
|
CONFIRM_TRANSACTION_ROUTE,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
beforeEach(() => {
|
||
4 years ago
|
sinon.stub(SendFooter.prototype, 'formShouldBeDisabled').returns(true);
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<SendFooter
|
||
|
addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
|
||
|
amount="mockAmount"
|
||
|
clearSend={propsMethodSpies.clearSend}
|
||
|
disabled
|
||
|
editingTransactionId="mockEditingTransactionId"
|
||
|
errors={{}}
|
||
4 years ago
|
from={{ address: 'mockAddress', balance: 'mockBalance' }}
|
||
5 years ago
|
gasLimit="mockGasLimit"
|
||
|
gasPrice="mockGasPrice"
|
||
|
gasTotal="mockGasTotal"
|
||
|
history={historySpies}
|
||
|
inError={false}
|
||
5 years ago
|
sendToken={{ mockProp: 'mockSendTokenProp' }}
|
||
5 years ago
|
sign={propsMethodSpies.sign}
|
||
|
to="mockTo"
|
||
|
toAccounts={['mockAccount']}
|
||
|
tokenBalance="mockTokenBalance"
|
||
5 years ago
|
unapprovedTxs={{}}
|
||
5 years ago
|
update={propsMethodSpies.update}
|
||
4 years ago
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
||
4 years ago
|
/>,
|
||
|
{ context: { t: (str) => str, metricsEvent: () => ({}) } },
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
SendFooter.prototype.formShouldBeDisabled.restore();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render a PageContainerFooter component', () => {
|
||
|
expect(wrapper.find(PageContainerFooter)).toHaveLength(1);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should pass the correct props to PageContainerFooter', () => {
|
||
4 years ago
|
const { onCancel, onSubmit, disabled } = wrapper
|
||
|
.find(PageContainerFooter)
|
||
4 years ago
|
.props();
|
||
4 years ago
|
expect(disabled).toStrictEqual(true);
|
||
4 years ago
|
|
||
4 years ago
|
expect(SendFooter.prototype.onSubmit.callCount).toStrictEqual(0);
|
||
4 years ago
|
onSubmit(MOCK_EVENT);
|
||
4 years ago
|
expect(SendFooter.prototype.onSubmit.callCount).toStrictEqual(1);
|
||
4 years ago
|
|
||
4 years ago
|
expect(SendFooter.prototype.onCancel.callCount).toStrictEqual(0);
|
||
4 years ago
|
onCancel();
|
||
4 years ago
|
expect(SendFooter.prototype.onCancel.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|