Files
iNaturalistReactNative/tests/unit/components/AddID/AddID.test.js
Ken-ichi e929764c25 Adopted and enforced code style from other iNat Javascript projects
These rules are largely based on the AirBnB ones, which are not quite standard
for the React Native world, where Prettier seems to be more common, but I
think they add a lot of useful checks, and unlike Prettier we can customize
them. This also just makes it easier for people on the iNat team to work on
the mobile app.

Some specific changes:

* Added eslint-plugin-react-hooks to eslint rules
* Added eslint-plugin-simple-import-sort to eslint rules
* Bugfix: could not import photo from gallery
* Added support for react-native/no-inline-styles eslint rule
* useUser should not bother fetching a user for a blank userId
2022-07-13 13:55:59 -07:00

55 lines
1.6 KiB
JavaScript

import { NavigationContainer } from "@react-navigation/native";
import { fireEvent, render, waitFor } from "@testing-library/react-native";
import inatjs from "inaturalistjs";
import React from "react";
import AddID from "../../../../src/components/ObsEdit/AddID";
import factory, { makeResponse } from "../../../factory";
// Mock inaturalistjs so we can make some fake responses
jest.mock( "inaturalistjs" );
// this resolves a test failure with the Animated library:
// Animated: `useNativeDriver` is not supported because the native animated module is missing.
jest.useFakeTimers( );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useRoute: ( ) => ( {
} )
};
} );
const testTaxaList = [
{ taxon: factory( "RemoteTaxon" ) },
{ taxon: factory( "RemoteTaxon" ) },
{ taxon: factory( "RemoteTaxon" ) }
];
const mockExpected = testTaxaList;
const renderAddID = route => render(
<NavigationContainer>
<AddID route={route} />
</NavigationContainer>
);
test( "renders taxon search results", async ( ) => {
inatjs.search.mockResolvedValue( makeResponse( mockExpected ) );
const route = { params: { } };
const { getByTestId } = renderAddID( route );
const input = getByTestId( "SearchTaxon" );
await waitFor( () => {
fireEvent.changeText( input, "Some taxon" );
} );
const { taxon } = testTaxaList[0];
expect( getByTestId( `Search.taxa.${taxon.id}` ) ).toBeTruthy( );
expect(
getByTestId( `Search.taxa.${taxon.id}.photo` ).props.source
).toStrictEqual( { uri: taxon.default_photo.square_url } );
} );