1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/components/app/modals/cancel-transaction/cancel-transaction.component.test.js

61 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
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
describe('CancelTransaction Component', () => {
const t = (key) => key;
2018-09-19 23:30:52 +02:00
it('should render a CancelTransaction modal', () => {
2020-11-03 00:41:28 +01:00
const wrapper = shallow(<CancelTransaction newGasFee="0x1319718a5000" />, {
context: { t },
});
2018-09-19 23:30:52 +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',
);
expect(wrapper.find('.cancel-transaction__title').text()).toStrictEqual(
2020-11-03 00:41:28 +01:00
'cancellationGasFee',
);
expect(
2020-11-03 00:41:28 +01:00
wrapper.find('.cancel-transaction__description').text(),
).toStrictEqual('attemptToCancelDescription');
});
2018-09-19 23:30:52 +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()
.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}
showTransactionConfirmedModal={() => undefined}
2018-09-19 23:30:52 +02:00
/>,
{ context: { t } },
);
2018-09-19 23:30:52 +02:00
expect(wrapper.find(Modal)).toHaveLength(1);
const modalProps = wrapper.find(Modal).props();
2018-09-19 23:30:52 +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
expect(createCancelTransactionSpy.callCount).toStrictEqual(0);
expect(hideModalSpy.callCount).toStrictEqual(0);
await modalProps.onSubmit();
expect(createCancelTransactionSpy.callCount).toStrictEqual(1);
expect(hideModalSpy.callCount).toStrictEqual(1);
modalProps.onCancel();
expect(hideModalSpy.callCount).toStrictEqual(2);
});
});