1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/pages/send/send-footer/send-footer.test.js
Thomas Huang 646dbaaff2
Continue converting tests from enzyme to @testing-library/react (#16373)
* Add transaction activity log component

* Remove duplicate tx activity log snapshot.

* Convert Identicon test to tlr.

* Convert Metafoxlogo test to tlr.

* Convert Reveal Seed Phrase test to tlr.

* Consolidate and convert Send Footer test to tlr.

* Convert Settings test to tlr.

* Consolidate and convert security tab test to tlr.

* Convert null selectedOption to empty string, and add test id to Dropdown component.

* Add Send state to mock-state

* Lint mock-state.json
2022-11-04 13:56:24 -07:00

137 lines
3.7 KiB
JavaScript

import React from 'react';
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 {
CONFIRM_TRANSACTION_ROUTE,
DEFAULT_ROUTE,
} from '../../../helpers/constants/routes';
import { SEND_STAGES } from '../../../ducks/send';
import SendFooter from '.';
const mockResetSendState = jest.fn();
const mockSendTransaction = jest.fn();
const mockAddtoAddressBook = jest.fn();
const mockCancelTx = jest.fn();
jest.mock('../../../ducks/send/index.js', () => ({
...jest.requireActual('../../../ducks/send/index.js'),
signTransaction: () => mockSendTransaction,
resetSendState: () => mockResetSendState,
}));
jest.mock('../../../store/actions.js', () => ({
addToAddressBook: () => mockAddtoAddressBook,
cancelTx: () => mockCancelTx,
}));
describe('SendFooter Component', () => {
const props = {
history: {
push: jest.fn(),
},
};
afterEach(() => {
props.history.push.mockReset();
});
const mockStore = configureMockStore([thunk])(mockState);
it('should match snapshot', () => {
const { container } = renderWithProvider(
<SendFooter {...props} />,
mockStore,
);
expect(container).toMatchSnapshot();
});
describe('onCancel', () => {
it('should call reset send state and route to recent page without cancelling tx', () => {
const { queryByText } = renderWithProvider(
<SendFooter {...props} />,
mockStore,
);
const cancelText = queryByText('Cancel');
fireEvent.click(cancelText);
expect(mockResetSendState).toHaveBeenCalled();
expect(mockCancelTx).not.toHaveBeenCalled();
expect(props.history.push).toHaveBeenCalledWith(
'/mostRecentOverviewPage',
);
});
it('should reject/cancel tx when coming from tx editing and route to index', () => {
const sendDataState = {
...mockState,
send: {
currentTransactionUUID: '01',
draftTransactions: {
'01': {
id: '99',
},
},
stage: SEND_STAGES.EDIT,
},
};
const sendStateStore = configureMockStore([thunk])(sendDataState);
const { queryByText } = renderWithProvider(
<SendFooter {...props} />,
sendStateStore,
);
const rejectText = queryByText('Reject');
fireEvent.click(rejectText);
expect(mockResetSendState).toHaveBeenCalled();
expect(mockCancelTx).toHaveBeenCalled();
expect(props.history.push).toHaveBeenCalledWith(DEFAULT_ROUTE);
});
});
describe('onSubmit', () => {
it('should', async () => {
const { queryByText } = renderWithProvider(
<SendFooter {...props} />,
mockStore,
);
const nextText = queryByText('Next');
fireEvent.click(nextText);
await waitFor(() => {
expect(mockAddtoAddressBook).toHaveBeenCalled();
expect(mockSendTransaction).toHaveBeenCalled();
expect(props.history.push).toHaveBeenCalledWith(
CONFIRM_TRANSACTION_ROUTE,
);
});
});
});
describe('Component Update', () => {
it('should match snapshot when component updated with errors', () => {
const { container, rerender } = renderWithProvider(
<SendFooter.WrappedComponent />,
);
const sendErrorProps = {
sendErrors: {
gasFee: 'gas fee error',
amount: 'amount error',
},
};
rerender(<SendFooter.WrappedComponent {...sendErrorProps} />);
expect(container).toMatchSnapshot();
});
});
});