Files
iNaturalistReactNative/tests/integration/navigation/StandardCamera.test.js
Amanda Bullington abd4bcee23 Refactored location fetching for accurate locations (#1788)
* Refactor to use watchPosition

* Update useWatchPosition with permissions/retry

* Replace useUserLocation with useWatchPosition and fix tests; return userLocation from watch position hook

* Only update observation keys when there's an observation

* Improve TypeScript definitions

* Revert TypeScript commit

* Revert "Only update observation keys when there's an observation"

This reverts commit a4cd17a513.

* Code cleanup: make useWatchPosition more modular

* Code cleanup; location permission in ObsEdit instead of subcomponent

* Use correct accuracy in Camera photos

* Camera fixes

* Fixes to watching position in ObsEdit

* Fix useWatchPosition tests

* Fix tests

* Make sure state updates when renavigating to OsEdit; test fixes
2024-07-16 09:23:09 -07:00

87 lines
3.2 KiB
JavaScript

import Geolocation from "@react-native-community/geolocation";
import {
screen,
userEvent,
within
} from "@testing-library/react-native";
import initI18next from "i18n/initI18next";
import useStore from "stores/useStore";
import { renderApp } from "tests/helpers/render";
import setupUniqueRealm from "tests/helpers/uniqueRealm";
// We're explicitly testing navigation here so we want react-navigation
// working normally
jest.unmock( "@react-navigation/native" );
// UNIQUE REALM SETUP
const mockRealmIdentifier = __filename;
const { mockRealmModelsIndex, uniqueRealmBeforeAll, uniqueRealmAfterAll } = setupUniqueRealm(
mockRealmIdentifier
);
jest.mock( "realmModels/index", ( ) => mockRealmModelsIndex );
jest.mock( "providers/contexts", ( ) => {
const originalModule = jest.requireActual( "providers/contexts" );
return {
__esModule: true,
...originalModule,
RealmContext: {
...originalModule.RealmContext,
useRealm: ( ) => global.mockRealms[mockRealmIdentifier],
useQuery: ( ) => []
}
};
} );
beforeAll( uniqueRealmBeforeAll );
afterAll( uniqueRealmAfterAll );
// /UNIQUE REALM SETUP
beforeAll( async () => {
await initI18next();
jest.useFakeTimers( );
} );
beforeEach( ( ) => useStore.setState( { isAdvancedUser: true } ) );
describe( "StandardCamera navigation with advanced user layout", ( ) => {
const actor = userEvent.setup( );
describe( "from MyObs", ( ) => {
it( "should return to MyObs when close button tapped", async ( ) => {
renderApp( );
expect( await screen.findByText( /Log in to contribute/ ) ).toBeVisible( );
const tabBar = await screen.findByTestId( "CustomTabBar" );
const addObsButton = await within( tabBar ).findByLabelText( "Add observations" );
await actor.press( addObsButton );
const cameraButton = await screen.findByLabelText( "Camera" );
await actor.press( cameraButton );
const cameraNavButtons = await screen.findByTestId( "CameraNavButtons" );
const closeButton = await within( cameraNavButtons ).findByLabelText( "Close" );
await actor.press( closeButton );
expect( await screen.findByText( /Log in to contribute/ ) ).toBeVisible( );
} );
} );
it( "should advance to Suggestions when photo taken and checkmark tapped", async ( ) => {
const mockWatchPosition = jest.fn( ( success, _error, _options ) => success( {
coords: {
latitude: 56,
longitude: 9,
accuracy: 8
}
} ) );
Geolocation.watchPosition.mockImplementation( mockWatchPosition );
renderApp( );
expect( await screen.findByText( /Log in to contribute/ ) ).toBeVisible( );
const tabBar = await screen.findByTestId( "CustomTabBar" );
const addObsButton = await within( tabBar ).findByLabelText( "Add observations" );
await actor.press( addObsButton );
const cameraButton = await screen.findByLabelText( "Camera" );
await actor.press( cameraButton );
const takePhotoButton = await screen.findByLabelText( /Take photo/ );
await actor.press( takePhotoButton );
const checkmarkButton = await screen.findByLabelText( "View suggestions" );
await actor.press( checkmarkButton );
expect( await screen.findByText( /ADD AN ID/ ) ).toBeVisible( );
} );
} );