Files
iNaturalistReactNative/tests/integration/Explore.test.js
Amanda Bullington cf70a4358a Move modules from jest setup to __mocks__ (#1949)
* Get a few mocks working in __mocks__ folder

* Move more mocks into __mocks__

* Move mocks

* Move zustand mock

* Add more mocks to __mocks__

* More mocks

* Move more files to __mocks__ and audit existing mocks

* Mock react navigation in __mocks__

* Restore test to help with imports after jest env torn down

* Add fake timer to integration test with userEvent

* Add RN paper mock
2024-08-11 11:27:52 -07:00

72 lines
2.5 KiB
JavaScript

import { fireEvent, screen, userEvent } from "@testing-library/react-native";
import ExploreContainer from "components/Explore/ExploreContainer";
import inatjs from "inaturalistjs";
import React from "react";
import factory, { makeResponse } from "tests/factory";
import { renderAppWithComponent } from "tests/helpers/render";
jest.mock( "sharedHooks/useStoredLayout", () => ( {
__esModule: true,
default: ( ) => ( {
layout: "list",
writeLayoutToStorage: jest.fn( )
} )
} ) );
const mockRemoteObservation = factory( "RemoteObservation", {
taxon: factory.states( "genus" )( "RemoteTaxon" )
} );
const mockTaxon = factory( "LocalTaxon" );
const actor = userEvent.setup( );
beforeAll( ( ) => {
inatjs.observations.speciesCounts.mockResolvedValue( makeResponse( [{
count: 1,
taxon: mockTaxon
}] ) );
inatjs.observations.search.mockResolvedValue( makeResponse( [mockRemoteObservation] ) );
jest.useFakeTimers( );
} );
const switchToObservationsView = async ( ) => {
const speciesViewIcon = await screen.findByLabelText( /Species View/ );
expect( speciesViewIcon ).toBeVisible( );
await actor.press( speciesViewIcon );
const observationsRadioButton = await screen.findByText( "Observations" );
await actor.press( observationsRadioButton );
const confirmButton = await screen.findByText( /EXPLORE OBSERVATIONS/ );
await actor.press( confirmButton );
const obsTaxonNameElt = await screen.findByText( mockRemoteObservation.taxon.name );
expect( obsTaxonNameElt ).toBeTruthy( );
};
describe( "Explore", ( ) => {
it( "should render species view and switch to observations view list correctly", async ( ) => {
renderAppWithComponent( <ExploreContainer /> );
await switchToObservationsView( );
expect(
await screen.findByTestId( `ObsStatus.${mockRemoteObservation.uuid}` )
).toBeTruthy( );
expect(
screen.queryByTestId( `UploadIcon.progress.${mockRemoteObservation.uuid}` )
).toBeFalsy( );
} );
it( "should display observations view grid correctly", async ( ) => {
renderAppWithComponent( <ExploreContainer /> );
await switchToObservationsView( );
expect(
await screen.findByTestId( "SegmentedButton.grid" )
).toBeTruthy( );
fireEvent.press( await screen.findByTestId( "SegmentedButton.grid" ) );
expect(
await screen.findByTestId( `ObsStatus.${mockRemoteObservation.uuid}` )
).toBeTruthy( );
expect(
screen.queryByTestId( `UploadIcon.progress.${mockRemoteObservation.uuid}` )
).toBeFalsy( );
} );
} );