Files
iNaturalistReactNative/tests/unit/components/AddID/AddID.test.js
Amanda Bullington 0d69fe1568 Fetch user locale from server and change language (#255)
* Fetch user from server, set locale in realm and change language with i18next
* Added some Spanish translations so I can see localization working
* config QueryClient with `cacheTime: Infinity` to deal with "Jest did not
  exit" errors

Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
2022-12-09 15:51:17 -08:00

56 lines
1.8 KiB
JavaScript

import { fireEvent, waitFor } from "@testing-library/react-native";
import AddID from "components/ObsEdit/AddID";
import inatjs from "inaturalistjs";
import React from "react";
import factory, { makeResponse } from "../../../factory";
import { renderComponent } from "../../../helpers/render";
// 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( );
const mockTaxaList = [
factory( "RemoteTaxon" ),
factory( "RemoteTaxon" ),
factory( "RemoteTaxon" )
];
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: mockTaxaList
} )
} ) );
jest.mock( "react-native-vector-icons/MaterialIcons", ( ) => {
const InnerReact = require( "react" );
class MaterialIcons extends InnerReact.Component {
static getImageSourceSync( _thing, _number, _color ) {
return { uri: "foo" };
}
render( ) {
return InnerReact.createElement( "MaterialIcons", this.props, this.props.children );
}
}
return MaterialIcons;
} );
test( "renders taxon search results", async ( ) => {
inatjs.search.mockResolvedValue( makeResponse( mockTaxaList ) );
const route = { params: { } };
const { getByTestId } = renderComponent( <AddID route={route} /> );
const input = getByTestId( "SearchTaxon" );
const taxon = mockTaxaList[0];
await waitFor( () => {
fireEvent.changeText( input, "Some taxon" );
expect( getByTestId( `Search.taxa.${taxon.id}` ) ).toBeTruthy( );
} );
expect(
getByTestId( `Search.taxa.${taxon.id}.photo` ).props.source
).toStrictEqual( { uri: taxon.default_photo.square_url } );
} );