Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(js-ts): Convert app/components/Views/OnboardingSuccess/index.test.js to TypeScript #11397

Closed
wants to merge 11 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Change these at any time.
accessibilityRole="button"
accessible={true}
activeOpacity={1}
onPress={[MockFunction]}
onPressIn={[Function]}
onPressOut={[Function]}
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import React from 'react';
// Internal dependencies.
import OnboardingSuccess from './';
import renderWithProvider from '../../../util/test/renderWithProvider';
import { useNavigation } from '@react-navigation/native';
import { useSelector } from 'react-redux';
import { selectProviderConfig } from '../../../selectors/networkController';
import { selectProviderConfig, ProviderConfig } from '../../../selectors/networkController';

jest.mock('@react-navigation/native', () => {
const actualReactNavigation = jest.requireActual('@react-navigation/native');
Expand All @@ -29,19 +28,34 @@ jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}));

const mockProviderConfig = {
const mockProviderConfig: ProviderConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ProviderConfig from app/selectors/networkController.ts instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the ProviderConfig interface defined in this file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cal-L done

type: 'mainnet',
chainId: '1',
chainId: '0x1',
ticker: '',
rpcUrl: '',
nickname: undefined
};

describe('OnboardingSuccess', () => {
it('should render correctly', () => {
useSelector.mockImplementation((selector) => {
(useSelector as jest.Mock).mockImplementation((selector: typeof selectProviderConfig) => {
if (selector === selectProviderConfig) return mockProviderConfig;
});
const { toJSON } = renderWithProvider(
<OnboardingSuccess navigation={useNavigation()} />,
const mockOnDone = jest.fn();
const { getByTestId, toJSON } = renderWithProvider(
<OnboardingSuccess onDone={mockOnDone} backedUpSRP={false} noSRP={false} />,
);

// Snapshot test
expect(toJSON()).toMatchSnapshot();

const doneButton = getByTestId('onboarding-success-done-button');
expect(doneButton).toBeTruthy();

// Simulate button press
doneButton.props.onPress();

// Check if mockOnDone was called
expect(mockOnDone).toHaveBeenCalledTimes(1);
});
});
Loading