Files
iNaturalistReactNative/tests/unit/components/Match/Match.test.js
Johannes Klein d1398a4d29 Add UI for match screen not identifying (#2728)
* Alternative return for match screen in absence of suggestion

* Add lower part text elements

* Add margin at bottom

* Copy code to make a new suggestions scrll for iconic taxa

* Removing not needed properties of the copied code

* Remove log

* Remove width constraints

* Add a state to track selected iconic taxon

* Comment and code style

* Pass prop down to taxa scroll

* Use new props in iconic taxa scroll

* Color border according to selected state

* Use iconic taxon as top ID if none given

* Remove testing code

* Update Match.test.js
2025-03-07 19:42:38 +01:00

86 lines
2.6 KiB
JavaScript

import Geolocation from "@react-native-community/geolocation";
import { screen } from "@testing-library/react-native";
import Match from "components/Match/Match";
import initI18next from "i18n/initI18next";
import React from "react";
import * as useLocationPermission from "sharedHooks/useLocationPermission.tsx";
import factory from "tests/factory";
import { renderComponent } from "tests/helpers/render";
// Initialize i18next for translations
beforeAll( async () => {
await initI18next();
} );
describe( "Match", ( ) => {
// Mock props that would normally come from MatchContainer
const defaultProps = {
observation: factory( "LocalObservation" ),
obsPhotos: [factory( "LocalObservationPhoto" )],
onSuggestionChosen: jest.fn(),
handleSaveOrDiscardPress: jest.fn(),
navToTaxonDetails: jest.fn(),
handleAddLocationPressed: jest.fn(),
scrollRef: { current: null },
topSuggestion: {
combined_score: 92,
taxon: factory( "LocalTaxon" )
},
otherSuggestions: [{
combined_score: 90,
taxon: factory( "LocalTaxon" )
}]
};
beforeEach( () => {
jest.clearAllMocks();
} );
it( "should show location permissions button if permissions not granted", () => {
jest.spyOn( useLocationPermission, "default" ).mockImplementation( ( ) => ( {
hasPermissions: false,
renderPermissionsGate: jest.fn( )
} ) );
renderComponent(
<Match
// eslint-disable-next-line react/jsx-props-no-spreading
{...defaultProps}
observation={defaultProps.observation}
/>
);
const addLocationButton = screen.queryByText( /ADD LOCATION FOR BETTER IDS/i );
expect( addLocationButton ).toBeVisible();
} );
it( "should not show location permissions button if permissions granted", () => {
const mockWatchPosition = jest.fn( ( success, _error, _options ) => success( {
coords: {
latitude: 56,
longitude: 9,
accuracy: 8
}
} ) );
Geolocation.watchPosition.mockImplementation( mockWatchPosition );
jest.spyOn( useLocationPermission, "default" ).mockImplementation( ( ) => ( {
hasPermissions: true,
renderPermissionsGate: jest.fn( )
} ) );
renderComponent(
<Match
// eslint-disable-next-line react/jsx-props-no-spreading
{...defaultProps}
observation={{
...defaultProps.observation,
latitude: 24,
longitude: -24
}}
/>
);
const addLocationButton = screen.queryByText( /ADD LOCATION FOR BETTER IDS/i );
expect( addLocationButton ).toBeFalsy( );
} );
} );