Files
iNaturalistReactNative/tests/unit/components/Projects/Projects.test.js
Amanda Bullington 0c4b9a5158 Fixes for API calls, useCurrentUser hook, api token not being fetched (#309)
* Random code cleanup

* Simplify useCurrentUser hook; only fetch messages if current user; closes #272

* Fix padding around login prompt button

* Code cleanup

* Fix projects; display search and tabs separately

* Remove log
2022-12-21 13:35:41 -08:00

42 lines
1.2 KiB
JavaScript

import { fireEvent } from "@testing-library/react-native";
import Projects from "components/Projects/Projects";
import React from "react";
import factory from "../../../factory";
import { renderComponent } from "../../../helpers/render";
const mockedNavigate = jest.fn( );
const mockProject = factory( "RemoteProject" );
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: [mockProject]
} )
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useNavigation: ( ) => ( {
navigate: mockedNavigate
} )
};
} );
test( "displays project search results", ( ) => {
const { getByTestId, getByText } = renderComponent( <Projects /> );
const input = getByTestId( "ProjectSearch.input" );
fireEvent.changeText( input, "butterflies" );
expect( getByText( mockProject.title ) ).toBeTruthy( );
expect( getByTestId( `Project.${mockProject.id}.photo` ).props.source )
.toStrictEqual( { uri: mockProject.icon } );
fireEvent.press( getByTestId( `Project.${mockProject.id}` ) );
expect( mockedNavigate ).toHaveBeenCalledWith( "ProjectDetails", {
id: mockProject.id
} );
} );