2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { mount } from 'enzyme';
|
2021-04-28 21:53:59 +02:00
|
|
|
import messages from '../../../../../app/_locales/en/messages.json';
|
2021-03-16 22:00:08 +01:00
|
|
|
import MetaMetricsOptIn from './metametrics-opt-in-modal.container';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('MetaMetrics Opt In', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
setParticipateInMetaMetrics: sinon.stub().resolves(),
|
|
|
|
hideModal: sinon.spy(),
|
|
|
|
participateInMetaMetrics: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = mount(<MetaMetricsOptIn.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
metricsEvent: () => undefined,
|
|
|
|
t: (key) => messages[key].message,
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
props.setParticipateInMetaMetrics.resetHistory();
|
|
|
|
props.hideModal.resetHistory();
|
|
|
|
});
|
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 () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const noThanks = wrapper.find('.btn-default.page-container__footer-button');
|
|
|
|
noThanks.simulate('click');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(await props.setParticipateInMetaMetrics.calledOnce).toStrictEqual(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(props.setParticipateInMetaMetrics.getCall(0).args[0]).toStrictEqual(
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
expect(props.hideModal.calledOnce).toStrictEqual(true);
|
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 () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const affirmAgree = wrapper.find(
|
|
|
|
'.btn-primary.page-container__footer-button',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
affirmAgree.simulate('click');
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(await props.setParticipateInMetaMetrics.calledOnce).toStrictEqual(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(props.setParticipateInMetaMetrics.getCall(0).args[0]).toStrictEqual(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(props.hideModal.calledOnce).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|