mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-05-06 22:56:12 -04:00
* Reorder hooks dependencies * Return uri from take photo hook * Keep state of photos added in this instance of the camera * List2 TS * INatIconButton TS * Refactor useBackPress to show discard modal only if photos taken during this instance of the camera * Remove newPhotoCount var * TS refactors * fetchUserLocation TS * Increase timeout * Fix error * Hoist deletePhotoByUri * Delete photos on discard * Reorder code * Set saving photo on checkmark press Closes #1556 * Update snapshots * Remove delete test * Create StandardCamera.test.js * Check if image is there before deletion * Update react-native-share-menu+6.0.0.patch * Update e2e_ios.yml * Update some types
83 lines
2.4 KiB
JavaScript
83 lines
2.4 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";
|
|
|
|
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"
|
|
];
|
|
|
|
describe( "StandardCamera", ( ) => {
|
|
beforeAll( async () => {
|
|
useStore.setState( initialStoreState, true );
|
|
} );
|
|
|
|
it( "deletes a photo on long press", async ( ) => {
|
|
const removePhotoFromList = ( list, photo ) => {
|
|
const i = list.findIndex( p => p === photo );
|
|
list.splice( i, 1 );
|
|
return list || [];
|
|
};
|
|
|
|
useStore.setState( {
|
|
evidenceToAdd: [mockPhotoUris[2]],
|
|
rotatedOriginalCameraPhotos: mockPhotoUris,
|
|
deletePhotoFromObservation: uri => useStore.setState( {
|
|
rotatedOriginalCameraPhotos: [...removePhotoFromList( mockPhotoUris, uri )]
|
|
} )
|
|
} );
|
|
|
|
const { rotatedOriginalCameraPhotos } = useStore.getState( );
|
|
|
|
render(
|
|
<StandardCamera
|
|
camera={{}}
|
|
device={{}}
|
|
/>
|
|
|
|
);
|
|
const photoImage = screen.getByTestId(
|
|
`PhotoCarousel.displayPhoto.${rotatedOriginalCameraPhotos[2]}`
|
|
);
|
|
const predeletedPhoto = screen.queryByTestId(
|
|
`PhotoCarousel.displayPhoto.${rotatedOriginalCameraPhotos[2]}`
|
|
);
|
|
expect( predeletedPhoto ).toBeVisible( );
|
|
|
|
fireEvent( photoImage, "onLongPress" );
|
|
const deleteMode = screen.getByTestId(
|
|
`PhotoCarousel.deletePhoto.${rotatedOriginalCameraPhotos[2]}`
|
|
);
|
|
await waitFor( ( ) => {
|
|
expect( deleteMode ).toBeVisible( );
|
|
} );
|
|
fireEvent.press( deleteMode );
|
|
|
|
render(
|
|
<StandardCamera
|
|
camera={{}}
|
|
device={{}}
|
|
/>
|
|
);
|
|
|
|
const undeletedPhoto = screen.getByTestId(
|
|
`PhotoCarousel.displayPhoto.${rotatedOriginalCameraPhotos[1]}`
|
|
);
|
|
expect( undeletedPhoto ).toBeVisible( );
|
|
const deletedPhoto = screen.queryByTestId(
|
|
`PhotoCarousel.displayPhoto.${rotatedOriginalCameraPhotos[2]}`
|
|
);
|
|
await waitFor( ( ) => {
|
|
expect( deletedPhoto ).toBeFalsy( );
|
|
} );
|
|
} );
|
|
} );
|