Files
iNaturalistReactNative/tests/unit/components/SharedComponents/HideView.test.js
Johannes Klein f10188250c Some Flow to Typescript migrations, in simple components (#3034)
* Update Attribution.tsx

* Update FollowButton.tsx

* Update LoginSheet.tsx

* Update UnfollowSheet.tsx

* Update UnfollowSheet.tsx

* Update EstablishmentMeans.tsx

* Update TaxonDetailsTitle.tsx

* Update Taxonomy.tsx

* Update TaxonMapPreview.tsx

* Update FullScreenActivityIndicator.tsx

* Update ActivityIndicator.tsx

* Update SpeciesSeenCheckmark.tsx

* Update Mortal.tsx

* Update HideView.tsx

* Update ConfidenceInterval.tsx

* Update ViewWrapper.tsx

* Update ScrollViewWrapper.tsx

* Update SimpleObservationLocation.tsx

* Update Divider.tsx

* Update DateTimePicker.tsx

* Update MediaNavButtons.tsx

* Update MediaNavButtons.tsx

* Update MediaNavButtons.tsx

* Update DisplayTaxon.tsx

* Update InputField.tsx

* Update InputField.tsx

* Update ObservationLocation.tsx

* Update WarningText.tsx

* Update LoadingIndicator.tsx

* Update CrosshairCircle.tsx

* Update CoordinatesCopiedNotification.tsx

* Update PhotoSharing.tsx

* Update TaxonDetailsMediaViewerHeader.tsx

* Update EvidenceButton.tsx

* Update TextSheet.tsx

* Update Wikipedia.tsx

* Update About.tsx

* Update About.tsx

* Update imports

* Code style
2025-08-01 12:25:46 +02:00

59 lines
1.3 KiB
JavaScript

import { render, screen } from "@testing-library/react-native";
import HideView from "components/SharedComponents/HideView.tsx";
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, { includeHiddenElements: true } )
).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();
} );
} );