Skip to content

Commit

Permalink
test: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptotavares committed Aug 2, 2024
1 parent f2a0f46 commit ca7cf05
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1669,15 +1669,15 @@ exports[`Confirm should match snapshot for signature - typed sign - permit 1`] =
<div
aria-describedby="tippy-tooltip-4"
class=""
data-original-title="3,000"
data-original-title="30"
data-tooltipped=""
style="display: inline;"
tabindex="0"
>
<p
class="mm-box mm-text mm-text--body-md mm-text--ellipsis mm-box--color-inherit"
>
3,000
30
</p>
</div>
</div>
Expand Down
44 changes: 40 additions & 4 deletions ui/pages/confirmations/confirm/confirm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { act } from '@testing-library/react';
import { unapprovedPersonalSignMsg } from '../../../../test/data/confirmations/personal_sign';
import {
orderSignatureMsg,
Expand All @@ -10,6 +11,7 @@ import {
} from '../../../../test/data/confirmations/typed_sign';
import mockState from '../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import * as actions from '../../../store/actions';

import Confirm from './confirm';

Expand All @@ -23,22 +25,41 @@ jest.mock('react-router-dom', () => ({
const middleware = [thunk];

describe('Confirm', () => {
afterEach(() => {
jest.resetAllMocks();
});

it('should render', () => {
const mockStore = configureMockStore(middleware)(mockState);
const { container } = renderWithProvider(<Confirm />, mockStore);
expect(container).toBeDefined();
});

it('should match snapshot for signature - typed sign - permit', () => {
it('should match snapshot for signature - typed sign - permit', async () => {
const mockStateTypedSign = {
...mockState,
metamask: {
...mockState.metamask,
},
confirm: { currentConfirmation: permitSignatureMsg },
};

jest.spyOn(actions, 'getTokenStandardAndDetails').mockResolvedValue({
decimals: '2',
standard: 'erc20',
});

const mockStore = configureMockStore(middleware)(mockStateTypedSign);
const { container } = renderWithProvider(<Confirm />, mockStore);
let container;

await act(async () => {
const { container: renderContainer } = renderWithProvider(
<Confirm />,
mockStore,
);
container = renderContainer;
});

expect(container).toMatchSnapshot();
});

Expand All @@ -55,16 +76,31 @@ describe('Confirm', () => {
expect(container).toMatchSnapshot();
});

it('should match snapshot signature - typed sign - order', () => {
it('should match snapshot signature - typed sign - order', async () => {
const mockStateTypedSign = {
...mockState,
metamask: {
...mockState.metamask,
},
confirm: { currentConfirmation: orderSignatureMsg },
};

jest.spyOn(actions, 'getTokenStandardAndDetails').mockResolvedValue({
decimals: '2',
standard: 'erc20',
});

const mockStore = configureMockStore(middleware)(mockStateTypedSign);
const { container } = renderWithProvider(<Confirm />, mockStore);
let container;

await act(async () => {
const { container: renderContainer } = renderWithProvider(
<Confirm />,
mockStore,
);
container = renderContainer;
});

expect(container).toMatchSnapshot();
});

Expand Down

0 comments on commit ca7cf05

Please sign in to comment.