mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-30 17:38:48 -05:00
* Update package.json * Update package.json * Updates for native files with upgrade-helpers * Update .flowconfig * Update package-lock.json * Update Podfile.lock * Add react-dom types * Update package-lock.json * Wrong install * Use types-react-codemod * Update TaxonSearch.tsx * Remove react-native-accessibility-engine dependency This is currently not maintained and not compatible with RN 0.78 * Comment out accessibility tests * Disable broken snapshot test * Move broken test * Move broken test * Move broken test * Remove duplicate file * Move broken tests * Move broken tests * Move broken tests * Move broken tests * Move broken tests * Move broken test * Remove duplicate file * Move broken tests
129 lines
3.6 KiB
JavaScript
129 lines
3.6 KiB
JavaScript
import { fireEvent, render, screen } from "@testing-library/react-native";
|
|
import { Checkbox } from "components/SharedComponents";
|
|
import React from "react";
|
|
import colors from "styles/tailwindColors";
|
|
import { renderComponent } from "tests/helpers/render";
|
|
|
|
const rerenderCheckmarkComponent = checked => {
|
|
renderComponent(
|
|
<Checkbox
|
|
accessibilityLabel="Checkmark"
|
|
text="Checkmark text"
|
|
isChecked={checked}
|
|
/>
|
|
);
|
|
const checkbox = screen.getByLabelText( /Checkmark/ );
|
|
expect( checkbox ).toHaveProp( "innerIconStyle", {
|
|
borderRadius: 6,
|
|
borderWidth: 2,
|
|
borderColor: colors.inatGreen
|
|
} );
|
|
};
|
|
|
|
describe( "Checkbox", () => {
|
|
it( "renders reliably", () => {
|
|
render( <Checkbox text="Checkmark text" /> );
|
|
|
|
// Disabled during the update to RN 0.78
|
|
// expect( screen ).toMatchSnapshot();
|
|
} );
|
|
|
|
it( "renders reliably being checked", () => {
|
|
render( <Checkbox text="Checkmark text" isChecked /> );
|
|
|
|
// Disabled during the update to RN 0.78
|
|
// expect( screen ).toMatchSnapshot();
|
|
} );
|
|
|
|
it( "has no accessibility errors", () => {
|
|
// const checkbox = <Checkbox accessibilityLabel="Checkmark" text="Checkmark text" isChecked />;
|
|
|
|
// Disabled during the update to RN 0.78
|
|
// expect( checkbox ).toBeAccessible();
|
|
} );
|
|
|
|
it( "renders an empty checkbox when isChecked is false", () => {
|
|
renderComponent(
|
|
<Checkbox
|
|
accessibilityLabel="Checkmark"
|
|
text="Checkmark text"
|
|
isChecked={false}
|
|
/>
|
|
);
|
|
|
|
const checkmark = screen.getByLabelText( /Checkmark/ );
|
|
|
|
expect( checkmark ).toBeTruthy( );
|
|
expect( checkmark ).toHaveProp( "innerIconStyle", {
|
|
borderRadius: 6,
|
|
borderWidth: 2,
|
|
borderColor: colors.darkGray
|
|
} );
|
|
} );
|
|
|
|
it( "renders a green filled checkbox when isChecked is true", () => {
|
|
renderComponent( <Checkbox accessibilityLabel="Checkmark" text="Checkmark text" isChecked /> );
|
|
|
|
const checkmark = screen.getByLabelText( /Checkmark/ );
|
|
expect( checkmark ).toHaveProp( "innerIconStyle", {
|
|
borderRadius: 6,
|
|
borderWidth: 2,
|
|
borderColor: colors.inatGreen
|
|
} );
|
|
} );
|
|
|
|
it( "changes value when user presses checkbox being not checked", () => {
|
|
let checked = false;
|
|
renderComponent(
|
|
<Checkbox
|
|
accessibilityLabel="Checkmark"
|
|
text="Checkmark text"
|
|
isChecked={checked}
|
|
// eslint-disable-next-line no-return-assign
|
|
onPress={( ) => ( checked = !checked )}
|
|
/>
|
|
);
|
|
const checkmark = screen.getByLabelText( /Checkmark/ );
|
|
|
|
expect( checked ).toBeFalsy( );
|
|
fireEvent.press( checkmark );
|
|
expect( checked ).toBeTruthy( );
|
|
rerenderCheckmarkComponent( checked );
|
|
} );
|
|
|
|
it( "changes value when user presses checkbox being checked", () => {
|
|
let checked = true;
|
|
renderComponent(
|
|
<Checkbox
|
|
accessibilityLabel="Checkmark"
|
|
text="Checkmark text"
|
|
isChecked={checked}
|
|
onPress={( ) => { checked = !checked; }}
|
|
/>
|
|
);
|
|
const checkmark = screen.getByLabelText( /Checkmark/ );
|
|
|
|
expect( checked ).toBeTruthy( );
|
|
fireEvent.press( checkmark );
|
|
expect( checked ).toBeFalsy( );
|
|
} );
|
|
|
|
it( "renders text and changes value when user presses text", () => {
|
|
let checked = false;
|
|
renderComponent(
|
|
<Checkbox
|
|
text="Checkmark text"
|
|
isChecked={checked}
|
|
onPress={( ) => { checked = !checked; }}
|
|
/>
|
|
);
|
|
|
|
const text = screen.getByText( /Checkmark text/ );
|
|
expect( text ).toBeVisible( );
|
|
expect( checked ).toBeFalsy( );
|
|
fireEvent.press( text );
|
|
expect( checked ).toBeTruthy( );
|
|
rerenderCheckmarkComponent( checked );
|
|
} );
|
|
} );
|