Files
iNaturalistReactNative/tests/unit/components/UserProfile/UserProfile.test.js
Amanda Bullington 7a98b6faf1 Timeless dates (#457)
* Add DateDisplay to ObsCard and make first pass at translation strings

* Add failing tests (due to lack of localization) for timeless dates

* WIP: trying to ensure i18next gets initialized before tests run

The remaining test failures might be legit. This probably breaks the actual
app, though.

* Got the rest of the tests working

* Updated tests to assume UTC
* Updated README to advise against using `npx jest` so test runs always have
  the env vars we specify in our `npm test` script
* Moved i18next initialization to an explicitly-named file
* Use i18next init function in app
* Fixed up remaining tests

* Added test for non-English localization of date format

* Cleanup

* Made DateDisplay explicitly handle strings not Dates

* Restore skipped localization tests for MyObservations

* Remove duplicative tests from DateDisplay unit test

* Added note to the README about initializing i18next

* Updated change to DateDisplay in main

---------

Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
2023-02-14 22:14:38 +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/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", () => {
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
} );
} );
} );