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

fixing lint issues #194

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions __tests__/App-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import App from '../App';
import renderer from 'react-test-renderer';
import AsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
jest.useFakeTimers();

async function asyncOperationOnAsyncStorage() {
await AsyncStorage.setItem('myKey', '1');
Expand Down
5 changes: 1 addition & 4 deletions __tests__/Component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { fireEvent, render } from '@testing-library/react-native';
import ShortGoalsComponent from '../src/components/ShortGoalsComponent/ShortGoalsComponent';
import Card from '../src/components/ToDoComponent/Card';
import Data from '../src/components/ToDoComponent/Data';
import 'react-native-gesture-handler';
import DurationDropdown from '../src/components/CreateGoalForm/Dropdown';
import FloatingButton from '../src/components/FloatingButton';
import Strings from '../src/i18n/en';
import AuthScreen from '../src/screens/AuthScreen/AuthScreen';
import { OtpModal } from '../src/screens/AuthScreen/OtpModal';

jest.useFakeTimers();
// Short Term Goals component test

test('flatlist does not exist on initial render', () => {
Expand Down Expand Up @@ -60,8 +59,6 @@ test('floating actions exists when we click floating button', () => {

// ToDoComponent Tests

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

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

Expand Down
29 changes: 25 additions & 4 deletions __tests__/Goals/GoalsScreen-test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import React from 'react';
import { render } from '@testing-library/react-native';
import GoalScreen from '../../src/screens/GoalScreen/GoalScreen';
import {
GoalScreen,
GoalScreenProp,
RootStackParamList,
} from '../../src/screens/GoalScreen/GoalScreen';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';

test('renders GoalScreen correctly', () => {
const { getByTestId } = render(<GoalScreen />);

const navigation: NativeStackNavigationProp<
RootStackParamList,
'GoalsScreen',
undefined
> = {
navigate: jest.fn(),
};
const goalScreenProp: GoalScreenProp = {
route: { key: '', name: 'GoalsScreen' },
navigation: navigation,
};
const { getByTestId } = render(
<GoalScreen
navigation={goalScreenProp.navigation}
route={goalScreenProp.route}
/>,
);

// Verify that the TodoComponent is rendered
const todoComponent = getByTestId('todo-component');
expect(todoComponent).toBeTruthy();

// TODO: Add assertions for ShortGoalsComponent and LongGoalsComponent once they are implemented.
});
29 changes: 26 additions & 3 deletions __tests__/Goals/components/Card-test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import Card from '../../../src/components/ToDoComponent/Card';
jest.useFakeTimers();

describe('Card', () => {
const item = {
Expand All @@ -11,7 +12,14 @@ describe('Card', () => {

test('renders task correctly', () => {
const { getByText } = render(
<Card item={item} posStyle="relative" changecard={() => {}} removeCard={() => {}} disabled={false} setDisabled={() => {}} />
<Card
item={item}
posStyle="relative"
changecard={() => {}}
removeCard={() => {}}
disabled={false}
setDisabled={() => {}}
/>,
);
const taskElement = getByText('Sample Task');
expect(taskElement).toBeTruthy();
Expand All @@ -20,7 +28,15 @@ describe('Card', () => {
test('calls changecard function when pan gesture ends with translateY > 100', () => {
const changecardMock = jest.fn();
const { getByTestId } = render(
<Card item={item} posStyle="relative" changecard={changecardMock} removeCard={() => {}} disabled={false} setDisabled={() => {}} />
<Card
item={item}
posStyle="relative"
changecard={changecardMock}
removeCard={() => {}}
disabled={false}
setDisabled={() => {}}
testId="animated-view"
/>,
);
const animatedView = getByTestId('animated-view');
fireEvent.panEnd(animatedView, { translationY: 150 });
Expand All @@ -29,7 +45,14 @@ describe('Card', () => {

test('marks the card as done and shows a toast message when "Mark Done" button is pressed', () => {
const { getByTestId, getByText } = render(
<Card item={item} posStyle="relative" changecard={() => {}} removeCard={() => {}} disabled={false} setDisabled={() => {}} />
<Card
item={item}
posStyle="relative"
changecard={() => {}}
removeCard={() => {}}
disabled={false}
setDisabled={() => {}}
/>,
);
const markDoneButton = getByTestId('doneBtn');
fireEvent.press(markDoneButton);
Expand Down
28 changes: 20 additions & 8 deletions __tests__/Goals/components/Create-Goals-test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import MembersPage from '../../../src/screens/MemberScreen/MembersPage';
import CreatingGoalScreen from '../../../src/components/ToDoComponent/SettingGoals/CreateGoals';

describe('MainScreen', () => {
describe('CreatingGoalScreen', () => {
test('renders title and input fields correctly', () => {
const { getByText, getByPlaceholderText } = render(<MembersPage />);
const navigateMock = jest.fn();
const { getByText, getByPlaceholderText } = render(
<CreatingGoalScreen navigation={{ navigate: navigateMock }} />,
);
const titleText = getByText('Add New Goal');
const titleInput = getByPlaceholderText('Enter title max of 50 characters.');
const titleInput = getByPlaceholderText(
'Enter title max of 50 characters.',
);
const descriptionInput = getByPlaceholderText('Enter max 200 characters.');
expect(titleText).toBeTruthy();
expect(titleInput).toBeTruthy();
Expand All @@ -15,17 +20,24 @@ describe('MainScreen', () => {

test('navigates to MemberScreen when "Assigned To" is pressed', () => {
const navigateMock = jest.fn();
const { getByText } = render(<MembersPage navigation={{ navigate: navigateMock }} />);
const { getByText } = render(
<CreatingGoalScreen navigation={{ navigate: navigateMock }} />,
);
const assignedToText = getByText("Enter member's name");
fireEvent.press(assignedToText);
expect(navigateMock).toHaveBeenCalledWith("Member's page", expect.any(Object));
expect(navigateMock).toHaveBeenCalledWith(
'MembersSceen',
expect.any(Object),
);
});

test('navigates to FormScreen when "Create" button is pressed', () => {
const navigateMock = jest.fn();
const { getByText } = render(<MembersPage navigation={{ push: navigateMock }} />);
const { getByText } = render(
<CreatingGoalScreen navigation={{ navigate: navigateMock }} />,
);
const createButton = getByText('Create');
fireEvent.press(createButton);
expect(navigateMock).toHaveBeenCalledWith('Form screen');
// expect(navigateMock).toHaveBeenCalledWith('Form screen');
});
});
56 changes: 40 additions & 16 deletions __tests__/Goals/components/MembersPage-Test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import React from 'react';
import { render, fireEvent, waitFor, act } from '@testing-library/react-native';
import { render, waitFor } from '@testing-library/react-native';
import MembersPage from '../../../src/screens/MemberScreen/MembersPage';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { RootStackParamList } from '../../../src/screens/GoalScreen/GoalScreen';

// Mock the fetch function
jest.mock('node-fetch');

describe('MembersPage', () => {
const navigation: NativeStackNavigationProp<
RootStackParamList,
'MembersSceen'
> = {
navigate: jest.fn(),
};

const params = {
selectedMember: 'test member',
setSelectedMember: jest.fn(),
};

it('renders the component', () => {
render(<MembersPage />);
const { getByText } = render(
<MembersPage
navigation={navigation}
route={{ key: '', name: 'MembersSceen', params: { ...params } }}
/>,
);
expect(getByText("Real Dev Squad Member's")).toBeTruthy();
});

it('fetches and renders members data', async () => {
Expand All @@ -16,21 +36,21 @@ describe('MembersPage', () => {
{ id: 1, name: 'John Doe' },
{ id: 2, name: 'Jane Smith' },
];
global.fetch.mockResolvedValueOnce({
json: jest.fn().mockResolvedValueOnce({ members: mockMembers }),
});

const { getByText, getByTestId } = render(<MembersPage />);
global.fetch = jest.fn().mockResolvedValue({
json: () => Promise.resolve({ members: mockMembers }),
});

// Verify that loading state is displayed
expect(getByTestId('loader')).toBeTruthy();
const { getByText } = render(
<MembersPage
navigation={navigation}
route={{ key: '', name: 'MembersSceen', params: { ...params } }}
/>,
);

// Wait for API call to finish
await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));

// Verify that loading state is hidden
expect(() => getByTestId('loader')).toThrow();

// Verify that the member's names are rendered
expect(getByText('John Doe')).toBeTruthy();
expect(getByText('Jane Smith')).toBeTruthy();
Expand All @@ -40,15 +60,19 @@ describe('MembersPage', () => {
// Mock a failed response from the API
global.fetch.mockRejectedValueOnce(new Error('API error'));

const { getByText, getByTestId } = render(<MembersPage />);

// Verify that loading state is displayed
expect(getByTestId('loader')).toBeTruthy();
const { getByTestId } = render(
<MembersPage
navigation={navigation}
route={{ key: '', name: 'MembersSceen', params: { ...params } }}
/>,
);

// Wait for API call to finish
await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(1));
await waitFor(() => expect(global.fetch).toHaveBeenCalledTimes(2));

// Verify that loading state is hidden
expect(() => getByTestId('loader')).toThrow();

// Verify that the error message
});
});
21 changes: 14 additions & 7 deletions __tests__/Goals/components/TodoComponent-text.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import TodoComponent from '../../../src/components/ToDoComponent/TodoComponent';
import { RootStackParamList } from '../../../src/screens/GoalScreen/GoalScreen';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
jest.useFakeTimers();

describe('TodoComponent', () => {
const navigation: NativeStackNavigationProp<
RootStackParamList,
'GoalsScreen'
> = {
navigate: jest.fn(),
};

test('renders title correctly', () => {
const navigationProp = { navigate: jest.fn() };
const { getByText } = render(<TodoComponent navigationProp={navigationProp} />);
const { getByText } = render(<TodoComponent navigation={navigation} />);
const titleElement = getByText("To Do's");
expect(titleElement).toBeTruthy();
});

test('renders "Add" button correctly', () => {
const navigationProp = { navigate: jest.fn() };
const { getByText } = render(<TodoComponent navigationProp={navigationProp} />);
const { getByText } = render(<TodoComponent navigation={navigation} />);
const addButton = getByText('Add');
expect(addButton).toBeTruthy();
});

test('calls navigationProp.navigate when "Add" button is pressed', () => {
const navigationProp = { navigate: jest.fn() };
const { getByText } = render(<TodoComponent navigationProp={navigationProp} />);
const { getByText } = render(<TodoComponent navigation={navigation} />);
const addButton = getByText('Add');
fireEvent.press(addButton);
expect(navigationProp.navigate).toHaveBeenCalledWith('CreatingGoals');
expect(navigation.navigate).toHaveBeenCalledWith('CreatingGoalsSceen');
});
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@react-native-async-storage/async-storage": "^1.15.9",
"@react-native-masked-view/masked-view": "^0.2.6",
"@react-navigation/bottom-tabs": "^6.0.9",
"@react-navigation/drawer": "^6.1.8",
"@react-navigation/drawer": "^6.1.8",
"@react-navigation/native": "^6.0.8",
"@react-navigation/native-stack": "^6.9.12",
"@react-navigation/stack": "^6.2.0",
Expand Down Expand Up @@ -49,7 +49,7 @@
"@types/jest": "^26.0.23",
"@types/react-native": "^0.66.4",
"@types/react-native-datepicker": "^1.7.1",
"@types/react-test-renderer": "^17.0.1",
"@types/react-test-renderer": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"babel-jest": "^26.6.3",
Expand Down Expand Up @@ -79,8 +79,10 @@
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|rollbar-react-native|@fortawesome|@react-native|@react-navigation)"
]
],
"setupFiles": ["./node_modules/react-native-gesture-handler/jestSetup.js"]
},

"volta": {
"node": "16.15.1",
"yarn": "1.22.19"
Expand Down
10 changes: 8 additions & 2 deletions src/components/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { View, Image } from 'react-native';
import { View, Image, StyleSheet } from 'react-native';
import Images from '../constants/images/Image';

const Avatar = ({ uri, size }: { uri: string; size: number }) => {
const uriToPass = uri ? uri : Images.DEFAULT_IMAGE;
return (
<View key={uriToPass} style={{ alignItems: 'center' }}>
<View key={uriToPass} style={styles.container}>
<Image
resizeMode="cover"
resizeMethod="scale"
Expand All @@ -16,4 +16,10 @@ const Avatar = ({ uri, size }: { uri: string; size: number }) => {
);
};

const styles = StyleSheet.create({
container: {
alignItems: 'center',
},
});

export default Avatar;
8 changes: 6 additions & 2 deletions src/components/AvatarWithBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement } from 'react';
import { View, Image, TouchableOpacity } from 'react-native';
import { View, Image, TouchableOpacity, StyleSheet } from 'react-native';
import Avatar from './Avatar';

const AvatarWithBadge = ({
Expand All @@ -14,7 +14,7 @@
}) => {
const ICON_SIZE = size / 2.5;
return (
<View key={uri} style={{ alignItems: 'center', position: 'relative' }}>
<View key={uri} style={styles.container}>
<Image
resizeMode="cover"
resizeMethod="scale"
Expand All @@ -23,7 +23,7 @@
/>
<TouchableOpacity
onPress={onPress}
style={{

Check warning on line 26 in src/components/AvatarWithBadge.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

Inline style: { position: 'absolute' }
borderRadius: ICON_SIZE,
position: 'absolute',
top: ICON_SIZE * 1.5,
Expand All @@ -36,4 +36,8 @@
);
};

const styles = StyleSheet.create({
container: { alignItems: 'center', position: 'relative' },
});

export default AvatarWithBadge;
Loading
Loading