2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2022-09-28 16:43:13 +02:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
|
|
|
import mockState from '../../../../../test/data/mock-state.json';
|
|
|
|
import {
|
|
|
|
yesLetsTry,
|
|
|
|
nevermind,
|
|
|
|
} from '../../../../../app/_locales/en/messages.json';
|
|
|
|
import CancelTransaction from '.';
|
|
|
|
|
|
|
|
const mockCreateCancelTransaction = jest.fn();
|
|
|
|
const mockShowModal = jest.fn();
|
|
|
|
const mockHideModal = jest.fn();
|
|
|
|
|
|
|
|
jest.mock('../../../../store/actions.js', () => {
|
|
|
|
return {
|
|
|
|
createCancelTransaction: () => mockCreateCancelTransaction,
|
|
|
|
showModal: () => mockShowModal,
|
|
|
|
hideModal: () => mockHideModal,
|
|
|
|
};
|
|
|
|
});
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('CancelTransaction Component', () => {
|
2022-09-28 16:43:13 +02:00
|
|
|
afterEach(() => {
|
|
|
|
mockCreateCancelTransaction.mockClear();
|
|
|
|
mockShowModal.mockClear();
|
|
|
|
mockHideModal.mockClear();
|
|
|
|
});
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
const props = {
|
|
|
|
newGasFee: '0x1319718a5000', // 21000000000000
|
|
|
|
};
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
it('should match snapshot', () => {
|
|
|
|
const mockStore = configureMockStore()(mockState);
|
|
|
|
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<CancelTransaction {...props} />,
|
|
|
|
mockStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2022-09-28 16:43:13 +02:00
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call create cancel transaction and hide modal', async () => {
|
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<CancelTransaction />,
|
|
|
|
mockStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2022-09-28 16:43:13 +02:00
|
|
|
|
|
|
|
fireEvent.click(queryByText(yesLetsTry.message));
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(mockCreateCancelTransaction).toHaveBeenCalled();
|
|
|
|
expect(mockHideModal).toHaveBeenCalled();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
it('should hide modal when clicking "Nevermind" button', () => {
|
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<CancelTransaction />,
|
|
|
|
mockStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
fireEvent.click(queryByText(nevermind.message));
|
|
|
|
|
|
|
|
expect(mockCreateCancelTransaction).not.toHaveBeenCalled();
|
|
|
|
expect(mockHideModal).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should hide modal when closing from header', () => {
|
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
|
|
|
const { queryByTestId } = renderWithProvider(
|
|
|
|
<CancelTransaction {...props} />,
|
|
|
|
mockStore,
|
|
|
|
);
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
fireEvent.click(queryByTestId('modal-header-close'));
|
2018-09-19 23:30:52 +02:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
expect(mockCreateCancelTransaction).not.toHaveBeenCalled();
|
|
|
|
expect(mockHideModal).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|