mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Various test files converting to @testing-library/react. (#15504)
* Convert End of Flow test to tlr. * Convert Select Action test to tlr * Convert Metametrics opt in test to tlr
This commit is contained in:
parent
12943e0e71
commit
06450a4056
@ -69,7 +69,7 @@ export default class EndOfFlowScreen extends PureComponent {
|
|||||||
const { onboardingInitiator } = this.props;
|
const { onboardingInitiator } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="end-of-flow">
|
<div className="end-of-flow" data-testid="end-of-flow">
|
||||||
<MetaFoxLogo />
|
<MetaFoxLogo />
|
||||||
<div className="end-of-flow__emoji">🎉</div>
|
<div className="end-of-flow__emoji">🎉</div>
|
||||||
<div className="first-time-flow__header">{t('congratulations')}</div>
|
<div className="first-time-flow__header">{t('congratulations')}</div>
|
||||||
@ -122,6 +122,7 @@ export default class EndOfFlowScreen extends PureComponent {
|
|||||||
type="primary"
|
type="primary"
|
||||||
className="first-time-flow__button"
|
className="first-time-flow__button"
|
||||||
onClick={this.onComplete}
|
onClick={this.onComplete}
|
||||||
|
data-testid="EOF-complete-button"
|
||||||
>
|
>
|
||||||
{t('endOfFlowMessage10')}
|
{t('endOfFlowMessage10')}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
import { fireEvent, screen } from '@testing-library/react';
|
||||||
import { tick } from '../../../../test/lib/tick';
|
import { tick } from '../../../../test/lib/tick';
|
||||||
import { mountWithRouter } from '../../../../test/lib/render-helpers';
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
||||||
import { DEFAULT_ROUTE } from '../../../helpers/constants/routes';
|
import { DEFAULT_ROUTE } from '../../../helpers/constants/routes';
|
||||||
import EndOfFlowScreen from './end-of-flow.container';
|
import EndOfFlowScreen from './end-of-flow.container';
|
||||||
|
|
||||||
describe('End of Flow Screen', () => {
|
describe('End of Flow Screen', () => {
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
history: {
|
history: {
|
||||||
push: sinon.stub(),
|
push: sinon.stub(),
|
||||||
@ -16,18 +15,17 @@ describe('End of Flow Screen', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mountWithRouter(<EndOfFlowScreen.WrappedComponent {...props} />);
|
renderWithProvider(<EndOfFlowScreen.WrappedComponent {...props} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders', () => {
|
it('should render', () => {
|
||||||
expect(wrapper).toHaveLength(1);
|
const endOfFlow = screen.queryByTestId('end-of-flow');
|
||||||
|
expect(endOfFlow).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate to the default route on click', async () => {
|
it('should navigate to the default route on click', async () => {
|
||||||
const endOfFlowButton = wrapper.find(
|
const endOfFlowButton = screen.getByTestId('EOF-complete-button');
|
||||||
'.btn-primary.first-time-flow__button',
|
fireEvent.click(endOfFlowButton);
|
||||||
);
|
|
||||||
endOfFlowButton.simulate('click');
|
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import configureMockStore from 'redux-mock-store';
|
import { fireEvent, screen } from '@testing-library/react';
|
||||||
import { mountWithRouter } from '../../../../test/lib/render-helpers';
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
||||||
import MetaMetricsOptIn from './metametrics-opt-in.container';
|
import MetaMetricsOptIn from './metametrics-opt-in.container';
|
||||||
|
|
||||||
describe('MetaMetricsOptIn', () => {
|
describe('MetaMetricsOptIn', () => {
|
||||||
it('opt out of MetaMetrics', () => {
|
it('opt out of MetaMetrics', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
sinon.resetHistory();
|
||||||
|
});
|
||||||
const props = {
|
const props = {
|
||||||
history: {
|
history: {
|
||||||
push: sinon.spy(),
|
push: sinon.spy(),
|
||||||
@ -13,21 +16,12 @@ describe('MetaMetricsOptIn', () => {
|
|||||||
setParticipateInMetaMetrics: sinon.stub().resolves(),
|
setParticipateInMetaMetrics: sinon.stub().resolves(),
|
||||||
participateInMetaMetrics: false,
|
participateInMetaMetrics: false,
|
||||||
};
|
};
|
||||||
const store = configureMockStore()({
|
renderWithProvider(<MetaMetricsOptIn.WrappedComponent {...props} />);
|
||||||
metamask: {},
|
|
||||||
});
|
|
||||||
const wrapper = mountWithRouter(
|
|
||||||
<MetaMetricsOptIn.WrappedComponent {...props} />,
|
|
||||||
store,
|
|
||||||
);
|
|
||||||
const noThanksButton = wrapper.find(
|
|
||||||
'.btn-secondary.page-container__footer-button',
|
|
||||||
);
|
|
||||||
noThanksButton.simulate('click');
|
|
||||||
|
|
||||||
|
const noThanksButton = screen.getByTestId('page-container-footer-cancel');
|
||||||
|
fireEvent.click(noThanksButton);
|
||||||
expect(
|
expect(
|
||||||
props.setParticipateInMetaMetrics.calledOnceWithExactly(false),
|
props.setParticipateInMetaMetrics.calledOnceWithExactly(false),
|
||||||
).toStrictEqual(true);
|
).toStrictEqual(true);
|
||||||
props.setParticipateInMetaMetrics.resetHistory();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -66,6 +66,7 @@ export default class SelectAction extends PureComponent {
|
|||||||
type="primary"
|
type="primary"
|
||||||
className="first-time-flow__button"
|
className="first-time-flow__button"
|
||||||
onClick={this.handleImport}
|
onClick={this.handleImport}
|
||||||
|
data-testid="import-wallet-button"
|
||||||
>
|
>
|
||||||
{t('importWallet')}
|
{t('importWallet')}
|
||||||
</Button>
|
</Button>
|
||||||
@ -86,6 +87,7 @@ export default class SelectAction extends PureComponent {
|
|||||||
type="primary"
|
type="primary"
|
||||||
className="first-time-flow__button"
|
className="first-time-flow__button"
|
||||||
onClick={this.handleCreate}
|
onClick={this.handleCreate}
|
||||||
|
data-testid="create-wallet-button"
|
||||||
>
|
>
|
||||||
{t('createAWallet')}
|
{t('createAWallet')}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import { mountWithRouter } from '../../../../test/lib/render-helpers';
|
import { fireEvent, screen } from '@testing-library/react';
|
||||||
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
||||||
import SelectAction from './select-action.container';
|
import SelectAction from './select-action.container';
|
||||||
|
|
||||||
describe('Selection Action', () => {
|
describe('Selection Action', () => {
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
isInitialized: false,
|
isInitialized: false,
|
||||||
setFirstTimeFlowType: sinon.spy(),
|
setFirstTimeFlowType: sinon.spy(),
|
||||||
@ -15,7 +14,7 @@ describe('Selection Action', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mountWithRouter(<SelectAction.WrappedComponent {...props} />);
|
renderWithProvider(<SelectAction.WrappedComponent {...props} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -24,10 +23,8 @@ describe('Selection Action', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clicks import wallet to route to import FTF', () => {
|
it('clicks import wallet to route to import FTF', () => {
|
||||||
const importWalletButton = wrapper
|
const importButton = screen.getByTestId('import-wallet-button');
|
||||||
.find('.btn-primary.first-time-flow__button')
|
fireEvent.click(importButton);
|
||||||
.at(0);
|
|
||||||
importWalletButton.simulate('click');
|
|
||||||
|
|
||||||
expect(props.setFirstTimeFlowType.calledOnce).toStrictEqual(true);
|
expect(props.setFirstTimeFlowType.calledOnce).toStrictEqual(true);
|
||||||
expect(props.setFirstTimeFlowType.getCall(0).args[0]).toStrictEqual(
|
expect(props.setFirstTimeFlowType.getCall(0).args[0]).toStrictEqual(
|
||||||
@ -37,10 +34,8 @@ describe('Selection Action', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('clicks create wallet to route to create FTF', () => {
|
it('clicks create wallet to route to create FTF', () => {
|
||||||
const createWalletButton = wrapper
|
const importButton = screen.getByTestId('create-wallet-button');
|
||||||
.find('.btn-primary.first-time-flow__button')
|
fireEvent.click(importButton);
|
||||||
.at(1);
|
|
||||||
createWalletButton.simulate('click');
|
|
||||||
|
|
||||||
expect(props.setFirstTimeFlowType.calledOnce).toStrictEqual(true);
|
expect(props.setFirstTimeFlowType.calledOnce).toStrictEqual(true);
|
||||||
expect(props.setFirstTimeFlowType.getCall(0).args[0]).toStrictEqual(
|
expect(props.setFirstTimeFlowType.getCall(0).args[0]).toStrictEqual(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user