Files
iNaturalistReactNative/tests/integration/MyObservationsSimple.test.js
Amanda Bullington d782538109 Advanced settings UI updates (#2797)
* Open more options on long press

* Add tests for long press

* Rearranging Settings screen with new layout

* Add toggle for advanced settings in layout slice; fix default mode toggle

* Update settings with navigation flows

* Fix tests

* Change power mode switch for e2e test

* Fix settings test for green button toggle

* Fix advanced user toggle in e2e test (which hides pivot cards)

* Changes based on design convo; test fixes

* Fix e2e tests

* Follow user flow chart and update nav accordingly

* Rename function

* Fix test

* Can be null so check for false only

* Little less spacing between radio button rows

* Minor UI updates

* Remove check for previous setting in UI

* This is no longer used anywhere

* Update AICamera.test.js

* Update AICamera.test.js

* Update AICamera.test.js

* Update Suggestions.test.js

* Update Settings.test.js

* Update LanguageSettings.test.js

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
2025-03-27 17:36:36 +01:00

115 lines
3.1 KiB
JavaScript

// These test ensure that My Observation integrates with other systems like
// remote data retrieval and local data persistence
import { screen, waitFor } from "@testing-library/react-native";
import MyObservationsContainer from "components/MyObservations/MyObservationsContainer.tsx";
import React from "react";
import safeRealmWrite from "sharedHelpers/safeRealmWrite";
import useStore from "stores/useStore";
import factory from "tests/factory";
import faker from "tests/helpers/faker";
import { renderAppWithComponent } from "tests/helpers/render";
import setupUniqueRealm from "tests/helpers/uniqueRealm";
const mockUnsyncedObservations = [
factory( "LocalObservation", {
_synced_at: null,
observationPhotos: [
factory( "LocalObservationPhoto", {
photo: {
url: faker.image.url( ),
position: 0
}
} )
]
} ),
factory( "LocalObservation", {
_synced_at: null,
observationPhotos: [
factory( "LocalObservationPhoto", {
photo: {
url: `${faker.image.url( )}/100`,
position: 0
}
} ),
factory( "LocalObservationPhoto", {
photo: {
url: `${faker.image.url( )}/200`,
position: 1
}
} )
]
} )
];
jest.mock( "sharedHooks/useFontScale", () => ( {
__esModule: true,
default: ( ) => ( { isLargeFontScale: false } )
} ) );
// UNIQUE REALM SETUP
const mockRealmIdentifier = __filename;
const { mockRealmModelsIndex, uniqueRealmBeforeAll, uniqueRealmAfterAll } = setupUniqueRealm(
mockRealmIdentifier
);
jest.mock( "realmModels/index", ( ) => mockRealmModelsIndex );
jest.mock( "providers/contexts", ( ) => {
const originalModule = jest.requireActual( "providers/contexts" );
return {
__esModule: true,
...originalModule,
RealmContext: {
...originalModule.RealmContext,
useRealm: ( ) => global.mockRealms[mockRealmIdentifier],
useQuery: ( ) => []
}
};
} );
beforeAll( uniqueRealmBeforeAll );
afterAll( uniqueRealmAfterAll );
// /UNIQUE REALM SETUP
const writeObservationsToRealm = ( observations, message ) => {
const realm = global.mockRealms[__filename];
safeRealmWrite( realm, ( ) => {
observations.forEach( mockObservation => {
realm.create( "Observation", mockObservation );
} );
}, message );
};
const displayItemByText = text => {
const item = screen.getByText( text );
expect( item ).toBeVisible( );
};
beforeEach( ( ) => {
useStore.setState( {
layout: {
isDefaultMode: true,
shownOnce: {},
isAllAddObsOptionsMode: false
}
} );
} );
describe( "MyObservationsSimple", ( ) => {
describe( "when signed out", ( ) => {
beforeEach( ( ) => {
writeObservationsToRealm(
mockUnsyncedObservations,
"writing unsynced observations for MyObservations integration test"
);
} );
it( "displays correct header", async () => {
const realm = global.mockRealms[__filename];
expect( realm.objects( "Observation" ).length ).toBeGreaterThan( 0 );
renderAppWithComponent( <MyObservationsContainer /> );
await waitFor( ( ) => {
displayItemByText( /My Observations/ );
} );
} );
} );
} );