mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-01-18 18:58:34 -05:00
* Add eslint-plugin-testing-library dependency * Enable plugin inside tests folder * Fix errors given by eslint-plugin
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import { screen } from "@testing-library/react-native";
|
|
import ProjectObservations from "components/Projects/ProjectObservations";
|
|
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]
|
|
} )
|
|
} ) );
|
|
|
|
describe( "ProjectObservations", () => {
|
|
test( "should not have accessibility errors", async ( ) => {
|
|
renderComponent( <ProjectObservations /> );
|
|
const projectObservations = await screen.findByTestId( "ProjectObservations.grid" );
|
|
expect( projectObservations ).toBeAccessible();
|
|
} );
|
|
} );
|
|
|
|
test( "displays project observations", ( ) => {
|
|
renderComponent( <ProjectObservations /> );
|
|
|
|
expect( screen.getByText(
|
|
`${
|
|
mockObservation.taxon.preferred_common_name
|
|
} (${
|
|
mockObservation.taxon.rank
|
|
} ${
|
|
mockObservation.taxon.name
|
|
})`
|
|
) ).toBeTruthy( );
|
|
expect( screen.getByTestId( "ObsList.photo" ).props.source ).toStrictEqual( {
|
|
uri: mockObservation.observation_photos[0].photo.url
|
|
} );
|
|
} );
|