mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-05-04 05:33:21 -04:00
* Use authenticated query for search results * Use search API for fetching places from Settings * Use authenticated query for authorized applications * Use authenticated query to fetch user.me * Move fetch/search api calls into react query format, out of hooks * Update with react query instead of hooks * Fetch list of blocked and muted users with authenticated query * Added Podfile postinstall block to get app running in a Simulator * Use auth query in identify * Upgrade Realm to 11.0.0-rc.0, most recent version that will work with RN 0.68.2 * Upgrade @realm/react library to 0.4.0; fixes initialization error on android due to importing realm * Use authquery for explore provider * ObsDetail wasn't showing the edit button for obs created while signed out * simplified ObsEditHeader so it takes a full observation instead of relying on the ObsEditContext * ObsEdit now accepts an obs UUID as a param and loads that if the context doesn't have a current obs * null checks for API methods, mostly to prevent requests that won't work b/c of missing params Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
import { NavigationContainer } from "@react-navigation/native";
|
|
import {
|
|
QueryClient,
|
|
QueryClientProvider
|
|
} from "@tanstack/react-query";
|
|
import { fireEvent, render, 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";
|
|
// 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 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;
|
|
} );
|
|
|
|
const queryClient = new QueryClient( );
|
|
|
|
const renderAddID = route => render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<NavigationContainer>
|
|
<AddID route={route} />
|
|
</NavigationContainer>
|
|
</QueryClientProvider>
|
|
);
|
|
|
|
test( "renders taxon search results", async ( ) => {
|
|
inatjs.search.mockResolvedValue( makeResponse( mockTaxaList ) );
|
|
const route = { params: { } };
|
|
const { getByTestId } = renderAddID( route );
|
|
|
|
const input = getByTestId( "SearchTaxon" );
|
|
await waitFor( () => {
|
|
fireEvent.changeText( input, "Some taxon" );
|
|
} );
|
|
|
|
const taxon = mockTaxaList[0];
|
|
|
|
expect( getByTestId( `Search.taxa.${taxon.id}` ) ).toBeTruthy( );
|
|
expect(
|
|
getByTestId( `Search.taxa.${taxon.id}.photo` ).props.source
|
|
).toStrictEqual( { uri: taxon.default_photo.square_url } );
|
|
} );
|