mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-31 01:48:36 -05:00
* Add usePerformance load time to cameras and suggestions * Declare when to hide delete photo mode without a useEffect * Use StatusBar hidden component in CameraContainer, instead of useEffects * Directly handle discards from bottom sheet instead of using useEffect * Rewrite a whole bunch of camera code to be more declarative and less imperative * Make sure permissions gate works as expected * Code cleanup * Consolidate focus/blur listeners in AICamera * Fix timing issues in Suggestions tests * Fix tests * Ensure photos are still saving to gallery when write permission given & update saving photo state
96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
import {
|
|
fireEvent, render, screen, waitFor
|
|
} from "@testing-library/react-native";
|
|
import StandardCamera from "components/Camera/StandardCamera/StandardCamera";
|
|
import React from "react";
|
|
import useStore from "stores/useStore";
|
|
import factory from "tests/factory";
|
|
import { wrapInNavigationContainer } from "tests/helpers/render";
|
|
|
|
jest.mock( "components/MediaViewer/MediaViewerModal", ( ) => jest.fn( ( ) => null ) );
|
|
|
|
const initialStoreState = useStore.getState( );
|
|
|
|
const mockPhotoUris = [
|
|
"https://inaturalist-open-data.s3.amazonaws.com/photos/1/large.jpeg",
|
|
"https://inaturalist-open-data.s3.amazonaws.com/photos/2/large.jpeg",
|
|
"https://inaturalist-open-data.s3.amazonaws.com/photos/3/large.jpeg"
|
|
];
|
|
|
|
const mockObservation = factory( "RemoteObservation", {
|
|
observationPhotos: [
|
|
factory( "RemoteObservationPhoto", {
|
|
photo: factory( "RemotePhoto", {
|
|
url: mockPhotoUris[0]
|
|
} )
|
|
} ),
|
|
factory( "RemoteObservationPhoto", {
|
|
photo: factory( "RemotePhoto", {
|
|
url: mockPhotoUris[1]
|
|
} )
|
|
} ),
|
|
factory( "RemoteObservationPhoto", {
|
|
photo: factory( "RemotePhoto", {
|
|
url: mockPhotoUris[2]
|
|
} )
|
|
} )
|
|
]
|
|
} );
|
|
|
|
const renderCamera = ( ) => render(
|
|
wrapInNavigationContainer(
|
|
<StandardCamera
|
|
camera={{}}
|
|
device={{}}
|
|
setNewPhotoUris={jest.fn( )}
|
|
newPhotoUris={[]}
|
|
/>
|
|
)
|
|
);
|
|
|
|
beforeAll( async () => {
|
|
useStore.setState( initialStoreState, true );
|
|
} );
|
|
|
|
describe( "StandardCamera", ( ) => {
|
|
beforeEach( ( ) => {
|
|
useStore.setState( {
|
|
currentObservation: mockObservation,
|
|
observations: [mockObservation]
|
|
} );
|
|
} );
|
|
it( "deletes a photo on long press", async ( ) => {
|
|
renderCamera( );
|
|
const { cameraUris } = useStore.getState( );
|
|
const photoImage = screen.getByTestId(
|
|
`PhotoCarousel.displayPhoto.${cameraUris[2]}`
|
|
);
|
|
const predeletedPhoto = screen.queryByTestId(
|
|
`PhotoCarousel.displayPhoto.${cameraUris[2]}`
|
|
);
|
|
expect( predeletedPhoto ).toBeVisible( );
|
|
|
|
fireEvent( photoImage, "onLongPress" );
|
|
const deleteMode = screen.getByTestId(
|
|
`PhotoCarousel.deletePhoto.${cameraUris[2]}`
|
|
);
|
|
await waitFor( ( ) => {
|
|
expect( deleteMode ).toBeVisible( );
|
|
} );
|
|
fireEvent.press( deleteMode );
|
|
|
|
renderCamera( );
|
|
|
|
const undeletedPhoto = screen.getByTestId(
|
|
`PhotoCarousel.displayPhoto.${cameraUris[1]}`
|
|
);
|
|
expect( undeletedPhoto ).toBeVisible( );
|
|
const deletedPhoto = screen.queryByTestId(
|
|
`PhotoCarousel.displayPhoto.${cameraUris[2]}`
|
|
);
|
|
await waitFor( ( ) => {
|
|
expect( deletedPhoto ).toBeFalsy( );
|
|
} );
|
|
} );
|
|
} );
|