Skip to content

Commit

Permalink
test: added one more test for github login.
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisheksharmayt committed Nov 6, 2024
1 parent 18a38fe commit eb55252
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __tests__/AuthScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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';

jest.mock('react-redux', () => {
return {
Expand All @@ -27,11 +28,26 @@ it('AuthScreen is rendered', () => {
});

it('Clicking on Sign in with Github opens browser', async () => {
const mockBuildUrl = (url: string, params: { [key: string]: string }) => {
const queryString = Object.keys(params)
.map((key) => `${key}=${params[key]}`)
.join('&');

return `${url}?${queryString}`;
};
const queryParams = {
sourceUtm: 'rds-mobile-app',
redirectURL: 'https://realdevsquad.com/',
};
const baseUrl = AuthApis.GITHUB_AUTH_API;
const githubUrl = mockBuildUrl(baseUrl, queryParams);

customRenderWithProvider(AuthScreen);

const githubSignInBtn = screen.getByText(Strings.SIGN_IN_BUTTON_TEXT);
fireEvent.press(githubSignInBtn);
expect(Linking.openURL).toHaveBeenCalledTimes(1);
expect(Linking.openURL).toHaveBeenCalledWith(githubUrl);
});

describe('AuthScreen', () => {
Expand Down

0 comments on commit eb55252

Please sign in to comment.