2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
2021-09-17 06:37:50 +02:00
|
|
|
import {
|
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
} from '../../../helpers/constants/routes';
|
2021-03-16 22:00:08 +01:00
|
|
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer';
|
2021-09-17 06:37:50 +02:00
|
|
|
import { renderWithProvider } from '../../../../test/jest';
|
2021-03-16 22:00:08 +01:00
|
|
|
import SendFooter from './send-footer.component';
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('SendFooter Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
addToAddressBookIfNew: sinon.spy(),
|
2021-09-17 06:37:50 +02:00
|
|
|
cancelTx: sinon.spy(),
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState: sinon.spy(),
|
2020-02-11 21:33:32 +01:00
|
|
|
sign: sinon.spy(),
|
|
|
|
update: sinon.spy(),
|
2021-04-15 20:01:46 +02:00
|
|
|
mostRecentOverviewPage: '/',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 21:33:32 +01:00
|
|
|
const historySpies = {
|
|
|
|
push: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const MOCK_EVENT = { preventDefault: () => undefined };
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-09-17 06:37:50 +02:00
|
|
|
const renderShallow = (props) => {
|
|
|
|
return shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<SendFooter
|
|
|
|
addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState={propsMethodSpies.resetSendState}
|
2021-09-17 06:37:50 +02:00
|
|
|
cancelTx={propsMethodSpies.cancelTx}
|
2019-12-03 17:35:44 +01:00
|
|
|
disabled
|
2021-09-17 06:37:50 +02:00
|
|
|
draftTransactionID="ID"
|
2019-12-03 17:35:44 +01:00
|
|
|
history={historySpies}
|
|
|
|
sign={propsMethodSpies.sign}
|
|
|
|
to="mockTo"
|
|
|
|
toAccounts={['mockAccount']}
|
|
|
|
sendErrors={{}}
|
2021-09-17 06:37:50 +02:00
|
|
|
sendStage="DRAFT"
|
2021-06-23 23:35:25 +02:00
|
|
|
gasEstimateType="BASIC"
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
2021-09-17 06:37:50 +02:00
|
|
|
{...props}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{ context: { t: (str) => str, metricsEvent: () => ({}) } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-09-17 06:37:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
sinon.spy(SendFooter.prototype, 'onCancel');
|
|
|
|
sinon.spy(SendFooter.prototype, 'onSubmit');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = renderShallow();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-06-23 23:35:25 +02:00
|
|
|
propsMethodSpies.resetSendState.resetHistory();
|
2021-09-17 06:37:50 +02:00
|
|
|
propsMethodSpies.cancelTx.resetHistory();
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.addToAddressBookIfNew.resetHistory();
|
2021-06-23 23:35:25 +02:00
|
|
|
propsMethodSpies.resetSendState.resetHistory();
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.sign.resetHistory();
|
|
|
|
propsMethodSpies.update.resetHistory();
|
|
|
|
historySpies.push.resetHistory();
|
|
|
|
SendFooter.prototype.onCancel.resetHistory();
|
|
|
|
SendFooter.prototype.onSubmit.resetHistory();
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterAll(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('onCancel', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should call resetSendState', () => {
|
|
|
|
expect(propsMethodSpies.resetSendState.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().onCancel();
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(propsMethodSpies.resetSendState.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-09-17 06:37:50 +02:00
|
|
|
it('should call cancelTx', () => {
|
|
|
|
expect(propsMethodSpies.cancelTx.callCount).toStrictEqual(0);
|
|
|
|
wrapper.instance().onCancel();
|
|
|
|
expect(propsMethodSpies.cancelTx.callCount).toStrictEqual(1);
|
|
|
|
expect(propsMethodSpies.cancelTx.getCall(0).args[0]?.id).toStrictEqual(
|
|
|
|
'ID',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should call history.push', () => {
|
|
|
|
expect(historySpies.push.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().onCancel();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
|
|
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'mostRecentOverviewPage',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2021-09-17 06:37:50 +02:00
|
|
|
|
|
|
|
it('should call history.push with DEFAULT_ROUTE in edit stage', () => {
|
|
|
|
wrapper = renderShallow({ sendStage: 'EDIT' });
|
|
|
|
expect(historySpies.push.callCount).toStrictEqual(0);
|
|
|
|
wrapper.instance().onCancel();
|
|
|
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
|
|
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(DEFAULT_ROUTE);
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('onSubmit', () => {
|
|
|
|
it('should call addToAddressBookIfNew with the correct params', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.instance().onSubmit(MOCK_EVENT);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.addToAddressBookIfNew.calledOnce).toStrictEqual(
|
|
|
|
true,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
|
|
|
propsMethodSpies.addToAddressBookIfNew.getCall(0).args,
|
|
|
|
).toStrictEqual(['mockTo', ['mockAccount']]);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should call props.sign whe submitting', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await wrapper.instance().onSubmit(MOCK_EVENT);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.sign.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should call history.push', async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await wrapper.instance().onSubmit(MOCK_EVENT);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(historySpies.push.callCount).toStrictEqual(1);
|
|
|
|
expect(historySpies.push.getCall(0).args[0]).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<SendFooter
|
|
|
|
addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
|
|
|
|
amount="mockAmount"
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState={propsMethodSpies.resetSendState}
|
2021-09-17 06:37:50 +02:00
|
|
|
cancelTx={propsMethodSpies.cancelTx}
|
2019-12-03 17:35:44 +01:00
|
|
|
disabled
|
2021-09-17 06:37:50 +02:00
|
|
|
draftTransactionID="ID"
|
2019-12-03 17:35:44 +01:00
|
|
|
editingTransactionId="mockEditingTransactionId"
|
|
|
|
errors={{}}
|
2020-11-03 00:41:28 +01:00
|
|
|
from={{ address: 'mockAddress', balance: 'mockBalance' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
gasLimit="mockGasLimit"
|
|
|
|
gasPrice="mockGasPrice"
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
history={historySpies}
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken={{ mockProp: 'mockSendTokenProp' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
sign={propsMethodSpies.sign}
|
|
|
|
to="mockTo"
|
|
|
|
toAccounts={['mockAccount']}
|
|
|
|
tokenBalance="mockTokenBalance"
|
2020-01-15 17:58:23 +01:00
|
|
|
unapprovedTxs={{}}
|
2019-12-03 17:35:44 +01:00
|
|
|
update={propsMethodSpies.update}
|
2021-04-15 20:01:46 +02:00
|
|
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{ context: { t: (str) => str, metricsEvent: () => ({}) } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-05-25 02:53:54 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render a PageContainerFooter component', () => {
|
|
|
|
expect(wrapper.find(PageContainerFooter)).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-07 14:03:20 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct props to PageContainerFooter', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const { onCancel, onSubmit, disabled } = wrapper
|
|
|
|
.find(PageContainerFooter)
|
2021-02-04 19:15:23 +01:00
|
|
|
.props();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(disabled).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(SendFooter.prototype.onSubmit.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
onSubmit(MOCK_EVENT);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(SendFooter.prototype.onSubmit.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(SendFooter.prototype.onCancel.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
onCancel();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(SendFooter.prototype.onCancel.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-09-17 06:37:50 +02:00
|
|
|
|
|
|
|
describe('Cancel Button', () => {
|
|
|
|
const renderFooter = (props) =>
|
|
|
|
renderWithProvider(
|
|
|
|
<SendFooter
|
|
|
|
disabled
|
|
|
|
mostRecentOverviewPage="mostRecentOverviewPage"
|
|
|
|
draftTransactionID="ID"
|
|
|
|
sendErrors={{}}
|
|
|
|
sendStage="DRAFT"
|
|
|
|
{...props}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
it('has a cancel button in footer', () => {
|
|
|
|
const { getByText } = renderFooter();
|
|
|
|
expect(getByText('Cancel')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has label changed to Reject in editing stage', () => {
|
|
|
|
const { getByText } = renderFooter({ sendStage: 'EDIT' });
|
|
|
|
expect(getByText('Reject')).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|