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

Fix/remove skipped test cases #477

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
},
},
};
25 changes: 14 additions & 11 deletions __tests__/AuthScreen-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ 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 { customRenderWithProvider } from '../src/utils/tests';
import { Linking } from 'react-native';

jest.mock('react-redux', () => {
return {
Expand All @@ -13,22 +14,24 @@ 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', () => {
customRenderWithProvider(AuthScreen);
screen.getByText(/welcome to/i);
screen.getByText(/real dev squad/i);
});

it.skip('Clicking on Sign in with Github shows a toast', async () => {
render(
<>
<AuthScreen />
<Toast />
</>,
);
it('Clicking on Sign in with Github opens browser', async () => {
customRenderWithProvider(AuthScreen);

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);
joyguptaa marked this conversation as resolved.
Show resolved Hide resolved
});

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 @@ -8,7 +8,7 @@

// Short Term Goals component test

test.skip('flatlist does not exist on initial render', () => {

Check warning on line 11 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test

Check warning on line 11 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test
const { queryByTestId, getByTestId } = render(<ShortGoalsComponent />);
expect(queryByTestId('flatlist')).toBeNull();
expect(getByTestId('arrowBtnIcon').props.style).toStrictEqual({
Expand All @@ -18,7 +18,7 @@
});
});

test.skip('flatlist exists when we click on the arrow button', () => {

Check warning on line 21 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test

Check warning on line 21 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test
const { queryByTestId, getByTestId } = render(<ShortGoalsComponent />);
fireEvent.press(getByTestId('arrowBtn'));
expect(queryByTestId('flatlist')).toBeTruthy();
Expand All @@ -32,12 +32,12 @@

// Create Goal component test

test.skip('roadmap type does not exist on initial render', () => {

Check warning on line 35 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test

Check warning on line 35 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test
const { queryByTestId } = render(<DurationDropdown />);
expect(queryByTestId('longTermRoadmap')).toBeNull();
});

test.skip('roadmap type exists when use select duration as long term and stays undefined initally', () => {

Check warning on line 40 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test

Check warning on line 40 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test
const { getByTestId } = render(<DurationDropdown />);
fireEvent.press(getByTestId('roadmapType'));
expect(getByTestId('roadmapType').props.value).toStrictEqual(undefined);
Expand All @@ -45,7 +45,7 @@

// Floating Button test

test.skip('floating actions exists when we click floating button', () => {

Check warning on line 48 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test

Check warning on line 48 in __tests__/Component-test.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Skipped test
const { queryByTestId, getByTestId } = render(<FloatingButton />);
fireEvent.press(getByTestId('floatingButton'));
expect(queryByTestId('floatingButton')).toBeTruthy();
Expand Down Expand Up @@ -86,7 +86,7 @@
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
68 changes: 59 additions & 9 deletions __tests__/Goals/components/Create-Goals-test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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 +27,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 +65,57 @@ 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) }],
);
});

// @ts-ignore
abhisheksharmayt marked this conversation as resolved.
Show resolved Hide resolved
spyAlert.mock.calls[0][2][0].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);
33 changes: 33 additions & 0 deletions src/utils/tests/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { Provider as StoreProvider } from 'react-redux';
import { AuthProvider } from '../../context/AuthContext';
import { store } from '../../../App';
import {
render,
RenderOptions,
RenderResult,
} from '@testing-library/react-native';
import Toast from 'react-native-toast-message';

export function customRenderWithProvider(
Component: React.FC<unknown>,
renderOptions?: RenderOptions,
): RenderResult {
return render(
<StoreProvider store={store}>
<AuthProvider>
<Component />
</AuthProvider>
</StoreProvider>,
renderOptions,
);
}

export const withToast = (Component: React.FC<unknown>) => {
return () => (
<>
<Component />
<Toast />
</>
);
};
Loading