Files
iNaturalistReactNative/tests/unit/components/SharedComponents/ObservationLocation.test.js
Chris 4d4ad83e64 432 obs list item 2 (#486)
* 432 obs list item

* Fix gradient

* Merge conflict essential change

* Merge conflict change required

* Fix tests

* Lint

* Make requested changes

* Space params

* Fix projects ui

* lint

* Use it.each

* lint

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
2023-02-17 14:10:33 +01:00

71 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 "../../../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
},
`${latitude}, ${longitude}`
],
[
"should handle latitude/longitude w/ zero",
{
latitude: 0,
longitude: 0,
place_guess: null
},
"0, 0"
],
[
"should show no location if unknown",
{
latitude: null,
longitude: null,
place_guess: null
},
"Missing 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} />
);
expect( await screen.findByText( expectedResult ) ).toBeTruthy();
} );
} );