Files
iNaturalistReactNative/tests/unit/components/Camera/CameraContainer.test.js
Ken-ichi f7dc08a704 Suggestions fixes (#972)
* Bugfix: TaxonDetails was crashing if it received a null taxon
* Send lat and lng instead of latitude and longitude to the score_image
  endpoint
* Show offline suggestions when you are offline
* Show notice when viewing offline suggestions
* Moved code unique to useOnlineSuggestions into that file
* Ensure we use a medium size image to get suggestions when dealing with
  remote URLs
* More logging around React Query retries
* Use default retry logic for useAuthenticatedQuery
* Made a module-resolver shortcut for tests
* Move offline notice above top suggestion; hide when offlines exist but onlines do too
2023-12-15 19:58:12 -08:00

95 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 "tests/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" );
} );
} );