mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-01-01 10:28:40 -05:00
* Create ObsDetailsDefaultMode and rearrange items on top of screen * Move activity, details, and more into three different sections instead of tabs * Styling cleanup; change Activity name to Community * Fix scroll to activity item from Notifications * Add ObsDetailsDefaultMode unit tests * Show kebab menu on other users' observations
67 lines
2.6 KiB
JavaScript
67 lines
2.6 KiB
JavaScript
import { fireEvent, screen } from "@testing-library/react-native";
|
|
import HeaderKebabMenu from "components/ObsDetailsDefaultMode/HeaderKebabMenu";
|
|
import i18next from "i18next";
|
|
import React from "react";
|
|
import { Platform, Share } from "react-native";
|
|
import { renderComponent } from "tests/helpers/render";
|
|
|
|
jest.mock( "react-native/Libraries/Share/Share", () => ( {
|
|
share: jest.fn( () => Promise.resolve( "mockResolve" ) )
|
|
} ) );
|
|
|
|
jest.mock( "react-native/Libraries/Utilities/Platform", ( ) => ( {
|
|
OS: "ios",
|
|
select: jest.fn( )
|
|
} ) );
|
|
|
|
const observationId = 1234;
|
|
const url = `https://www.inaturalist.org/observations/${observationId}`;
|
|
|
|
describe( "HeaderKebabMenu", () => {
|
|
it( "renders and opens kebab menu share button", async ( ) => {
|
|
renderComponent( <HeaderKebabMenu observationId={observationId} /> );
|
|
const anchorButton = screen.getByLabelText( i18next.t( "Observation-options" ) );
|
|
expect( anchorButton ).toBeTruthy( );
|
|
fireEvent.press( anchorButton );
|
|
const shareButton = await screen.findByTestId( "MenuItem.Share" );
|
|
expect( shareButton ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "opens native share dialog with expected url", async ( ) => {
|
|
renderComponent( <HeaderKebabMenu observationId={observationId} /> );
|
|
const anchorButton = screen.getByLabelText( i18next.t( "Observation-options" ) );
|
|
expect( anchorButton ).toBeTruthy( );
|
|
fireEvent.press( anchorButton );
|
|
const shareButton = await screen.findByTestId( "MenuItem.Share" );
|
|
expect( shareButton ).toBeTruthy( );
|
|
fireEvent.press( shareButton );
|
|
expect( Share.share ).toHaveBeenCalledTimes( 1 );
|
|
expect( Share.share ).toHaveBeenCalledWith( { message: "", url } );
|
|
} );
|
|
|
|
const defaultPlatformOS = Platform.OS;
|
|
|
|
describe( "on Android", ( ) => {
|
|
// TODO change this to a less brittle and sweeping approach. Some ideas at
|
|
// https://stackoverflow.com/questions/43161416/mocking-platform-detection-in-jest-and-react-native
|
|
beforeAll( ( ) => {
|
|
Platform.OS = "android";
|
|
} );
|
|
|
|
afterAll( ( ) => {
|
|
Platform.OS = defaultPlatformOS;
|
|
} );
|
|
|
|
it( "opens native share dialog with expected message", async ( ) => {
|
|
renderComponent( <HeaderKebabMenu observationId={observationId} /> );
|
|
const anchorButton = screen.getByLabelText( i18next.t( "Observation-options" ) );
|
|
expect( anchorButton ).toBeTruthy( );
|
|
fireEvent.press( anchorButton );
|
|
const shareButton = await screen.findByTestId( "MenuItem.Share" );
|
|
expect( shareButton ).toBeTruthy( );
|
|
fireEvent.press( shareButton );
|
|
expect( Share.share ).toHaveBeenCalledWith( { message: url, url: "" } );
|
|
} );
|
|
} );
|
|
} );
|