Files
iNaturalistReactNative/tests/unit/components/Projects/ProjectObservations.test.js
Ken-ichi aa0eabcc59 Fix crash on Android after login (#347)
The problem has something to do with the unicode capitalization code that got
ported from the web. It seems like the JS engine in Android has a problem
with calling toUpperCase() on some unicode characters, and this gets around
that particular bug, plus one problem with a null check on a Realm
collection.
2023-01-10 15:35:59 -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 } );
} );