mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-21 07:20:03 -04:00
* 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>
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
import { screen } from "@testing-library/react-native";
|
|
import ProjectObservations from "components/Projects/ProjectObservations";
|
|
import initI18next from "i18n/initI18next";
|
|
import React from "react";
|
|
|
|
import factory from "../../../factory";
|
|
import { renderComponent } from "../../../helpers/render";
|
|
|
|
const mockProject = factory( "RemoteProject" );
|
|
const mockObservation = factory( "RemoteObservation", {
|
|
taxon: { preferred_common_name: "Foo", name: "bar" }
|
|
} );
|
|
|
|
jest.mock( "@react-navigation/native", ( ) => {
|
|
const actualNav = jest.requireActual( "@react-navigation/native" );
|
|
return {
|
|
...actualNav,
|
|
useRoute: ( ) => ( {
|
|
params: {
|
|
id: mockProject.id
|
|
}
|
|
} )
|
|
};
|
|
} );
|
|
|
|
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
|
|
__esModule: true,
|
|
default: ( ) => ( {
|
|
data: [mockObservation]
|
|
} )
|
|
} ) );
|
|
|
|
describe( "ProjectObservations", () => {
|
|
beforeAll( async ( ) => {
|
|
await initI18next( );
|
|
} );
|
|
|
|
test( "should not have accessibility errors", async ( ) => {
|
|
renderComponent( <ProjectObservations /> );
|
|
const projectObservations = await screen.findByTestId( "ProjectObservations.grid" );
|
|
expect( projectObservations ).toBeAccessible();
|
|
} );
|
|
} );
|
|
|
|
test( "displays project observations", ( ) => {
|
|
renderComponent( <ProjectObservations /> );
|
|
|
|
expect( screen.getByTestId( "display-taxon-name" ) ).toHaveTextContent(
|
|
`${
|
|
mockObservation.taxon.preferred_common_name
|
|
}${
|
|
mockObservation.taxon.rank.charAt( 0 ).toUpperCase()
|
|
+ mockObservation.taxon.rank.slice( 1 )
|
|
} ${
|
|
mockObservation.taxon.name
|
|
}`
|
|
);
|
|
expect( screen.getByTestId( "ObsList.photo" ).props.source ).toStrictEqual( {
|
|
uri: mockObservation.observation_photos[0].photo.url
|
|
} );
|
|
} );
|