Skip to content

Commit

Permalink
Fix/remove skipped test cases (#477)
Browse files Browse the repository at this point in the history
* test: created provider wrapper

* test: created provider wrapper

* test: create goal test updated

* test(AuthScreen): updated "sign with github" test case

* test: updated card component skipped test case

* test: created provider wrapper

* test: create goal test updated

* test(AuthScreen): updated "sign with github" test case

* test: updated card component skipped test case

* refactor: removed ts-ignore and update onPress call

* refactor: updated variable name to improve readability

* test: added one more test for github login.

* refactor: removed render abstraction and created a wrapper provider

* refactor: updated ProviderWrapper location

* test: fix removed fragment
  • Loading branch information
abhisheksharmayt authored Nov 9, 2024
1 parent b81abab commit e0a24c8
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 18 deletions.
84 changes: 84 additions & 0 deletions __mocks__/mockData/Goals/mockData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
export const mockUsersData = [
{
incompleteUserDetails: false,
discordJoinedAt: '2023-05-18T08:42:15.623000+00:00',
discordId: '892345671234567890',
linkedin_id: 'user7891',
yoe: 3,
picture: {
publicId: 'profile/9kLmxpQw2YtRvCcc12AB/xyz9abcdwxyzdef123',
url: 'https://res.cloudinary.com/realdevsquad/image/upload/v1701234567/profile/9kLmxpQw2YtRvCcc12AB/xyz9abcdwxyzdef123.jpg',
},
github_created_at: 1612345678000,
github_display_name: 'user7891',
github_id: 'dev7891',
id: '9kLmxpQw2YtRvCcc12AB',
twitter_id: 'coder7891',
status: 'active',
github_user_id: '67891234',
profileURL: 'https://my-profile-service-yhg4.onrender.com',
website: 'https://user7891.dev',
company: 'TechStartup XYZ',
designation: 'Backend Developer',
instagram_id: 'dev.7891',
profileStatus: 'ACTIVE',
roles: {
archived: false,
in_discord: true,
member: true,
},
username: 'dev-user-7891',
last_name: 'user7891',
first_name: 'test user',
updated_at: 1729349563939,
created_at: 1729349563328,
},
{
incompleteUserDetails: false,
discordJoinedAt: '2022-09-30T15:23:44.789000+00:00',
discordId: '123456789012345678',
linkedin_id: 'user4567',
yoe: 1,
picture: {
publicId: 'profile/8jKnWpLv1XsQbBaa45CD/abc8xyzawxyzabc890',
url: 'https://res.cloudinary.com/realdevsquad/image/upload/v1698765432/profile/8jKnWpLv1XsQbBaa45CD/abc8xyzawxyzabc890.jpg',
},
github_created_at: 1598765432000,
github_display_name: 'user4567',
github_id: 'dev4567',
id: '8jKnWpLv1XsQbBaa45CD',
twitter_id: 'coder4567',
status: 'active',
github_user_id: '34567891',
profileURL: 'https://my-profile-service-yhg4.onrender.com',
website: 'https://user4567.tech',
company: 'None',
designation: 'Junior Developer',
instagram_id: '',
profileStatus: 'BLOCKED',
roles: {
archived: false,
in_discord: true,
member: false,
},
username: 'dev-user-4567',
last_name: 'user4567',
first_name: 'dev',
updated_at: 1729349599999,
created_at: 1729349580000,
},
];

export const mockGoalData = {
data: {
type: 'Goal',
attributes: {
title: 'test title',
description: 'test description',
created_by: 'testUserId',
assigned_to: 'testAssignedUserId',
ends_on: '2026-01-01T00:00:00Z',
assigned_by: 'testAssignedByUserId',
},
},
};
43 changes: 35 additions & 8 deletions __tests__/AuthScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';
import { screen, render, fireEvent } from '@testing-library/react-native';
import AuthScreen from '../src/screens/AuthScreen/AuthScreen';
import Strings from '../src/i18n/en';
import { Toast } from 'react-native-toast-message/lib/src/Toast';
import { Provider } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';
import { Linking } from 'react-native';
import AuthApis from '../src/constants/apiConstant/AuthApi';
import ProviderWrapper from '../src/utils/tests/ProviderWrapper';

jest.mock('react-redux', () => {
return {
Expand All @@ -13,22 +15,47 @@ jest.mock('react-redux', () => {
};
});

it.skip('AuthScreen is rendered', () => {
render(<AuthScreen />);
jest.mock('react-native/Libraries/Linking/Linking', () => ({
openURL: jest.fn(() => Promise.resolve('mockResolve')),
getInitialURL: jest.fn(() => Promise.resolve('mockResolve')),
addEventListener: jest.fn(),
}));

it('AuthScreen is rendered', () => {
render(
<ProviderWrapper>
<AuthScreen />
</ProviderWrapper>,
);
screen.getByText(/welcome to/i);
screen.getByText(/real dev squad/i);
});

it.skip('Clicking on Sign in with Github shows a toast', async () => {
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);

render(
<>
<ProviderWrapper>
<AuthScreen />
<Toast />
</>,
</ProviderWrapper>,
);

const githubSignInBtn = screen.getByText(Strings.SIGN_IN_BUTTON_TEXT);
fireEvent.press(githubSignInBtn);
screen.getByText(/Sign in with GitHub coming soon/i);
expect(Linking.openURL).toHaveBeenCalledTimes(1);
expect(Linking.openURL).toHaveBeenCalledWith(githubUrl);
});

describe('AuthScreen', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/Component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const DATA = {
assigned_by: 'admin',
};

test.skip('setTimeout called which calls other two functions remove and changecard', () => {
test('setTimeout called which calls other two functions remove and changecard', () => {
const { getByTestId } = render(
<Card
item={DATA}
Expand Down
72 changes: 63 additions & 9 deletions __tests__/Goals/components/Create-Goals-test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import MembersPage from '../../../src/screens/MemberScreen/MembersPage';
import { render, fireEvent, waitFor } from '@testing-library/react-native';
import CreateGoals from '../../../src/components/ToDoComponent/SettingGoals/CreateGoals';
import { Alert } from 'react-native';
import {
mockGoalData,
mockUsersData,
} from '../../../__mocks__/mockData/Goals/mockData';

const axios = require('axios');
jest.mock('axios');
jest.mock('react-native-gesture-handler', () => {});

describe('MainScreen', () => {
Expand All @@ -24,6 +30,9 @@ describe('MainScreen', () => {

test('navigates to MemberScreen when "Assigned To" is pressed', async () => {
const navigateMock = jest.fn();
axios.get.mockResolvedValue({
data: { users: mockUsersData, message: 'Users returned successfully!' },
});
const { getByTestId, findByTestId } = render(
<CreateGoals navigation={{ navigate: navigateMock }} />,
);
Expand Down Expand Up @@ -59,13 +68,58 @@ describe('MainScreen', () => {
expect(userContainer).toBeNull();
});

test.skip('navigates to FormScreen when "Create" button is pressed', () => {
const navigateMock = jest.fn();
const { getByText } = render(
<MembersPage navigation={{ push: navigateMock }} />,
test('navigates to Goal Screen when "Create Goal" button is pressed', async () => {
const spyAlert = jest.spyOn(Alert, 'alert');
axios.get.mockResolvedValue({
data: { users: mockUsersData, message: 'Users returned successfully!' },
});
axios.post.mockResolvedValue(mockGoalData);

const {
getByTestId,
getByPlaceholderText,
getByText,
findByTestId,
getAllByText,
} = render(<CreateGoals navigation={navigationProp} />);

const createGoalButton = getByText(/create goal/i);
const titleInput = getByPlaceholderText(
'Enter title max of 50 characters.',
);
const createButton = getByText('Create');
fireEvent.press(createButton);
expect(navigateMock).toHaveBeenCalledWith('Form screen');
const descriptionInput = getByPlaceholderText('Enter max 200 characters.');
const selectUserButton = getByTestId('dropdown');

fireEvent.press(selectUserButton);
const userContainer = await findByTestId('user-container');
expect(userContainer).toBeTruthy();

const userInput = getByPlaceholderText('Search User');
await waitFor(() => {
fireEvent.changeText(userInput, 'test user');
});
const userItems = getAllByText(/test user/i);
expect(userItems).toBeTruthy();

await waitFor(() => {
fireEvent.press(userItems[0]);
fireEvent.changeText(titleInput, 'Test Goal');
fireEvent.changeText(descriptionInput, 'Test Description');
});

fireEvent.press(createGoalButton);

await waitFor(() => {
expect(Alert.alert).toHaveBeenCalledWith(
'Success',
`Task has been created and assigned to test user`,
[{ text: 'OK', onPress: expect.any(Function) }],
);
});

const alertMockCall = spyAlert.mock.calls?.[0]?.[2]?.[0];
alertMockCall?.onPress!();

expect(navigationProp.navigate).toHaveBeenCalledWith('GoalsScreen');
});
});
3 changes: 3 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { jest } from '@jest/globals';
import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js';


require('react-native-reanimated/src/jestUtils').setUpTests();
jest.mock('react-native-device-info', () => mockRNDeviceInfo);
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('@react-native-community/netinfo', () => mockRNCNetInfo);
16 changes: 16 additions & 0 deletions src/utils/tests/ProviderWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Provider as StoreProvider } from 'react-redux';
import { AuthProvider } from '../../context/AuthContext';
import { store } from '../../../App';

interface ProviderWrapperProps {
children: JSX.Element;
}

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

export default ProviderWrapper;

0 comments on commit e0a24c8

Please sign in to comment.