mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-03 13:29:47 -04:00
* Do not filter out hidden comments and IDs when getting an obs from server * Do not add a filtered set of comments and IDs to local obs Searching for visibleComments and visibleIdentifications anyways gives 0 results outside this file. * Move file * Remove flow * Type fcts * Add a type to item * More types * Add field to RealmTaxon * Type navigation as used in ObsDetails * Update ActivityItem.tsx * Migrate FloatingButtons to TS * Change prop type * Rename ActivityHeader * Migrate ActivityHeaderKebabMenu to TS * Type functions * Add undefined as possibility from TextInputSheet callback * Revert "Add undefined as possibility from TextInputSheet callback" This reverts commit95b5fef2b9. * Revert "Type functions" This reverts commit6997f195ce. * Revert "Rename ActivityHeader" This reverts commite384c1f5a5. * Revert "Update ActivityItem.tsx" This reverts commitc1dc151b9a. * Revert "Add field to RealmTaxon" This reverts commit965af041c0. * Revert "More types" This reverts commit73af10bfcd. * Revert "Add a type to item" This reverts commit5e5bf0ebae. * Revert "Type fcts" This reverts commit84cac53e33. * Revert "Type navigation as used in ObsDetails" This reverts commit9febf9ea30. * Revert "Remove flow" This reverts commitdca054c212. * Revert "Move file" This reverts commitbf62c0db95. * Add UI for a hidden comment/ID * Rename export like file name * Update ID category text in tests * Ask for hidden status from API and persist in realm * Show fallback UI for hidden photos in PhotoContainer * Update strings.ftl * Show fallback UI for hidden sounds in SoundContainer * Change mock to remoteObservation Previously, this test file was relying on a faulty remoteObservation. The passed in remoteObservation was {} and because of the now removed filter code in useRemoteObservation what was passes into the test was {comments:[], identifications:[]} which made this test pass without ever using the useLocalObervation mock. * Add eye icon to photo * Add eye icon to sound * Add eye icon to comments/IDs
178 lines
5.5 KiB
JavaScript
178 lines
5.5 KiB
JavaScript
import { fireEvent, screen } from "@testing-library/react-native";
|
|
import ActivityHeader from "components/ObsDetailsSharedComponents/ActivityTab/ActivityHeader";
|
|
import { t } from "i18next";
|
|
import React from "react";
|
|
import factory from "tests/factory";
|
|
import faker from "tests/helpers/faker";
|
|
import { renderComponent } from "tests/helpers/render";
|
|
|
|
const mockUser = factory( "LocalUser", {
|
|
id: 0,
|
|
login: faker.internet.userName( ),
|
|
iconUrl: faker.image.url( ),
|
|
} );
|
|
|
|
describe( "ActivityHeaderKebabMenu", () => {
|
|
it( "renders kebab menu buttons", async ( ) => {
|
|
const mockId = factory( "LocalIdentification", {
|
|
uuid: "123456789",
|
|
user: mockUser,
|
|
category: "improving",
|
|
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: "improving",
|
|
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: "improving",
|
|
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: "improving",
|
|
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( );
|
|
} );
|
|
} );
|