Files
iNaturalistReactNative/tests/unit/components/SharedComponents/ObservationLocation.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

70 lines
1.6 KiB
JavaScript

import { render, screen } from "@testing-library/react-native";
import { ObservationLocation } from "components/SharedComponents";
import initI18next from "i18n/initI18next";
import React from "react";
import factory from "tests/factory";
const latitude = 30.18183;
const longitude = -85.760449;
const testData = [
[
"should format location correctly from place_guess",
{
latitude,
longitude,
place_guess: "Panama City Beach, Florida"
},
"Panama City Beach, Florida"
],
[
"should format location correctly from latitude/longitude",
{
latitude,
longitude,
place_guess: null
},
`Lat: ${latitude}, Lon: ${longitude}`
],
[
"should handle latitude/longitude w/ zero",
{
latitude: 0,
longitude: 0,
place_guess: null
},
"Lat: 0, Lon: 0"
],
[
"should show no location if unknown",
{
latitude: null,
longitude: null,
place_guess: null
},
"No Location"
]
];
describe( "ObservationLocation", () => {
beforeAll( async ( ) => {
await initI18next( );
} );
it( "should be accessible", () => {
const mockObservation = factory( "RemoteObservation" );
expect(
<ObservationLocation observation={mockObservation} />
).toBeAccessible();
} );
it.each( testData )( "%s", async ( a, obsData, expectedResult ) => {
const mockObservation = factory( "RemoteObservation", obsData );
render(
<ObservationLocation observation={mockObservation} details />
);
expect( await screen.findByText( new RegExp( expectedResult ) ) ).toBeTruthy();
} );
} );