Files
iNaturalistReactNative/tests/unit/components/Projects/ProjectDetails.test.js
Amanda Bullington 9c6106f5d0 Refactor tests to use minimum viable test factories (#681)
* Make minimum viable RemoteComment

* Minimum vialbe RemoteIdentification

* Minimum viable remote project, place, and messages

* Create minimum viable records for all remote factories

* Remove factories for local device data

* Minimum viable local taxon, comment, id

* Minimum viable for local observation photo (photo has no primary key)

* Minimum viable LocalUser

* Minimum viable record for LocalObservation
2023-06-27 17:06:01 -07:00

59 lines
1.7 KiB
JavaScript

import { faker } from "@faker-js/faker";
import { screen } from "@testing-library/react-native";
import ProjectDetails from "components/Projects/ProjectDetails";
import initI18next from "i18n/initI18next";
import React from "react";
import factory from "../../../factory";
import { renderComponent } from "../../../helpers/render";
const mockProject = factory( "RemoteProject", {
title: faker.lorem.sentence( ),
icon: faker.image.imageUrl( ),
header_image_url: faker.image.imageUrl( ),
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( <ProjectDetails /> );
const projectDetails = await screen.findByTestId( "project-details" );
expect( projectDetails ).toBeAccessible();
} );
test( "displays project details", ( ) => {
renderComponent( <ProjectDetails /> );
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 } );
} );
} );