1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/components/institutional/compliance-modal/compliance-modal.test.js
António Regadas 300bfd6e69
[MMI] 2642 compliance modal component (#18410)
* adds component, styles and storybook file

* wip

* prettier and adds test

* prettier

* lint

* review fix

* lint

* updates to IconSize, IconName
2023-04-13 11:14:44 +01:00

56 lines
1.5 KiB
JavaScript

import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { useDispatch } from 'react-redux';
import sinon from 'sinon';
import { hideModal } from '../../../store/actions';
import ComplianceModal from '.';
jest.mock('react-redux', () => ({
useDispatch: jest.fn(),
}));
jest.mock('../../../store/actions', () => ({
hideModal: jest.fn(),
}));
describe('ComplianceModal', () => {
let dispatchMock;
beforeEach(() => {
dispatchMock = jest.fn();
useDispatch.mockReturnValue(dispatchMock);
});
afterEach(() => {
jest.resetAllMocks();
});
it('should render the correct content', () => {
const { container, getByTestId } = render(<ComplianceModal />);
expect(getByTestId('compliance-info')).toBeInTheDocument();
expect(getByTestId('compliance-bullets')).toBeInTheDocument();
expect(container).toMatchSnapshot();
});
it('should close the modal when close button is clicked', () => {
const { getByTestId } = render(<ComplianceModal />);
fireEvent.click(getByTestId('compliance-modal-close'));
expect(hideModal).toHaveBeenCalled();
expect(dispatchMock).toHaveBeenCalledWith(hideModal());
});
it('should open the Compliance page when submit button is clicked', () => {
global.platform = { openTab: sinon.spy() };
const { container } = render(<ComplianceModal />);
const btn = container.getElementsByClassName('btn-primary')[0];
fireEvent.click(btn);
expect(global.platform.openTab.called).toBeTruthy();
});
});