From f9f628690c5069e42ecda2430bef8dd793ec33dc Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Thu, 20 Apr 2023 13:12:37 -0500 Subject: [PATCH] Metametrics onboarding unit test, snapshot (#18253) * Metametrics onboarding unit test, snapshot * Test route navigation in metametrics --- .../__snapshots__/metametrics.test.js.snap | 156 ++++++++++++++++++ .../metametrics/metametrics.test.js | 95 +++++++++++ 2 files changed, 251 insertions(+) create mode 100644 ui/pages/onboarding-flow/metametrics/__snapshots__/metametrics.test.js.snap create mode 100644 ui/pages/onboarding-flow/metametrics/metametrics.test.js diff --git a/ui/pages/onboarding-flow/metametrics/__snapshots__/metametrics.test.js.snap b/ui/pages/onboarding-flow/metametrics/__snapshots__/metametrics.test.js.snap new file mode 100644 index 000000000..8bde23f94 --- /dev/null +++ b/ui/pages/onboarding-flow/metametrics/__snapshots__/metametrics.test.js.snap @@ -0,0 +1,156 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Onboarding Metametrics Component should match snapshot 1`] = ` +
+
+

+ Help us improve MetaMask +

+

+ MetaMask would like to gather usage data to better understand how our users interact with MetaMask. This data will be used to provide the service, which includes improving the service based on your use. +

+

+ MetaMask will... +

+
    +
  • + + Always allow you to opt-out via Settings +
  • +
  • + + Send anonymized click and pageview events +
  • +
  • +
    + + + + + + Never + + collect information we don’t need to provide the service (such as keys, addresses, transaction hashes, or balances) + + +
    +
  • +
  • +
    + + + + + + Never + + collect your full IP address* + + +
    +
  • +
  • +
    + + + + + + Never + + sell data. Ever! + + +
    + +
  • +
+
+ This data is aggregated and is therefore anonymous for the purposes of General Data Protection Regulation (EU) 2016/679. +
+
+ + + * When you use Infura as your default RPC provider in MetaMask, Infura will collect your IP address and your Ethereum wallet address when you send a transaction. We don’t store this information in a way that allows our systems to associate those two pieces of data. For more information on how MetaMask and Infura interact from a data collection perspective, see our update + + here + + . For more information on our privacy practices in general, see our + + Privacy Policy here + + . + + +
+
+ + +
+
+
+`; diff --git a/ui/pages/onboarding-flow/metametrics/metametrics.test.js b/ui/pages/onboarding-flow/metametrics/metametrics.test.js new file mode 100644 index 000000000..363d266d6 --- /dev/null +++ b/ui/pages/onboarding-flow/metametrics/metametrics.test.js @@ -0,0 +1,95 @@ +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 { ONBOARDING_CREATE_PASSWORD_ROUTE } from '../../../helpers/constants/routes'; +import { + onboardingMetametricsAgree, + onboardingMetametricsDisagree, +} from '../../../../app/_locales/en/messages.json'; +import { setParticipateInMetaMetrics } from '../../../store/actions'; +import OnboardingMetametrics from './metametrics'; + +const mockPushHistory = jest.fn(); + +jest.mock('react-router-dom', () => { + const original = jest.requireActual('react-router-dom'); + return { + ...original, + useLocation: jest.fn(() => ({ search: '' })), + useHistory: () => ({ + push: mockPushHistory, + }), + }; +}); + +jest.mock('../../../store/actions.ts', () => ({ + setParticipateInMetaMetrics: jest + .fn() + .mockReturnValue(jest.fn((val) => Promise.resolve([val]))), +})); + +describe('Onboarding Metametrics Component', () => { + let mockStore; + + const mockState = { + metamask: { + firstTimeFlowType: 'create', + participateInMetaMetrics: '', + }, + }; + + beforeEach(() => { + mockStore = configureMockStore([thunk])(mockState); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should match snapshot', () => { + const { container } = renderWithProvider( + , + mockStore, + ); + + expect(container).toMatchSnapshot(); + }); + + it('should set setParticipateInMetaMetrics to true when clicking agree', async () => { + const { queryByText } = renderWithProvider( + , + mockStore, + ); + + const confirmAgree = queryByText(onboardingMetametricsAgree.message); + + fireEvent.click(confirmAgree); + + await waitFor(() => { + expect(setParticipateInMetaMetrics).toHaveBeenCalledWith(true); + expect(mockPushHistory).toHaveBeenCalledWith( + ONBOARDING_CREATE_PASSWORD_ROUTE, + ); + }); + }); + + it('should set setParticipateInMetaMetrics to false when clicking cancel', async () => { + const { queryByText } = renderWithProvider( + , + mockStore, + ); + + const confirmCancel = queryByText(onboardingMetametricsDisagree.message); + + fireEvent.click(confirmCancel); + + await waitFor(() => { + expect(setParticipateInMetaMetrics).toHaveBeenCalledWith(false); + expect(mockPushHistory).toHaveBeenCalledWith( + ONBOARDING_CREATE_PASSWORD_ROUTE, + ); + }); + }); +});