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 Modal from '../../modal';
|
|
|
|
import CancelTransaction from './cancel-transaction.component';
|
|
|
|
import CancelTransactionGasFee from './cancel-transaction-gas-fee';
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('CancelTransaction Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = (key) => key;
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render a CancelTransaction modal', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const wrapper = shallow(<CancelTransaction newGasFee="0x1319718a5000" />, {
|
|
|
|
context: { t },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.find(Modal)).toHaveLength(1);
|
|
|
|
expect(wrapper.find(CancelTransactionGasFee)).toHaveLength(1);
|
|
|
|
expect(wrapper.find(CancelTransactionGasFee).props().value).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'0x1319718a5000',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.find('.cancel-transaction__title').text()).toStrictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
'cancellationGasFee',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('.cancel-transaction__description').text(),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('attemptToCancelDescription');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct props to the Modal component', async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const createCancelTransactionSpy = sinon
|
|
|
|
.stub()
|
2021-02-04 19:15:23 +01:00
|
|
|
.callsFake(() => Promise.resolve());
|
|
|
|
const hideModalSpy = sinon.spy();
|
2018-09-19 23:30:52 +02:00
|
|
|
|
|
|
|
const wrapper = shallow(
|
|
|
|
<CancelTransaction
|
|
|
|
defaultNewGasPrice="0x3b9aca00"
|
|
|
|
createCancelTransaction={createCancelTransactionSpy}
|
|
|
|
hideModal={hideModalSpy}
|
2020-08-14 13:47:02 +02:00
|
|
|
showTransactionConfirmedModal={() => undefined}
|
2018-09-19 23:30:52 +02:00
|
|
|
/>,
|
2020-07-14 17:20:41 +02:00
|
|
|
{ context: { t } },
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.find(Modal)).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
const modalProps = wrapper.find(Modal).props();
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(modalProps.headerText).toStrictEqual('attemptToCancel');
|
|
|
|
expect(modalProps.submitText).toStrictEqual('yesLetsTry');
|
|
|
|
expect(modalProps.cancelText).toStrictEqual('nevermind');
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(createCancelTransactionSpy.callCount).toStrictEqual(0);
|
|
|
|
expect(hideModalSpy.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
await modalProps.onSubmit();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(createCancelTransactionSpy.callCount).toStrictEqual(1);
|
|
|
|
expect(hideModalSpy.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
modalProps.onCancel();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(hideModalSpy.callCount).toStrictEqual(2);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|