mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-21 05:58:37 -04:00
* 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
183 lines
5.6 KiB
JavaScript
183 lines
5.6 KiB
JavaScript
import { faker } from "@faker-js/faker";
|
|
import { fireEvent, screen } from "@testing-library/react-native";
|
|
import ActivityHeader from "components/ObsDetails/ActivityTab/ActivityHeader";
|
|
import initI18next from "i18n/initI18next";
|
|
import { t } from "i18next";
|
|
import React from "react";
|
|
import factory from "tests/factory";
|
|
import { renderComponent } from "tests/helpers/render";
|
|
|
|
const mockUser = factory( "LocalUser", {
|
|
id: 0,
|
|
login: faker.internet.userName( ),
|
|
iconUrl: faker.image.url( )
|
|
} );
|
|
|
|
describe( "ActivityHeaderKebabMenu", () => {
|
|
beforeAll( async ( ) => {
|
|
await initI18next( );
|
|
} );
|
|
|
|
it( "renders kebab menu buttons", async ( ) => {
|
|
const mockId = factory( "LocalIdentification", {
|
|
uuid: "123456789",
|
|
user: mockUser,
|
|
category: "Identification",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} ),
|
|
current: true
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "renders correct kebab menu for non-withdrawn id from current user", async ( ) => {
|
|
const mockId = factory( "LocalIdentification", {
|
|
uuid: "123456789",
|
|
user: mockUser,
|
|
category: "Identification",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} ),
|
|
current: true
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
fireEvent.press( await screen.findByTestId( "KebabMenu.Button" ) );
|
|
expect( await screen.findByText( "Withdraw" ) ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "renders correct kebab menu for withdrawn id from current user", async ( ) => {
|
|
const mockId = factory( "LocalIdentification", {
|
|
uuid: "123456789",
|
|
user: mockUser,
|
|
category: "Identification",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} ),
|
|
current: false
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
fireEvent.press( await screen.findByTestId( "KebabMenu.Button" ) );
|
|
expect( await screen.findByText( "Restore" ) ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "renders correct kebab menu for comment from current user", async ( ) => {
|
|
const mockId = factory( "LocalComment", {
|
|
body: "hello",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} )
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
fireEvent.press( await screen.findByTestId( "KebabMenu.Button" ) );
|
|
expect( await screen.findByText( t( "Edit-comment" ) ) ).toBeTruthy( );
|
|
expect( await screen.findByText( t( "Edit-comment" ) ) ).toBeTruthy( );
|
|
} );
|
|
it( "renders WithdrawIDSheet when withdraw is pressed", async ( ) => {
|
|
const mockId = factory( "LocalIdentification", {
|
|
uuid: "123456789",
|
|
user: mockUser,
|
|
category: "Identification",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} ),
|
|
current: true
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
fireEvent.press( await screen.findByTestId( "KebabMenu.Button" ) );
|
|
fireEvent.press( await screen.findByText( t( "Withdraw" ) ) );
|
|
expect( await screen.findByText( t( "WITHDRAW-ID-QUESTION" ) ) ).toBeTruthy( );
|
|
} );
|
|
|
|
it( "renders delete comment sheet when delete comment is pressed", async ( ) => {
|
|
const mockId = factory( "LocalComment", {
|
|
body: "hello",
|
|
taxon: factory( "LocalTaxon", {
|
|
name: "Miner's Lettuce"
|
|
} )
|
|
} );
|
|
renderComponent(
|
|
<ActivityHeader
|
|
item={mockId}
|
|
currentUser
|
|
idWithdrawn={false}
|
|
flagged={false}
|
|
updateCommentBody={jest.fn()}
|
|
deleteComment={jest.fn()}
|
|
withdrawOrRestoreIdentification={jest.fn()}
|
|
onItemFlagged={jest.fn()}
|
|
/>
|
|
);
|
|
|
|
expect( await screen.findByTestId( "KebabMenu.Button" ) ).toBeTruthy( );
|
|
fireEvent.press( await screen.findByTestId( "KebabMenu.Button" ) );
|
|
fireEvent.press( await screen.findByText( t( "Delete-comment" ) ) );
|
|
expect( await screen.findByText( t( "DELETE-COMMENT-QUESTION" ) ) ).toBeTruthy( );
|
|
} );
|
|
} );
|