Files
iNaturalistReactNative/tests/unit/components/ObsEdit/BottomButtons.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

63 lines
1.8 KiB
JavaScript

import { faker } from "@faker-js/faker";
import { screen } from "@testing-library/react-native";
import BottomButtons from "components/ObsEdit/BottomButtons";
import initI18next from "i18n/initI18next";
import React from "react";
import * as useCurrentUser from "sharedHooks/useCurrentUser";
import factory from "tests/factory";
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", () => {
beforeAll( async ( ) => {
await initI18next( );
} );
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( );
} );
} );