mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-01-07 05:19:08 -05:00
* Create view hider component * Fix logic to be easier to use on consumer side * Add tests * Fix errors and tests --------- Co-authored-by: Amanda Bullington <35536439+albullington@users.noreply.github.com> Co-authored-by: Amanda Bullington <albullington@gmail.com>
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { render, screen } from "@testing-library/react-native";
|
|
import HideView from "components/SharedComponents/HideView";
|
|
import React, { useEffect } from "react";
|
|
import { Text } from "react-native";
|
|
|
|
const testFunc = jest.fn();
|
|
|
|
const TEST_TEXT = "Centipedes";
|
|
|
|
const TestComponent = () => {
|
|
useEffect( () => {
|
|
testFunc();
|
|
}, [] );
|
|
|
|
return <Text>{TEST_TEXT}</Text>;
|
|
};
|
|
|
|
describe( "HideView", () => {
|
|
afterEach( () => {
|
|
jest.clearAllMocks();
|
|
} );
|
|
|
|
test( "should show component correctly", () => {
|
|
render(
|
|
<HideView show>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).toHaveBeenCalledTimes( 1 );
|
|
|
|
expect( screen.queryByText( TEST_TEXT ) ).toBeVisible();
|
|
} );
|
|
|
|
test( "should hide component correctly", () => {
|
|
render(
|
|
<HideView show={false}>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).toHaveBeenCalledTimes( 1 );
|
|
expect( screen.queryByText( TEST_TEXT ) ).not.toBeVisible();
|
|
} );
|
|
|
|
test( "should not render hidden component", () => {
|
|
render(
|
|
<HideView show={false} noInitialRender>
|
|
<TestComponent />
|
|
</HideView>
|
|
);
|
|
|
|
expect( testFunc ).not.toHaveBeenCalled();
|
|
expect( screen.queryByText( TEST_TEXT ) ).not.toBeTruthy();
|
|
} );
|
|
} );
|