Files
iNaturalistReactNative/tests/unit/components/Camera/CameraContainer.test.js
Amanda Bullington 808cbee452 Replace ObsEditProvider with zustand for global state management (#948)
* Add zustand to app

* Begin replacing ObsEditProvider with zustand for global state

* Use store and add tests

* Fix bugs

* Add test to check for deleted photos in StandardCamera

* Make sure evidence is only added to current observation; submit comment with ID on ObsDetail

* Fix ObsEditWithoutProvider tests

* Move store to where it's needed

* Fix tests

* Await evidence being added to obsPhotos from camera

* Add a note about slices to useStore
2023-12-05 14:10:00 -08:00

96 lines
2.2 KiB
JavaScript

import {
fireEvent, render, screen
} from "@testing-library/react-native";
import CameraContainer from "components/Camera/CameraContainer";
import initI18next from "i18n/initI18next";
import INatPaperProvider from "providers/INatPaperProvider";
import React from "react";
import { View } from "react-native";
import factory from "../../../factory";
const mockedNavigate = jest.fn();
const mockTaxon = factory( "RemoteTaxon" );
jest.mock( "sharedHooks/useAuthenticatedQuery", () => ( {
__esModule: true,
default: () => ( {
data: mockTaxon
} )
} ) );
jest.mock( "@react-navigation/native", () => {
const actualNav = jest.requireActual( "@react-navigation/native" );
return {
...actualNav,
useNavigation: () => ( {
navigate: mockedNavigate,
addListener: () => {}
} ),
useRoute: () => ( {} ),
useFocusEffect: () => ( {} )
};
} );
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/StandardCamera/PhotoPreview", () => ( {
__esModule: true,
default: () => mockView
} ) );
jest.mock( "components/Camera/ARCamera/FrameProcessorCamera", () => ( {
__esModule: true,
default: () => mockView
} ) );
const renderCameraContainer = () => render(
<INatPaperProvider>
<CameraContainer />
</INatPaperProvider>
);
describe( "CameraContainer", ( ) => {
beforeAll( async ( ) => {
await initI18next();
jest.useFakeTimers( );
} );
it( "should not have accessibility errors", () => {
const Camera = (
<INatPaperProvider>
<CameraContainer />
</INatPaperProvider>
);
expect( Camera ).toBeAccessible();
} );
it( "should first render with flash disabled", async () => {
renderCameraContainer();
await screen.findByTestId( "flash-button-label-flash-off" );
} );
it( "should change to flash enabled on button press", async () => {
renderCameraContainer();
const flashButton = await screen.findByTestId(
"flash-button-label-flash-off"
);
fireEvent.press( flashButton );
await screen.findByTestId( "flash-button-label-flash" );
} );
} );