Files
iNaturalistReactNative/tests/unit/components/Camera/StandardCamera.test.js
Johannes Klein 7324117869 266 flash icon change (#271)
* Add script to clean start
* Add function to camera mock
* Basic StandardCamera test setup
* Display flash off icon in camera
* Add accessibility labels to strings
* Change to use testID for tests
* Rename package script
* Update vision-camera mock
2022-12-13 15:41:46 -08:00

66 lines
1.6 KiB
JavaScript

import { fireEvent, render, screen } from "@testing-library/react-native";
import StandardCamera from "components/Camera/StandardCamera";
import { ObsEditContext } from "providers/contexts";
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
} ),
useRoute: () => ( {} )
};
} );
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(
<ObsEditContext.Provider value={mockValue}>
<StandardCamera />
</ObsEditContext.Provider>
);
describe( "StandardCamera", ( ) => {
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" );
} );
} );