mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-19 13:11:23 -04:00
* Regroup accessibility label strings at end of strings file * Add accessibility test to AddID * Add a11y labels to AddID * Add a11y test to StandardCamera * Add a11y props to StandardCamera * Remove unit test with only todos * Add a11y test to Messages * Refactor PhotoScroll test into own file * Add a11y test to ObsDetails * Add a11y test to ObsList * Add a11y matcher to PhotoGallery test * Add a11y matcher to ProjectDetails test * Add a11y matcher to ProjectObservations test * Add a11y matcher to Projects test * Add a11y props to ProjectList * Add a11y props to ProjectTabs * Add a11y matcher to Search * Add a11y matcher to UserProfile test * Add a11y test matcher to UserText test * Update react-native-accessibility-engine * Add a11y matcher to Tabs test * Add a11y label to a selectable photo * Refactor DataTab tests into separate file * Refactor ActivityTab test out into own file * Added a test how to check if a component uses a mocked container * Add wrong a11y props to TextInput left icon * Enable a11y test with actual BottomSheet because mock does not pass a11y props down * Add a11y default props to Button
122 lines
3.8 KiB
JavaScript
122 lines
3.8 KiB
JavaScript
import { fireEvent, screen, waitFor } from "@testing-library/react-native";
|
|
import AddID from "components/ObsEdit/AddID";
|
|
import { t } from "i18next";
|
|
import inatjs from "inaturalistjs";
|
|
import React from "react";
|
|
|
|
import factory, { makeResponse } from "../../../factory";
|
|
import { renderComponent } from "../../../helpers/render";
|
|
// Mock inaturalistjs so we can make some fake responses
|
|
jest.mock( "inaturalistjs" );
|
|
|
|
// this resolves a test failure with the Animated library:
|
|
// Animated: `useNativeDriver` is not supported because the native animated module is missing.
|
|
jest.useFakeTimers( );
|
|
|
|
jest.mock(
|
|
"components/SharedComponents/ViewNoFooter",
|
|
() => function MockViewNoFooter( props ) {
|
|
const MockName = "mock-view-no-footer";
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
return <MockName {...props} testID={MockName}>{props.children}</MockName>;
|
|
}
|
|
);
|
|
|
|
jest.mock(
|
|
"components/SharedComponents/BottomSheetStandardBackdrop",
|
|
() => function MockBottomSheetStandardBackdrop( props ) {
|
|
const MockName = "mock-bottom-sheet-standard-backdrop";
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
return <MockName {...props} testID={MockName}>{props.children}</MockName>;
|
|
}
|
|
);
|
|
|
|
const mockTaxaList = [
|
|
factory( "RemoteTaxon" ),
|
|
factory( "RemoteTaxon" ),
|
|
factory( "RemoteTaxon" )
|
|
];
|
|
|
|
jest.mock( "sharedHooks/useAuthenticatedQuery", ( ) => ( {
|
|
__esModule: true,
|
|
default: ( ) => ( {
|
|
data: mockTaxaList
|
|
} )
|
|
} ) );
|
|
|
|
jest.mock( "react-native-vector-icons/MaterialIcons", ( ) => {
|
|
const InnerReact = require( "react" );
|
|
class MaterialIcons extends InnerReact.Component {
|
|
static getImageSourceSync( _thing, _number, _color ) {
|
|
return { uri: "foo" };
|
|
}
|
|
|
|
render( ) {
|
|
return InnerReact.createElement( "MaterialIcons", this.props, this.props.children );
|
|
}
|
|
}
|
|
return MaterialIcons;
|
|
} );
|
|
|
|
jest.mock( "@gorhom/bottom-sheet", () => {
|
|
const actualBottomSheet = jest.requireActual( "@gorhom/bottom-sheet" );
|
|
return {
|
|
...actualBottomSheet
|
|
};
|
|
} );
|
|
|
|
const mockRoute = { params: {} };
|
|
|
|
describe( "AddID", ( ) => {
|
|
test( "should not have accessibility errors", ( ) => {
|
|
const addID = <AddID route={mockRoute} />;
|
|
expect( addID ).toBeAccessible( );
|
|
} );
|
|
|
|
it( "should render inside mocked container", ( ) => {
|
|
renderComponent( <AddID route={mockRoute} /> );
|
|
expect( screen.queryByTestId( "mock-view-no-footer" ) ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "show taxon search results", async ( ) => {
|
|
inatjs.search.mockResolvedValue( makeResponse( mockTaxaList ) );
|
|
const { getByTestId } = renderComponent( <AddID route={mockRoute} /> );
|
|
const input = getByTestId( "SearchTaxon" );
|
|
const taxon = mockTaxaList[0];
|
|
await waitFor( () => {
|
|
fireEvent.changeText( input, "Some taxon" );
|
|
expect( getByTestId( `Search.taxa.${taxon.id}` ) ).toBeTruthy( );
|
|
} );
|
|
expect(
|
|
getByTestId( `Search.taxa.${taxon.id}.photo` ).props.source
|
|
).toStrictEqual( { uri: taxon.default_photo.square_url } );
|
|
} );
|
|
|
|
it( "calls callback with a taxon that can be saved to Realm", async ( ) => {
|
|
const mockCallback = jest.fn( ident => {
|
|
global.realm.write( ( ) => {
|
|
global.realm.create( "Taxon", ident.taxon );
|
|
} );
|
|
} );
|
|
renderComponent( (
|
|
<AddID
|
|
route={{
|
|
params: {
|
|
onIDAdded: mockCallback
|
|
}
|
|
}}
|
|
/>
|
|
) );
|
|
const input = screen.getByTestId( "SearchTaxon" );
|
|
const taxon = mockTaxaList[0];
|
|
|
|
fireEvent.changeText( input, "Some taxon" );
|
|
|
|
expect( await screen.findByTestId( `Search.taxa.${taxon.id}` ) ).toBeTruthy( );
|
|
const labelText = t( "Add-this-ID" );
|
|
const chooseButton = ( await screen.findAllByLabelText( labelText ) )[0];
|
|
fireEvent.press( chooseButton );
|
|
expect( mockCallback ).toHaveBeenCalled( );
|
|
} );
|
|
} );
|