1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/pages/onboarding-flow/welcome/welcome.test.js
vthomas13 40e4a3653f
Updating Terms of Use, Adding popover and onboarding flow check (#18221)
* WIP commit

* Moving copy out of messages.json, styling changes

* handling scroll button click and disable logic

* moving scrollButton up to popover component, adding logic for accepting terms of use in popover and onboarding flows

* adding terms of use to e2e wallet creation/import

* adjusting failing unit test

* fixing QR code e2e

* updating welcome test

* setting app state in fixtures

* Update app/scripts/controllers/app-state.js

removing console log

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/app/terms-of-use-popup/terms-of-use-popup.stories.js

adding args to ToU popup storybook

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* Update ui/components/app/terms-of-use-popup/terms-of-use-popup.js

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>

* updating DS components in terms of use

* popover styling changes

* adding metametrics tracking

* editing scrollbutton behavior

* adding unit test

* code fencing

---------

Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
2023-04-14 12:51:13 -04:00

115 lines
3.7 KiB
JavaScript

import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import initializedMockState from '../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import {
setFirstTimeFlowType,
setTermsOfUseLastAgreed,
} from '../../../store/actions';
import {
ONBOARDING_METAMETRICS,
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
ONBOARDING_COMPLETION_ROUTE,
} from '../../../helpers/constants/routes';
import OnboardingWelcome from './welcome';
const mockHistoryReplace = jest.fn();
const mockHistoryPush = jest.fn();
jest.mock('../../../store/actions.ts', () => ({
setFirstTimeFlowType: jest.fn().mockReturnValue(
jest.fn((type) => {
return type;
}),
),
setTermsOfUseLastAgreed: jest.fn().mockReturnValue(
jest.fn((type) => {
return type;
}),
),
}));
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({
push: mockHistoryPush,
replace: mockHistoryReplace,
}),
}));
describe('Onboarding Welcome Component', () => {
const mockState = {
metamask: {
identities: {},
selectedAddress: '',
},
};
afterEach(() => {
jest.clearAllMocks();
});
describe('Initialized State Conditionals with keyrings and firstTimeFlowType', () => {
it('should route to secure your wallet when keyring is present but not imported first time flow type', () => {
const mockStore = configureMockStore([thunk])(initializedMockState);
renderWithProvider(<OnboardingWelcome />, mockStore);
expect(mockHistoryReplace).toHaveBeenCalledWith(
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
);
});
it('should route to completion when keyring is present and imported first time flow type', () => {
const importFirstTimeFlowState = {
...initializedMockState,
metamask: {
...initializedMockState.metamask,
firstTimeFlowType: 'import',
},
};
const mockStore = configureMockStore([thunk])(importFirstTimeFlowState);
renderWithProvider(<OnboardingWelcome />, mockStore);
expect(mockHistoryReplace).toHaveBeenCalledWith(
ONBOARDING_COMPLETION_ROUTE,
);
});
});
describe('Welcome Component', () => {
const mockStore = configureMockStore([thunk])(mockState);
it('should render', () => {
renderWithProvider(<OnboardingWelcome />, mockStore);
const onboardingWelcome = screen.queryByTestId('onboarding-welcome');
expect(onboardingWelcome).toBeInTheDocument();
});
it('should set first time flow to create and route to metametrics', () => {
renderWithProvider(<OnboardingWelcome />, mockStore);
const termsCheckbox = screen.getByTestId('onboarding-terms-checkbox');
fireEvent.click(termsCheckbox);
const createWallet = screen.getByTestId('onboarding-create-wallet');
fireEvent.click(createWallet);
expect(setTermsOfUseLastAgreed).toHaveBeenCalled();
expect(setFirstTimeFlowType).toHaveBeenCalledWith('create');
});
it('should set first time flow to import and route to metametrics', () => {
renderWithProvider(<OnboardingWelcome />, mockStore);
const termsCheckbox = screen.getByTestId('onboarding-terms-checkbox');
fireEvent.click(termsCheckbox);
const createWallet = screen.getByTestId('onboarding-import-wallet');
fireEvent.click(createWallet);
expect(setTermsOfUseLastAgreed).toHaveBeenCalled();
expect(setFirstTimeFlowType).toHaveBeenCalledWith('import');
expect(mockHistoryPush).toHaveBeenCalledWith(ONBOARDING_METAMETRICS);
});
});
});