Files
iNaturalistReactNative/tests/unit/components/Projects/ProjectObservations.test.js
Chris 516b1a487d Create more robust taxon display name component - #320 (#334)
* Add missing dependency

* Fix display taxon name

* Lint

* Add unit tests

* Lint

* Add test file

* Fix bad commits

* Add unit tests

* Lint

* Fix lint

* Lint

* Fix tests

* Fix tests

* Remove console log

* Fix most comments and add test case for subspecies

* Fix lint

* Add common name capitalization

* Fix broken tests

* Fix test
2023-01-06 10:39:38 -08:00

46 lines
1.2 KiB
JavaScript

import ProjectDetails from "components/Projects/ProjectDetails";
import React from "react";
import factory from "../../../factory";
import { renderComponent } from "../../../helpers/render";
const mockProject = factory( "RemoteProject" );
const mockObservation = factory( "RemoteObservation", {
taxon: { preferred_common_name: "Foo", name: "bar" }
} );;
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useRoute: ( ) => ( {
params: {
id: mockProject.id
}
} )
};
} );
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: [mockObservation]
} )
} ) );
test( "displays project observations", ( ) => {
const { getByTestId, getByText } = renderComponent( <ProjectDetails /> );
expect( getByText(
`${
mockObservation.taxon.preferred_common_name
} (${
mockObservation.taxon.rank
} ${
mockObservation.taxon.name
})`
) ).toBeTruthy( );
expect( getByTestId( "ObsList.photo" ).props.source )
.toStrictEqual( { uri: mockObservation.observation_photos[0].photo.url } );
} );