mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-19 21:18:35 -04:00
* 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
66 lines
1.6 KiB
JavaScript
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" );
|
|
} );
|
|
} );
|