Files
iNaturalistReactNative/tests/unit/components/Projects/Projects.test.js
Amanda Bullington 337d812ab9 UI updates to bottom sheet (#181)
* Changes My Observations upload bottom sheet from modal to non-modal
* Give flatlist container a minHeight to make bottom sheet snap correctly when flatlist has few items
* Mock useLoggedIn hook in tests
* Move useCurrentUser to sharedHooks/ and mock in ObsList test
* Mock useUser hook
* Use useCurrentUser hook on user profile
* Downgrade gesture handler
2022-09-19 14:40:26 -07:00

62 lines
1.7 KiB
JavaScript

import { NavigationContainer } from "@react-navigation/native";
import { fireEvent, render } from "@testing-library/react-native";
import React from "react";
import Projects from "../../../../src/components/Projects/Projects";
import factory from "../../../factory";
const mockedNavigate = jest.fn( );
const mockProject = factory( "RemoteProject" );
const mockLatLng = {
latitude: 37.77,
longitude: -122.42
};
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( "../../../../src/components/Projects/hooks/useProjects", ( ) => ( {
__esModule: true,
default: ( ) => [mockProject]
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useNavigation: ( ) => ( {
navigate: mockedNavigate
} )
};
} );
const renderProjects = () => render(
<NavigationContainer>
<Projects />
</NavigationContainer>
);
test( "displays project search results", ( ) => {
const { getByTestId, getByText } = renderProjects( );
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
} );
} );