Files
iNaturalistReactNative/tests/unit/components/ProjectDetails/ProjectDetails.test.js
Ken-ichi f7dc08a704 Suggestions fixes (#972)
* Bugfix: TaxonDetails was crashing if it received a null taxon
* Send lat and lng instead of latitude and longitude to the score_image
  endpoint
* Show offline suggestions when you are offline
* Show notice when viewing offline suggestions
* Moved code unique to useOnlineSuggestions into that file
* Ensure we use a medium size image to get suggestions when dealing with
  remote URLs
* More logging around React Query retries
* Use default retry logic for useAuthenticatedQuery
* Made a module-resolver shortcut for tests
* Move offline notice above top suggestion; hide when offlines exist but onlines do too
2023-12-15 19:58:12 -08:00

58 lines
1.8 KiB
JavaScript

import { faker } from "@faker-js/faker";
import { screen } from "@testing-library/react-native";
import ProjectDetailsContainer from "components/ProjectDetails/ProjectDetailsContainer";
import initI18next from "i18n/initI18next";
import React from "react";
import factory from "tests/factory";
import { renderComponent } from "tests/helpers/render";
const mockProject = factory( "RemoteProject", {
title: faker.lorem.sentence( ),
icon: faker.image.url( ),
header_image_url: faker.image.url( ),
description: faker.lorem.paragraph( )
} );
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
__esModule: true,
default: ( ) => ( {
data: mockProject
} )
} ) );
jest.mock( "@react-navigation/native", ( ) => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useRoute: ( ) => ( {
params: {
id: mockProject.id
}
} )
};
} );
describe( "ProjectDetails", ( ) => {
beforeAll( async ( ) => {
await initI18next( );
} );
test( "should not have accessibility errors", async ( ) => {
renderComponent( <ProjectDetailsContainer /> );
const projectDetails = await screen.findByTestId( "project-details" );
expect( projectDetails ).toBeAccessible();
} );
test( "displays project details", ( ) => {
renderComponent( <ProjectDetailsContainer /> );
expect( screen.getByText( mockProject.title ) ).toBeTruthy( );
expect( screen.getByText( mockProject.description ) ).toBeTruthy( );
expect(
screen.getByTestId( "ProjectDetails.headerImage" ).props.source
).toStrictEqual( { uri: mockProject.header_image_url } );
expect(
screen.getByTestId( "ProjectDetails.projectIcon" ).props.source
).toStrictEqual( { uri: mockProject.icon } );
} );
} );