Files
iNaturalistReactNative/tests/unit/components/UserProfile/UserProfile.test.js
Chris 01099be1ce Create tab navigator (#507)
* Create tab navigator

* Add add obs button

* lint

* Wire up routes

* Fix login

* Add keys

* Fix delayed state bug

* Lint

* space parens

* Add details to tab nav

* Lint

* re-add back btn

* Rebase off main

* Fix format

* Fix back button

* Remove unused change

* Replace lowercase folder

* I don't know why that is needed

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
2023-03-10 14:57:32 +01:00

71 lines
2.0 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import UserProfile from "components/UserProfile/UserProfile";
import initI18next from "i18n/initI18next";
import React from "react";
import factory from "../../../factory";
import { renderComponent } from "../../../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: () => ( {
headerTitle: `@${mockUser.login}`
} )
} )
};
} );
jest.mock(
"components/SharedComponents/ViewWrapper",
() => function MockContainer( props ) {
const MockName = "mock-view-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>;
}
);
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( `iNaturalist ${mockUser.roles[0]}` ) ).toBeTruthy();
expect( screen.getByTestId( "UserIcon.photo" ).props.source ).toStrictEqual( {
uri: mockUser.icon_url
} );
} );
} );