mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
* Refactor ObsStatus, add filled property * Remove viewed prop from observation * Update properties for ObsDetail mark viewed * Use separate fields for comments and ids for ObsStatus * Add hook for fetching updates * Unit tests for the updates hook * Unit tests for different paths for updating the realm observation when using the hook * Update MyObservations.test.js * Add integration test if updates has been called in my observations * Update Podfile.lock * Update observation to not viewed if the keys have not been initialized * Add test case if observation fields are not initialized * Add test case * Refetch stale data on coming back from the background * Subscribe to observation updates also in ObsDetail screen This also invalidates and refetches the data after a successful mutation of the id or comment being viewed. * Refetch observation updates data on sync button press * Throw error in updates query * Return refetch function from hook * Add mock to ObsDetails * Remove unused var * Update useObservationsUpdates.test.js * Reset realm viewed state to true ... for all observations on app mount and coming to the foreground. * Reorder function calls * Change hook to use boolean as enabled param * Create ObsDetails.test.js * Update date handle tests to make sure Remote data classes have parseable date * Add test case for comment and identification * Update ObsDetails.test.js * Also check for user in ObsDetails * Refactored into separate hook for App.js * Unit and integration test for new hook * Rename const * Rename field * Rename field * Export query key from hook * Refactor true check * Additional methods for obs being viewed or not * Changed test description * Add per_page to observations updated
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
import { renderHook } from "@testing-library/react-native";
|
|
import useObservationUpdatesWhenFocused from "sharedHooks/useObservationUpdatesWhenFocused";
|
|
|
|
const appStateListeners = {
|
|
};
|
|
|
|
jest.mock( "react-native/Libraries/AppState/AppState", ( ) => ( {
|
|
addEventListener: jest.fn( ( event, callback ) => {
|
|
appStateListeners[event] = callback;
|
|
return {
|
|
remove: jest.fn( () => {
|
|
if ( appStateListeners[event] === callback ) {
|
|
delete appStateListeners[event];
|
|
}
|
|
} )
|
|
};
|
|
} )
|
|
} ) );
|
|
|
|
describe( "useObservationUpdatesWhenFocused", ( ) => {
|
|
it( "should add a change listener on mount", ( ) => {
|
|
renderHook( ( ) => useObservationUpdatesWhenFocused( ) );
|
|
expect( appStateListeners.change ).toBeDefined( );
|
|
expect( appStateListeners.change ).toBeInstanceOf( Function );
|
|
} );
|
|
|
|
it( "should remove the change listener on unmount", ( ) => {
|
|
const { unmount } = renderHook( ( ) => useObservationUpdatesWhenFocused( ) );
|
|
unmount( );
|
|
expect( appStateListeners.change ).toBeUndefined( );
|
|
} );
|
|
} );
|