Files
iNaturalistReactNative/tests/unit/components/UserProfile/UserProfile.test.js
Amanda Bullington 337d812ab9 UI updates to bottom sheet (#181)
* Changes My Observations upload bottom sheet from modal to non-modal
* Give flatlist container a minHeight to make bottom sheet snap correctly when flatlist has few items
* Mock useLoggedIn hook in tests
* Move useCurrentUser to sharedHooks/ and mock in ObsList test
* Mock useUser hook
* Use useCurrentUser hook on user profile
* Downgrade gesture handler
2022-09-19 14:40:26 -07:00

54 lines
1.5 KiB
JavaScript

import { NavigationContainer } from "@react-navigation/native";
import { render } from "@testing-library/react-native";
import React from "react";
import UserProfile from "../../../../src/components/UserProfile/UserProfile";
import factory from "../../../factory";
const testUser = factory( "RemoteUser" );
const mockExpected = testUser;
jest.mock( "../../../../src/components/UserProfile/hooks/useUser", ( ) => ( {
__esModule: true,
default: ( ) => ( {
user: mockExpected
} )
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useRoute: ( ) => ( {
params: {
userId: mockExpected.id
}
} )
};
} );
const renderUserProfile = ( ) => render(
<NavigationContainer>
<UserProfile />
</NavigationContainer>
);
test( "renders user profile from API call", ( ) => {
const { getByTestId, getByText } = renderUserProfile( );
expect( getByTestId( `UserProfile.${testUser.id}` ) ).toBeTruthy( );
expect( getByText( `@${testUser.login}` ) ).toBeTruthy( );
expect( getByTestId( "UserIcon.photo" ).props.source )
.toStrictEqual( { uri: testUser.icon_url } );
} );
test.todo( "should not have accessibility errors" );
// test( "should not have accessibility errors", ( ) => {
// const userProfile = (
// <NavigationContainer>
// <UserProfile />
// </NavigationContainer>
// );
// expect( userProfile ).toBeAccessible( );
// } );