Skip to content

Commit

Permalink
refactor: removed render abstraction and created a wrapper provider
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisheksharmayt committed Nov 6, 2024
1 parent eb55252 commit cccf67c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
14 changes: 11 additions & 3 deletions __tests__/AuthScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import AuthScreen from '../src/screens/AuthScreen/AuthScreen';
import Strings from '../src/i18n/en';
import { Provider } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';
import { customRenderWithProvider } from '../src/utils/tests';
import { Linking } from 'react-native';
import AuthApis from '../src/constants/apiConstant/AuthApi';
import ProviderWrapper from './ProviderWrapper';

jest.mock('react-redux', () => {
return {
Expand All @@ -22,7 +22,11 @@ jest.mock('react-native/Libraries/Linking/Linking', () => ({
}));

it('AuthScreen is rendered', () => {
customRenderWithProvider(AuthScreen);
render(
<ProviderWrapper>
<AuthScreen />
</ProviderWrapper>
);
screen.getByText(/welcome to/i);
screen.getByText(/real dev squad/i);
});
Expand All @@ -42,7 +46,11 @@ it('Clicking on Sign in with Github opens browser', async () => {
const baseUrl = AuthApis.GITHUB_AUTH_API;
const githubUrl = mockBuildUrl(baseUrl, queryParams);

customRenderWithProvider(AuthScreen);
render(
<ProviderWrapper>
<AuthScreen />
</ProviderWrapper>
);

const githubSignInBtn = screen.getByText(Strings.SIGN_IN_BUTTON_TEXT);
fireEvent.press(githubSignInBtn);
Expand Down
18 changes: 18 additions & 0 deletions __tests__/ProviderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { ReactNode } from 'react';
import { Provider as StoreProvider } from 'react-redux';
import { AuthProvider } from '../src/context/AuthContext';
import { store } from '../App';

interface ProviderWrapperProps {
children: ReactNode;
}

const ProviderWrapper: React.FC<ProviderWrapperProps> = ({ children }) => (
<StoreProvider store={store}>
<AuthProvider>
<>{children}</>
</AuthProvider>
</StoreProvider>
);

export default ProviderWrapper;
33 changes: 0 additions & 33 deletions src/utils/tests/index.tsx

This file was deleted.

0 comments on commit cccf67c

Please sign in to comment.