1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/pages/onboarding-flow/creation-successful/creation-successful.test.js
Alex Donesky 71f91568db
Migrate completedOnboarding and firstTimeFlowType state into onboardingController (#12356)
* migrate completedOnboarding state into onboardingController

* migrate firstTimeFlowType state from preferencesController to onboardingController
2021-10-15 13:52:52 -05:00

50 lines
1.7 KiB
JavaScript

import React from 'react';
import { fireEvent } from '@testing-library/react';
import reactRouterDom from 'react-router-dom';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { ONBOARDING_PRIVACY_SETTINGS_ROUTE } from '../../../helpers/constants/routes';
import {
renderWithProvider,
setBackgroundConnection,
} from '../../../../test/jest';
import CreationSuccessful from './creation-successful';
const completeOnboardingStub = jest
.fn()
.mockImplementation(() => Promise.resolve());
describe('Creation Successful Onboarding View', () => {
const mockStore = {
metamask: {
provider: {
type: 'test',
},
},
};
const store = configureMockStore([thunk])(mockStore);
setBackgroundConnection({ completeOnboarding: completeOnboardingStub });
const pushMock = jest.fn();
beforeAll(() => {
jest
.spyOn(reactRouterDom, 'useHistory')
.mockImplementation()
.mockReturnValue({ push: pushMock });
});
it('should call completeOnboarding in the background when "Done" button is clicked', () => {
const { getByText } = renderWithProvider(<CreationSuccessful />, store);
const doneButton = getByText('Done');
fireEvent.click(doneButton);
expect(completeOnboardingStub).toHaveBeenCalledTimes(1);
});
it('should redirect to privacy-settings view when "Set advanced privacy settings" button is clicked', () => {
const { getByText } = renderWithProvider(<CreationSuccessful />, store);
const privacySettingsButton = getByText('Set advanced privacy settings');
fireEvent.click(privacySettingsButton);
expect(pushMock).toHaveBeenCalledWith(ONBOARDING_PRIVACY_SETTINGS_ROUTE);
});
});