2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2022-09-28 16:43:13 +02:00
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
|
|
|
import MetaMetricsOptIn from '.';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('MetaMetrics Opt In', () => {
|
2020-01-30 20:34:45 +01:00
|
|
|
const props = {
|
2022-09-28 16:43:13 +02:00
|
|
|
setParticipateInMetaMetrics: jest.fn().mockResolvedValue(),
|
|
|
|
hideModal: jest.fn(),
|
2020-01-30 20:34:45 +01:00
|
|
|
participateInMetaMetrics: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
it('should match snapshot', () => {
|
|
|
|
const { container } = renderWithProvider(
|
|
|
|
<MetaMetricsOptIn.WrappedComponent />,
|
|
|
|
);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
expect(container).toMatchSnapshot();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('passes false to setParticipateInMetaMetrics and hides modal', async () => {
|
2022-09-28 16:43:13 +02:00
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<MetaMetricsOptIn.WrappedComponent {...props} />,
|
2021-10-05 21:20:42 +02:00
|
|
|
);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
fireEvent.click(queryByText('[noThanks]'));
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(props.setParticipateInMetaMetrics).toHaveBeenCalledWith(false);
|
|
|
|
expect(props.hideModal).toHaveBeenCalled();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('passes true to setParticipateInMetaMetrics and hides modal', async () => {
|
2022-09-28 16:43:13 +02:00
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<MetaMetricsOptIn.WrappedComponent {...props} />,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-09-28 16:43:13 +02:00
|
|
|
fireEvent.click(queryByText('[affirmAgree]'));
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(props.setParticipateInMetaMetrics).toHaveBeenCalledWith(true);
|
|
|
|
expect(props.hideModal).toHaveBeenCalled();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|