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

62 lines
1.7 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import { DisplayTaxon } from "components/SharedComponents";
import initI18next from "i18n/initI18next";
import React from "react";
import factory from "tests/factory";
import { renderComponent } from "tests/helpers/render";
const mockTaxon = factory( "RemoteTaxon", {
name: "Aves",
preferred_common_name: "Birds",
default_photo: {
url: ""
}
} );
const taxonWithIconicTaxonPhoto = factory( "LocalTaxon", {
name: "Pavo cristatus",
preferred_common_name: "Peafowl",
iconic_taxon_name: "Aves",
default_photo: {
url: "some url"
}
} );
describe( "DisplayTaxon", () => {
beforeAll( async ( ) => {
await initI18next( );
} );
it( "should be accessible", () => {
expect( <DisplayTaxon taxon={mockTaxon} handlePress={( ) => { }} /> ).toBeAccessible( );
} );
it( "displays an iconic taxon icon when no photo is available", () => {
renderComponent( <DisplayTaxon taxon={mockTaxon} handlePress={( ) => { }} /> );
expect( screen.getByTestId( "IconicTaxonName.iconicTaxonIcon" ) );
} );
it( "displays an iconic taxon photo when no taxon photo is available", () => {
renderComponent( <DisplayTaxon taxon={taxonWithIconicTaxonPhoto} handlePress={( ) => { }} /> );
expect(
screen.getByTestId( "DisplayTaxon.image" ).props.source
).toStrictEqual( { uri: taxonWithIconicTaxonPhoto?.default_photo?.url } );
} );
it( "displays 50% opacity when taxon id is withdrawn", () => {
renderComponent(
<DisplayTaxon
taxon={taxonWithIconicTaxonPhoto}
handlePress={( ) => { }}
withdrawn
/>
);
expect(
screen.getByTestId( "DisplayTaxon.image" )
).toHaveStyle( { opacity: 0.5 } );
} );
} );