mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-24 00:41:45 -04:00
* Add KebabMenu to shared components index * Separate EvidenceList from PhotoCarousel component * Remove unneeded props from PhotoCarousel * Create notes bottom sheet * Fix tests for delete obs sheet * Add wild status sheet * Show date from observations uploaded via website * Move media viewer modal into evidence section * Fix mock * Move location fetching into its own hook * Refactor ObsEdit header; move code into Header component * Add discard changes sheet * Styling updates and save changes button * Add classes to buttons based on evidence/id missing * Add imprecise location sheet * Add jest.fn from provider to ObsEdit tests * Remove fakeTimers from ObsEditWithoutProvider.test.js; minor cleanup * Show discard obs sheet anytime a user tries to navigate back * Fixes to bottom sheet backdrop, evidence, add discard changes sheet * Switch to paper radio buttons instead of checkmarks * Fix bottom sheet backdrop in android by wrapping with GestureHandlerRootView * Update bottom sheet for add comment & notes * Fix test * Remove fake timer from ObsEdit test to get tests passing * Force update github actions cache --------- Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
89 lines
3.3 KiB
JavaScript
89 lines
3.3 KiB
JavaScript
import { useRoute } from "@react-navigation/native";
|
|
import { screen, waitFor } from "@testing-library/react-native";
|
|
import ObsEdit from "components/ObsEdit/ObsEdit";
|
|
import ObsEditProvider from "providers/ObsEditProvider";
|
|
import React from "react";
|
|
import Observation from "realmModels/Observation";
|
|
|
|
import factory from "../factory";
|
|
import { renderComponent } from "../helpers/render";
|
|
import { signIn, signOut } from "../helpers/user";
|
|
|
|
beforeEach( async ( ) => {
|
|
global.realm.write( ( ) => {
|
|
global.realm.deleteAll( );
|
|
} );
|
|
const mockUser = factory( "LocalUser" );
|
|
await signIn( mockUser );
|
|
} );
|
|
|
|
afterEach( ( ) => {
|
|
signOut( );
|
|
jest.clearAllMocks( );
|
|
} );
|
|
|
|
function renderObsEdit( update ) {
|
|
return renderComponent(
|
|
<ObsEditProvider>
|
|
<ObsEdit />
|
|
</ObsEditProvider>,
|
|
update
|
|
);
|
|
}
|
|
|
|
describe( "UUID in params", ( ) => {
|
|
it( "should set the observation in context when context is blank", async ( ) => {
|
|
const observation = await Observation.saveLocalObservationForUpload(
|
|
factory( "LocalObservation" ),
|
|
global.realm
|
|
);
|
|
useRoute.mockImplementation( ( ) => ( { params: { uuid: observation.uuid } } ) );
|
|
renderObsEdit( );
|
|
await waitFor( ( ) => {
|
|
expect( screen.getByText( observation.taxon.name ) ).toBeTruthy( );
|
|
} );
|
|
} );
|
|
|
|
// I don't love this approach. What I want to do is assert that the context
|
|
// has the value I expect it has, but I don't see a way to do that without
|
|
// mocking the entirety of ObsEditProvider, which I don't want to do
|
|
// because that's one of the systems under test here
|
|
it( "should render the observation in params after viewing other observation", async ( ) => {
|
|
const observation = await Observation.saveLocalObservationForUpload(
|
|
factory( "LocalObservation" ),
|
|
global.realm
|
|
);
|
|
useRoute.mockImplementation( () => ( { params: { uuid: observation.uuid } } ) );
|
|
const { update } = renderObsEdit();
|
|
expect( await screen.findByText( observation.taxon.name ) ).toBeTruthy();
|
|
// Up to this point we're just repeating the prior test to ensure that the
|
|
// observation in the params gets inserted into the context
|
|
|
|
// Now we alter the params so they specify a different observation
|
|
const newObservation = await Observation.saveLocalObservationForUpload(
|
|
factory( "LocalObservation" ),
|
|
global.realm
|
|
);
|
|
useRoute.mockImplementation( () => ( {
|
|
params: { uuid: newObservation.uuid }
|
|
} ) );
|
|
await renderObsEdit( update );
|
|
expect( screen.getByText( newObservation.taxon.name ) ).toBeTruthy();
|
|
expect( screen.queryByText( observation.taxon.name ) ).toBeFalsy();
|
|
} );
|
|
|
|
it( "should not reset the observation in context when context has "
|
|
+ "the same observation", async ( ) => {
|
|
const observation = await Observation.saveLocalObservationForUpload(
|
|
factory( "LocalObservation" ),
|
|
global.realm
|
|
);
|
|
useRoute.mockImplementation( ( ) => ( { params: { uuid: observation.uuid } } ) );
|
|
const { update } = renderObsEdit( );
|
|
expect( await screen.findByText( observation.taxon.name ) ).toBeTruthy( );
|
|
useRoute.mockImplementation( ( ) => ( { params: { uuid: observation.uuid } } ) );
|
|
await renderObsEdit( update );
|
|
expect( await screen.findByText( observation.taxon.name ) ).toBeTruthy( );
|
|
} );
|
|
} );
|