Skip to content

Commit

Permalink
test: adjuste methods that cause bugs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-prud committed Oct 8, 2023
1 parent 402d07e commit 4318767
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function Avatar({size = 32, user}: AvatarProps) {
backgroundColor="gray1"
justifyContent="center"
alignItems="center"
testID="avatar-component" >
<Box borderRadius="s32" overflow="hidden" >
testID="avatar-component">
<Box borderRadius="s32" overflow="hidden">
<Image
source={{
uri: avatar,
Expand Down
2 changes: 1 addition & 1 deletion src/screens/app/HomeScreen/__tests__/HomeScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {renderCustomScreenComponent} from '@tests';
import {HomeHeader} from '../components';

describe('HomeScreen', () => {
it.skip('should render HomeHeader when not isLoading and no error', () => {
it('should render HomeHeader when not isLoading and no error', () => {
const {getByTestId} = renderCustomScreenComponent({
customHeader: <HomeHeader />,
children: <></>,
Expand Down
4 changes: 2 additions & 2 deletions src/screens/app/HomeScreen/__tests__/useHomeScreen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {act, renderHook, waitFor} from '@tests';
import {useHomeScreen} from '../useHomeScreen';

describe('useHomeScreen', () => {
it.skip("should create 'homeContentRef' when hook is called", () => {
it("should create 'homeContentRef' when hook is called", () => {
const {result} = renderHook(() => useHomeScreen());

const {homeContentRef} = result.current;

expect(homeContentRef.current).toBeDefined();
});

it.skip("should retrieve and update values from 'usePostList'", async () => {
it("should retrieve and update values from 'usePostList'", async () => {
const {result} = renderHook(() => useHomeScreen());

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ afterEach(() => {
});

describe('HomeHeader', () => {
it.skip('should render the component', () => {
it('should render the component', () => {
const {getByTestId} = render(<HomeHeader />);

expect(getByTestId('home-header')).toBeTruthy();
});

it.skip("should navigate to 'ProfileScreen' when avatar is pressabled", () => {
it("should navigate to 'ProfileScreen' when avatar is pressabled", () => {
const {getByTestId} = render(<HomeHeader />);

const avatarHeaderContainer = getByTestId('avatar-header-container');
Expand All @@ -26,7 +26,7 @@ describe('HomeHeader', () => {
expect(mockedNavigate).toHaveBeenCalledTimes(1);
});

it.skip("should navigate to 'SearchScreen' when search icon is pressabled", () => {
it("should navigate to 'SearchScreen' when search icon is pressabled", () => {
const {getByTestId} = render(<HomeHeader />);

const searchHeaderContainer = getByTestId('search-header-container');
Expand Down
4 changes: 1 addition & 3 deletions src/services/UserService/__tests__/UserService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {UserService} from '../UserService';
describe('UserService', () => {
describe('Me method', () => {
it('should be able to return the user data', async () => {
const {me} = UserService();

const userResponse = await me();
const userResponse = await UserService().me();

expect(userResponse).toEqual(userResponse);
});
Expand Down
10 changes: 5 additions & 5 deletions src/useCases/Post/usePostList/__tests__/usePostList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import {waitFor, renderHook, act, mockPostList} from '@tests';
import {usePostList} from '../usePostList';

describe('UsePostList', () => {
it.skip('should seek postList and update correct states', async () => {
it('should seek postList and update correct states', async () => {
const {result} = renderHook(() => usePostList());

const fetchDataMock = jest.spyOn(result.current, 'fetchData');

await act(() => {
result.current.fetchData();
await act(async () => {
await result.current.fetchData();
});

await waitFor(() => {
expect(fetchDataMock).toHaveBeenCalledTimes(1);
});

const {postList, isLoading, error} = result.current;

expect(fetchDataMock).toHaveBeenCalledTimes(1);
expect(postList).toEqual(mockPostList);
expect(isLoading).toBe(false);
expect(error).toBe(false);
});

it.skip('should refetch data when call refetchData', async () => {
it('should refetch data when call refetchData', async () => {
const {result} = renderHook(() => usePostList());

const refetchDataMock = jest.spyOn(result.current, 'refetch');
Expand Down
6 changes: 3 additions & 3 deletions src/useCases/Post/usePostList/usePostList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {PostService} from '@services';
import {PostProps} from '@types';

export function usePostList() {
const {listAll} = PostService();
// const {listAll} = PostService();

const [postList, setPostList] = useState<PostProps[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(false);

const fetchData = useCallback(async () => {
try {
const response = await listAll();
const response = await PostService().listAll();

setPostList(response);
} catch (erro) {
Expand All @@ -22,7 +22,7 @@ export function usePostList() {
} finally {
setIsLoading(false);
}
}, [listAll]);
}, []);

useEffect(() => {
fetchData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {renderHook, act, waitFor, mockUser} from '@tests';
import {useGetUserData} from '../useGetUserData';

describe('UseGetUserData', () => {
it.skip('should seek user data and update correct states', async () => {
it('should seek user data and update correct states', async () => {
const {result} = renderHook(() => useGetUserData());

await act(async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/useCases/User/useGetUserData/useGetUserData.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {useCallback, useEffect, useState} from 'react';

import {UserService} from '@services';
import UserService from '../../../services/UserService/UserService';

export function useGetUserData() {
const {me} = UserService();
// const {me} = UserService();

const [userData, setUserData] = useState({} as any);
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -13,7 +13,7 @@ export function useGetUserData() {
try {
setIsLoading(true);

const response = await me();
const response = await UserService.me();

setUserData(response);
} catch (erro) {
Expand All @@ -23,7 +23,7 @@ export function useGetUserData() {
} finally {
setIsLoading(false);
}
}, [me]);
}, []);

useEffect(() => {
getUserData();
Expand Down

0 comments on commit 4318767

Please sign in to comment.