mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-20 23:10:53 -04:00
* Fetch user from server, set locale in realm and change language with i18next * Added some Spanish translations so I can see localization working * config QueryClient with `cacheTime: Infinity` to deal with "Jest did not exit" errors Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 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" );
|
|
|
|
const mockLatLng = {
|
|
latitude: 37.77,
|
|
longitude: -122.42
|
|
};
|
|
|
|
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
|
|
__esModule: true,
|
|
default: ( ) => ( {
|
|
data: [mockProject]
|
|
} )
|
|
} ) );
|
|
|
|
jest.mock( "../../../../src/sharedHooks/useLoggedIn", ( ) => ( {
|
|
__esModule: true,
|
|
default: ( ) => true
|
|
} ) );
|
|
|
|
// Mock the hooks we use on Map since we're not trying to test them here
|
|
jest.mock( "../../../../src/sharedHooks/useUserLocation", ( ) => ( {
|
|
default: ( ) => mockLatLng,
|
|
__esModule: true
|
|
} ) );
|
|
|
|
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
|
|
} );
|
|
} );
|