Files
iNaturalistReactNative/tests/integration/sharedHooks/useObservationUpdatesWhenFocused.test.js
Ken-ichi f7dc08a704 Suggestions fixes (#972)
* Bugfix: TaxonDetails was crashing if it received a null taxon
* Send lat and lng instead of latitude and longitude to the score_image
  endpoint
* Show offline suggestions when you are offline
* Show notice when viewing offline suggestions
* Moved code unique to useOnlineSuggestions into that file
* Ensure we use a medium size image to get suggestions when dealing with
  remote URLs
* More logging around React Query retries
* Use default retry logic for useAuthenticatedQuery
* Made a module-resolver shortcut for tests
* Move offline notice above top suggestion; hide when offlines exist but onlines do too
2023-12-15 19:58:12 -08:00

37 lines
1.3 KiB
JavaScript

import { renderHook } from "@testing-library/react-native";
import useObservationUpdatesWhenFocused from "sharedHooks/useObservationUpdatesWhenFocused";
import factory from "tests/factory";
jest.mock( "react-native/Libraries/AppState/AppState", () => ( {
addEventListener: jest.fn( ( event, callback ) => {
callback( "active" );
} )
} ) );
const mockObservations = [
factory( "LocalObservation", { comments_viewed: false, identifications_viewed: false } ),
factory( "LocalObservation", { comments_viewed: true, identifications_viewed: false } ),
factory( "LocalObservation", { comments_viewed: false, identifications_viewed: true } ),
factory( "LocalObservation", { comments_viewed: true, identifications_viewed: true } )
];
describe( "useObservationUpdatesWhenFocused", () => {
beforeAll( async () => {
// Write mock observations to realm
await global.realm.write( () => {
mockObservations.forEach( o => {
global.realm.create( "Observation", o );
} );
} );
} );
it( "should reset state of all observations in realm", () => {
renderHook( () => useObservationUpdatesWhenFocused() );
const observations = global.realm.objects( "Observation" );
observations.forEach( o => {
expect( o.comments_viewed ).toBe( true );
expect( o.identifications_viewed ).toBe( true );
} );
} );
} );