Files
iNaturalistReactNative/tests/unit/components/Projects/ProjectDetails.test.js
Amanda Bullington e81894d406 Use authenticated queries for fetch/search requests (#195)
* 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>
2022-10-19 13:01:04 -07:00

55 lines
1.4 KiB
JavaScript

import { NavigationContainer } from "@react-navigation/native";
import {
QueryClient,
QueryClientProvider
} from "@tanstack/react-query";
import { render } from "@testing-library/react-native";
import ProjectDetails from "components/Projects/ProjectDetails";
import React from "react";
import factory from "../../../factory";
const mockProject = factory( "RemoteProject" );
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: mockProject
} )
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useRoute: ( ) => ( {
params: {
id: mockProject.id
}
} )
};
} );
const queryClient = new QueryClient( );
const renderProjectDetails = ( ) => render(
<QueryClientProvider client={queryClient}>
<NavigationContainer>
<ProjectDetails />
</NavigationContainer>
</QueryClientProvider>
);
test( "displays project details", ( ) => {
const { getByTestId, getByText } = renderProjectDetails( );
expect( getByText( mockProject.title ) ).toBeTruthy( );
expect( getByText( mockProject.description ) ).toBeTruthy( );
expect(
getByTestId( "ProjectDetails.headerImage" ).props.source
).toStrictEqual( { uri: mockProject.header_image_url } );
expect(
getByTestId( "ProjectDetails.projectIcon" ).props.source
).toStrictEqual( { uri: mockProject.icon } );
} );