Files
iNaturalistReactNative/tests/unit/components/UserProfile/UserProfile.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

75 lines
2.1 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import UserProfile from "components/UserProfile/UserProfile";
import initI18next from "i18n/initI18next";
import { t } from "i18next";
import React from "react";
import factory from "tests/factory";
import { renderComponent } from "tests/helpers/render";
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,
useRoute: () => ( {
params: {
userId: mockUser.id
}
} ),
useNavigation: () => ( {
setOptions: () => ( { } )
} )
};
} );
jest.mock(
"components/SharedComponents/ScrollViewWrapper",
() => function MockContainer( props ) {
const MockName = "mock-scrollview-with-footer";
// No testID here because the component needs the correct one to work
// eslint-disable-next-line react/jsx-props-no-spreading
return <MockName {...props}>{props.children}</MockName>;
}
);
jest.mock( "components/UserProfile/UserDescription" );
describe( "UserProfile", () => {
beforeAll( async () => {
await initI18next();
} );
it( "should render inside mocked container for testing", () => {
renderComponent( <UserProfile /> );
expect( screen.getByTestId( "UserProfile" ) ).toBeTruthy();
} );
test( "should not have accessibility errors", async () => {
renderComponent( <UserProfile /> );
const userProfile = await screen.findByTestId( "UserProfile" );
expect( userProfile ).toBeAccessible();
} );
test( "renders user profile from API call", async () => {
renderComponent( <UserProfile /> );
expect( screen.getByTestId( `UserProfile.${mockUser.id}` ) ).toBeTruthy( );
expect(
screen.getByText(
new RegExp( t( "OBSERVATIONS-WITHOUT-NUMBER", { count: mockUser.observations_count } ) )
)
).toBeTruthy( );
expect( screen.getByTestId( "UserIcon.photo" ).props.source ).toStrictEqual( {
uri: mockUser.icon_url
} );
} );
} );