Files
iNaturalistReactNative/tests/unit/components/ObsEdit/ObsEditHeader.test.js
Amanda Bullington bb31c1907b Update react navigation libraries for performance (#2903)
* Update navigators and create util for tabstack navigation

* Changes for react navigation 7

* Refactor to use navigateToTabStack throughout app

* Add comment about unmountOnBlur

* Get all unit tests passing; remove navutils & mock HeaderBackButton

* Fix animation issues in tests

* Temporarily remove parts of tests with back functionality

* Fix tests

* Delete ios/iNaturalistReactNative.xcodeproj/project.pbxproj

* Fix pbxproj

* Code cleanup; minimize unnecessary changes

* Fix tests

* Downgrade react-native-screens to v4.4.0 (#2918)

react-native-screens version 4.5.0 increases the react native version that it supports to 0.74.0+ (https://github.com/software-mansion/react-native-screens/pull/2613/files). So, by using 4.4.0 we are still able to build the app on Android as we are still on 0.73 for now (have tested and it works).
Have not seen any effect on the changes related to the latest react-navigation versions.

* Make requested changes

* Speed up Explore nearby tile loading (#2912)

* Create a performance tracker to show urltile load time in debug mode

* Set default radius to 1km, not 50km

* Code cleanup & TypeScript definitions

* Fix TypeError

* Address eslint error

* Make github actions happy

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>

* New Crowdin translations by GitHub Action (#2920)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>

* MOB-690 - Add error context to 401 errors (#2921)

* MOB-690 - Add error context to 401 errors

* Add Object.defineProperty like in the other error classes

* Add logger line

* Also throw 401 error if the error object has no response property

---------

Co-authored-by: Yaron Budowski <budowski@gmail.com>

* v1.0.4+164

* Rebase with latest version of RN screens. Remove unused code and packages, add eslint package for TS, suppress TS errors (#2924)

* New Crowdin translations by GitHub Action (#2926)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>

* New Crowdin translations by GitHub Action (#2929)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>

* Use 3 separate initial routes for tabs; hide animations on drawer screens

* Fix test

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
Co-authored-by: Ken-ichi <kenichi.ueda@gmail.com>
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: Yaron Budowski <budowski@gmail.com>
2025-05-30 09:26:47 -07:00

99 lines
2.6 KiB
JavaScript

import { screen } from "@testing-library/react-native";
import ObsEditHeader from "components/ObsEdit/ObsEditHeader";
import React from "react";
import { View } from "react-native";
import factory from "tests/factory";
import faker from "tests/helpers/faker";
import { renderComponent, wrapInNavigationContainer } from "tests/helpers/render";
// eslint-disable-next-line i18next/no-literal-string
const mockHeaderBackButton = <View testID="ObsEdit.BackButton">Mocked Back</View>;
// Note: HeaderBackButton has accessibility issues
jest.mock( "@react-navigation/elements", () => ( {
...jest.requireActual( "@react-navigation/elements" ),
HeaderBackButton: jest.fn()
.mockImplementation( ( ) => mockHeaderBackButton )
} ) );
const mockObservations = [
factory( "LocalObservation" ),
factory( "LocalObservation" )
];
describe( "ObsEditHeader", () => {
it( "has no accessibility errors", () => {
const button = wrapInNavigationContainer(
<ObsEditHeader
observations={mockObservations}
/>
);
expect( button ).toBeAccessible();
} );
it( "renders a header title with 1 observation", async () => {
renderComponent(
<ObsEditHeader
observations={[mockObservations[1]]}
/>
);
const headerText = await screen.findByText( /New Observation/ );
expect( headerText ).toBeVisible();
} );
it( "renders a header title with multiple observations", async () => {
renderComponent(
<ObsEditHeader
observations={mockObservations}
/>
);
const headerText = await screen.findByText( /2 Observations/ );
expect( headerText ).toBeVisible();
} );
it( "renders edit header title when observation is saved locally", async () => {
const observation = factory( "LocalObservation", {
_created_at: faker.date.past( )
} );
renderComponent(
<ObsEditHeader
currentObservation={observation}
observations={[observation]}
/>
);
const headerText = await screen.findByText( /Edit Observation/ );
expect( headerText ).toBeVisible();
} );
it( "renders a kebab menu", async () => {
renderComponent(
<ObsEditHeader
observations={mockObservations}
/>
);
const kebabLabel = await screen.findByLabelText( /Menu/ );
expect( kebabLabel ).toBeVisible();
} );
it( "renders a back button", () => {
renderComponent(
<ObsEditHeader
observations={mockObservations}
/>
);
const backButtonId = screen.getByTestId( "ObsEdit.BackButton" );
expect( backButtonId ).toBeVisible( );
} );
} );