Files
iNaturalistReactNative/tests/unit/components/Camera/StandardCamera.test.js
Amanda Bullington c623c02272 Refactor DiscardChangesSheet and show only when leaving screen (#562)
* Only render bottom sheet when needed; refactor; fixes #556

* Fix test: add useFocusEffect to mocked nav
2023-03-31 10:26:23 -07:00

83 lines
2.1 KiB
JavaScript

import { fireEvent, render, screen } from "@testing-library/react-native";
import StandardCamera from "components/Camera/StandardCamera";
import { ObsEditContext } from "providers/contexts";
import INatPaperProvider from "providers/INatPaperProvider";
import React from "react";
import { View } from "react-native";
const mockedNavigate = jest.fn();
jest.mock( "@react-navigation/native", () => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useNavigation: () => ( {
navigate: mockedNavigate,
addListener: () => {}
} ),
useRoute: () => ( {} ),
useFocusEffect: () => ( {} )
};
} );
const mockValue = {
addCameraPhotosToCurrentObservation: jest.fn(),
allObsPhotoUris: [],
cameraPreviewUris: []
};
const mockView = <View />;
jest.mock( "components/Camera/CameraView", () => ( {
__esModule: true,
default: ( ) => mockView
} ) );
jest.mock( "components/Camera/FadeInOutView", () => ( {
__esModule: true,
default: () => mockView
} ) );
jest.mock( "components/Camera/PhotoPreview", () => ( {
__esModule: true,
default: () => mockView
} ) );
const renderStandardCamera = () => render(
<INatPaperProvider>
<ObsEditContext.Provider value={mockValue}>
<StandardCamera />
</ObsEditContext.Provider>
</INatPaperProvider>
);
describe( "StandardCamera", ( ) => {
test( "should not have accessibility errors", () => {
const standardCamera = (
<INatPaperProvider>
<ObsEditContext.Provider value={mockValue}>
<StandardCamera />
</ObsEditContext.Provider>
</INatPaperProvider>
);
expect( standardCamera ).toBeAccessible();
} );
test( "should first render with flash disabled", async () => {
renderStandardCamera();
await screen.findByTestId( "flash-button-label-flash-off" );
} );
test( "should change to flash enabled on button press", async () => {
renderStandardCamera();
const flashButton = await screen.findByTestId(
"flash-button-label-flash-off"
);
fireEvent.press( flashButton );
await screen.findByTestId( "flash-button-label-flash" );
} );
} );