Files
iNaturalistReactNative/tests/unit/components/UserProfile/UserProfile.test.js
Chris 44b28ff54e Incremental changes to navbar component (#407)
* Incremental changes to navbar component

* Fix tests

* Fix ally tests

* Space parens

* Add box shadow for android

* Add accessibility role

* Add a11y

* lint

* Add basic tests

* Fix tests

* Fix tests

* Update colors

* Merge remote changes

* Lint

* Add more comprehensive test

* Incremental changes to navbar component

* Fix tests

* Fix ally tests

* Space parens

* Add box shadow for android

* Add accessibility role

* Add a11y

* lint

* Add basic tests

* Fix tests

* Fix tests

* Update colors

* Merge remote changes

* Lint

* Add more comprehensive test

* switch to react native paper

* Make explore button nav to explore

* Remove inline styles

* Fix border on android

* Use user icon component in nav bar

* Rename props

* Remove t from nav button

* Change accessibility props

* Use a11y role for tabs

* Update NavBar.js

* Mock route for messages

* Mock route in tests

* Remove not needed function

* Remove NavBar unit test

* Create integration test file

* Add container mock to user profile test

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
2023-02-03 11:42:55 +01:00

66 lines
1.9 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import UserProfile from "components/UserProfile/UserProfile";
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/ViewWithFooter",
() => 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", () => {
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
} );
} );
} );