mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-10-08 02:52:57 -04:00
Create NumericFieldInput.test.js
This commit is contained in:
1 parent
cf775c5899
commit
84da38e187
1 file changed
+40
@@ -0,0 +1,40 @@
|
||||
import { screen, userEvent } from "@testing-library/react-native";
|
||||
import NumericFieldInput from "components/AddToProjects/FieldInputs/NumericFieldInput";
|
||||
import useObservationFieldValue from "components/AddToProjects/hooks/useObservationFieldValue";
|
||||
import React from "react";
|
||||
import { renderComponent } from "tests/helpers/render";
|
||||
|
||||
jest.mock( "components/AddToProjects/hooks/useObservationFieldValue" );
|
||||
|
||||
const actor = userEvent.setup( );
|
||||
const mockSetValue = jest.fn( );
|
||||
|
||||
beforeEach( ( ) => {
|
||||
mockSetValue.mockClear( );
|
||||
useObservationFieldValue.mockImplementation( () => ( {
|
||||
value: "",
|
||||
setValue: mockSetValue,
|
||||
} ) );
|
||||
} );
|
||||
|
||||
describe( "NumericFieldInput", ( ) => {
|
||||
it( "reads the OFV value from the hook for the given obsFieldId", ( ) => {
|
||||
renderComponent( <NumericFieldInput obsFieldId={100} /> );
|
||||
|
||||
expect( useObservationFieldValue ).toHaveBeenCalledWith( 100 );
|
||||
} );
|
||||
|
||||
it( "renders with placeholder", ( ) => {
|
||||
renderComponent( <NumericFieldInput obsFieldId={100} /> );
|
||||
|
||||
expect( screen.getByPlaceholderText( "Enter a number" ) ).toBeVisible( );
|
||||
} );
|
||||
|
||||
it( "calls setValue with the typed number", async ( ) => {
|
||||
renderComponent( <NumericFieldInput obsFieldId={100} /> );
|
||||
|
||||
await actor.type( screen.getByPlaceholderText( "Enter a number" ), "3" );
|
||||
|
||||
expect( mockSetValue ).toHaveBeenCalledWith( "3" );
|
||||
} );
|
||||
} );
|
||||
Reference in new issue
Block a user