mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-21 14:08:31 -04:00
* Restyle community taxon section * Use fave/unfave mutation in case of need_id metric * Add votes field to Observation * Change useIsConnected to TS * Refactor fetching of remote observation into hook Also includes the code to update local copy of a user's own observation * Use const as key instead of string * Remove unused prop * Only send obs uuid to DQA * Get obs in DQA container * Rebuild object that is to check as it was send in nav params * Refactor qualityGrade * Refactor set to not loading state * Update test to reflect fetching of obs * Refactor too long lines * Refetch remote observation after success in adding/removing vote * Change qualitcMetrics to make use of observation.votes as well Also refactored the object structure to use more efficient and performant filtering and finding in child components. * Only use data slice for DQA buttons * Refactor DQAButtons to only work with data slice relevant to that metric * Special case for needs_id metric * Also show loading indicator when fetching remote obs * Add TODO * Check only for vote of this user * Optional chaining for user id * Update test * Enable fetching of remote if local is falsy * Invalidate query on mutation * Only set loading to false after refetch is finished * Split up DQA test into unit tests and integration tests * Use factory for mock user * Add needs_id DQAVoteButtons unit test * Revert hook to js * Check for observation before using it * Undo code style changes * Remove unused value * Refactor faves to be derived from votes * Refactor needs_id interaction into standalone fcts * Code style
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
import { screen } from "@testing-library/react-native";
|
|
import CustomTabBarContainer from "navigation/BottomTabNavigator/CustomTabBarContainer";
|
|
import React from "react";
|
|
import * as useCurrentUser from "sharedHooks/useCurrentUser";
|
|
import * as useIsConnected from "sharedHooks/useIsConnected.ts";
|
|
import factory from "tests/factory";
|
|
import faker from "tests/helpers/faker";
|
|
import { renderComponent } from "tests/helpers/render";
|
|
|
|
const mockUser = factory( "LocalUser", {
|
|
login: faker.internet.userName( ),
|
|
icon_url: faker.image.url( )
|
|
} );
|
|
|
|
jest.mock( "sharedHooks/useCurrentUser", ( ) => ( {
|
|
__esModule: true,
|
|
default: () => undefined
|
|
} ) );
|
|
|
|
jest.mock( "sharedHooks/useAuthenticatedQuery", () => ( {
|
|
__esModule: true,
|
|
default: () => ( {
|
|
data: 0
|
|
} )
|
|
} ) );
|
|
|
|
describe( "CustomTabBar", () => {
|
|
beforeEach( ( ) => {
|
|
jest.useFakeTimers();
|
|
} );
|
|
|
|
it( "should render correctly", async () => {
|
|
renderComponent( <CustomTabBarContainer navigation={jest.fn( )} /> );
|
|
|
|
await expect( screen ).toMatchSnapshot();
|
|
} );
|
|
|
|
it( "should not have accessibility errors", async () => {
|
|
const tabBar = <CustomTabBarContainer navigation={jest.fn( )} />;
|
|
|
|
await expect( tabBar ).toBeAccessible();
|
|
} );
|
|
|
|
it( "should display person icon while user is logged out", async () => {
|
|
renderComponent( <CustomTabBarContainer navigation={jest.fn( )} isOnline /> );
|
|
|
|
const personIcon = screen.getByTestId( "NavButton.personIcon" );
|
|
await expect( personIcon ).toBeVisible( );
|
|
} );
|
|
|
|
it( "should display avatar while user is logged in", async () => {
|
|
jest.spyOn( useCurrentUser, "default" ).mockImplementation( () => mockUser );
|
|
renderComponent( <CustomTabBarContainer navigation={jest.fn( )} isOnline /> );
|
|
|
|
const avatar = screen.getByTestId( "UserIcon.photo" );
|
|
await expect( avatar ).toBeVisible( );
|
|
} );
|
|
|
|
it( "should display person icon when connectivity is low", async ( ) => {
|
|
jest.spyOn( useIsConnected, "default" ).mockImplementation( () => false );
|
|
renderComponent( <CustomTabBarContainer navigation={jest.fn( )} isOnline={false} /> );
|
|
|
|
const personIcon = screen.getByTestId( "NavButton.personIcon" );
|
|
await expect( personIcon ).toBeVisible( );
|
|
} );
|
|
} );
|