Files
iNaturalistReactNative/tests/unit/components/ObsEdit/BottomButtons.test.js
Ken-ichi f3bcec2d2e Continuous location fetch in the cameras (#1673)
* Fetch location continuously in cameras until accuracy falls below threshold
* Unit test for useUserLocation
* Added untilAcc option to useUserLocation
* Bugfix: ObsEdit was not always fetching location for new camera photos

Closes #1340
2024-06-12 11:18:12 -07:00

58 lines
1.7 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import BottomButtons from "components/ObsEdit/BottomButtons";
import React from "react";
import * as useCurrentUser from "sharedHooks/useCurrentUser.ts";
import factory from "tests/factory";
import faker from "tests/helpers/faker";
import { renderComponent } from "tests/helpers/render";
const mockObservation = factory( "LocalObservation", {
_synced_at: faker.date.past( )
} );
const mockUser = factory( "LocalUser" );
jest.mock( "sharedHooks/useCurrentUser", () => ( {
__esModule: true,
default: ( ) => null
} ) );
describe( "BottomButtons", () => {
it( "has no accessibility errors", () => {
const bottomButtons = (
<BottomButtons />
);
expect( bottomButtons ).toBeAccessible();
} );
it( "shows save button when user is logged out", () => {
renderComponent( <BottomButtons /> );
const save = screen.getByText( /SAVE/ );
expect( save ).toBeVisible( );
} );
it( "shows save changes button when user logged in and observation was previously synced", () => {
jest.spyOn( useCurrentUser, "default" ).mockImplementation( ( ) => mockUser );
renderComponent( <BottomButtons
currentObservation={mockObservation}
/> );
const saveChanges = screen.getByText( /SAVE CHANGES/ );
expect( saveChanges ).toBeVisible( );
} );
it( "shows save and upload button when user logged in with new observation", () => {
jest.spyOn( useCurrentUser, "default" ).mockImplementation( ( ) => mockUser );
renderComponent( <BottomButtons /> );
const save = screen.getByText( /SAVE/ );
expect( save ).toBeVisible( );
const upload = screen.getByText( /UPLOAD/ );
expect( upload ).toBeVisible( );
} );
} );