Files
iNaturalistReactNative/tests/unit/components/ObsEdit/IdentificationSection.test.js
Amanda Bullington 5913fb511e Energy usage / performance improvements (#844)
* Remove console statements in production build

* Move uploadReducer into separate file

* Create reducer for creating obs; combine reducers

* Fixes with createObsReducer

* Move album, passes test states out of global context

* Bug fixes for ObsEdit flow

* Create photo gallery container

* Set accessibility test todo for PhotoGallery

* Improve FlashList performance MyObs

* Prevent flicker on modal close

* Create less rerenders in MyObservations

* Memoize drawer items for less rerendering

* Memoize custom tab bar

* Remove unused libraries and update snapshot

* Fix and prune dependencies

* Add AddObsModal tests

* Fix e2e test android by making comment confirm button visible
2023-11-02 11:03:48 -07:00

80 lines
2.5 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import IdentificationSection from "components/ObsEdit/IdentificationSection";
import initI18next from "i18n/initI18next";
import { ObsEditContext } from "providers/contexts";
import INatPaperProvider from "providers/INatPaperProvider";
import ObsEditProvider from "providers/ObsEditProvider";
import React from "react";
import factory from "../../../factory";
import { renderComponent } from "../../../helpers/render";
// Mock ObservationProvider so it provides a specific array of observations
// without any current observation or ability to update or fetch
// observations
jest.mock( "providers/ObsEditProvider" );
const mockObsEditProviderWithObs = obs => ObsEditProvider.mockImplementation( ( { children } ) => (
// eslint-disable-next-line react/jsx-no-constructed-context-values
<INatPaperProvider>
<ObsEditContext.Provider value={{
observations: obs,
currentObservation: obs[0]
}}
>
{children}
</ObsEditContext.Provider>
</INatPaperProvider>
) );
const renderIdentificationSection = ( ) => renderComponent(
<ObsEditProvider>
<IdentificationSection passesIdentificationTest />
</ObsEditProvider>
);
describe( "IdentificationSection", () => {
beforeAll( async ( ) => {
await initI18next( );
} );
it( "should show IconicTaxonChooser when there is no identification", ( ) => {
const observations = [
factory( "RemoteObservation", {
taxon: null
} )
];
mockObsEditProviderWithObs( observations );
renderIdentificationSection( );
expect( screen.getByTestId( "ObsEdit.Suggestions" ) ).toBeVisible( );
} );
it( "should show IconicTaxonChooser when an iconic taxon is selected", ( ) => {
const observations = [
factory( "RemoteObservation", {
taxon: {
name: "Fungi",
isIconic: true,
iconic_taxon_name: "Fungi"
}
} )
];
mockObsEditProviderWithObs( observations );
renderIdentificationSection( );
expect( screen.getByTestId( "ObsEdit.Suggestions" ) ).toBeVisible( );
} );
it( "should hide IconicTaxonChooser when a non-iconic taxon is selected", ( ) => {
const observations = [
factory( "RemoteObservation", {
taxon: {
name: "Fox Squirrel",
iconic_taxon_name: null
}
} )
];
mockObsEditProviderWithObs( observations );
renderIdentificationSection( );
expect( screen.queryByTestId( "ObsEdit.Suggestions" ) ).toBeFalsy( );
} );
} );