Files
iNaturalistReactNative/tests/unit/components/Search/Search.users.test.js
Ken-ichi f7dc08a704 Suggestions fixes (#972)
* Bugfix: TaxonDetails was crashing if it received a null taxon
* Send lat and lng instead of latitude and longitude to the score_image
  endpoint
* Show offline suggestions when you are offline
* Show notice when viewing offline suggestions
* Moved code unique to useOnlineSuggestions into that file
* Ensure we use a medium size image to get suggestions when dealing with
  remote URLs
* More logging around React Query retries
* Use default retry logic for useAuthenticatedQuery
* Made a module-resolver shortcut for tests
* Move offline notice above top suggestion; hide when offlines exist but onlines do too
2023-12-15 19:58:12 -08:00

54 lines
1.6 KiB
JavaScript

import { fireEvent, screen } from "@testing-library/react-native";
import Search from "components/Search/Search";
import React from "react";
import factory from "tests/factory";
import { renderComponent } from "tests/helpers/render";
// TODO: figure out how to clear jest mocks correctly or return a different
// value from jest mocks so these can all live in a single file?
const mockedNavigate = jest.fn( );
const mockUser = factory( "RemoteUser" );
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: [mockUser]
} )
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useNavigation: ( ) => ( {
navigate: mockedNavigate
} ),
useRoute: ( ) => ( { } )
};
} );
const { login } = mockUser;
test( "displays user search results on button press", ( ) => {
renderComponent( <Search /> );
const button = screen.getByTestId( "Search.users" );
fireEvent.press( button );
expect( screen.getByTestId( `Search.user.${login}` ) ).toBeTruthy( );
expect( screen.getByTestId( `Search.${login}.photo` ).props.source ).toStrictEqual( {
uri: mockUser.icon
} );
expect( screen.getByText( new RegExp( login ) ) ).toBeTruthy();
} );
test( "navigates to user profile on button press", ( ) => {
renderComponent( <Search /> );
const button = screen.getByTestId( "Search.users" );
fireEvent.press( button );
fireEvent.press( screen.getByTestId( `Search.user.${login}` ) );
expect( mockedNavigate ).toHaveBeenCalledWith( "UserProfile", { userId: mockUser.id } );
} );