Files
iNaturalistReactNative/tests/unit/components/SharedComponents/Map.test.js
Ken-ichi b5ed9d0475 feat: show obs on TaxonDetails map (#2399)
* reduce prop surface area for map-related components
* map just receives an observation, not a bunch of its properties
* adjust a lot of logic based on observation.obscured to more specific logic
  based on whether the current user can view the coordinates
* hide the map on ObsDetails if there are no coordinates
* show the spec'd explanation for why coordinates are obscured
* remove a prop that just hides a component if true; that should really be up
  to the outer context
* fixed a bug on ObsDetail where the remote obs wasn't getting mapped to
  Realm-ish attributes
* prevent button mashing from opening multiple TaxonDetails
* clean out the state related obs create / edit after exiting that flow so
  that TaxonDetails (or anyone else trying to detect an obs being edited)
  doesn't end up finding it when the user has finished creating / editing.

Closes #2271
2024-11-11 14:20:14 -08:00

52 lines
1.5 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import { Map } from "components/SharedComponents";
import { TILE_URL } from "components/SharedComponents/Map/helpers/mapHelpers.ts";
import React from "react";
import faker from "tests/helpers/faker";
import { renderComponent } from "tests/helpers/render";
const baseUrl = `${TILE_URL}/grid/{z}/{x}/{y}.png`;
jest.mock( "sharedHooks/useLocationPermission.tsx", () => ( {
__esModule: true,
default: ( ) => ( {
hasPermissions: true,
renderPermissionsGate: jest.fn(),
requestPermissions: jest.fn()
} )
} ) );
describe( "Map", ( ) => {
it( "should be accessible", ( ) => {
expect( <Map /> ).toBeAccessible( );
} );
it( "displays filtered observations on map", async ( ) => {
const taxonId = 1234;
renderComponent(
<Map
withPressableObsTiles
tileMapParams={{ taxon_id: taxonId }}
/>
);
const tiles = await screen.findByTestId( "Map.UrlTile" );
const { urlTemplate } = tiles.props;
expect( urlTemplate )
.toMatch( new RegExp( `^${baseUrl}.*taxon_id=${taxonId}` ) );
} );
it( "displays location indicator when given an observation w/ lat/lng", async ( ) => {
renderComponent(
<Map
showLocationIndicator
observation={{
latitude: Number( faker.location.latitude( ) ),
longitude: Number( faker.location.longitude( ) )
}}
/>
);
const testId = "Map.LocationIndicator";
expect( screen.getByTestId( testId ) ).toBeTruthy();
} );
} );