Files
iNaturalistReactNative/tests/integration/DataQualityAssesment/DataQualityAssessment.test.js
Johannes Klein 4ccf8e6cae Fallback UI for hidden content (#3628)
* 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 commit 95b5fef2b9.

* Revert "Type functions"

This reverts commit 6997f195ce.

* Revert "Rename ActivityHeader"

This reverts commit e384c1f5a5.

* Revert "Update ActivityItem.tsx"

This reverts commit c1dc151b9a.

* Revert "Add field to RealmTaxon"

This reverts commit 965af041c0.

* Revert "More types"

This reverts commit 73af10bfcd.

* Revert "Add a type to item"

This reverts commit 5e5bf0ebae.

* Revert "Type fcts"

This reverts commit 84cac53e33.

* Revert "Type navigation as used in ObsDetails"

This reverts commit 9febf9ea30.

* Revert "Remove flow"

This reverts commit dca054c212.

* Revert "Move file"

This reverts commit bf62c0db95.

* 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
2026-05-20 00:47:34 +02:00

95 lines
2.9 KiB
JavaScript

import { useRoute } from "@react-navigation/native";
import { fireEvent, screen } from "@testing-library/react-native";
import DQAContainer from "components/ObsDetails/DQAContainer";
import React from "react";
import factory from "tests/factory";
import faker from "tests/helpers/faker";
import { renderComponent } from "tests/helpers/render";
const mockObservation = factory( "LocalObservation", {
observed_on: "2023-12-14T21:07:41-09:30",
observationPhotos: [factory( "LocalObservationPhoto" )],
latitude: Number( faker.location.latitude( ) ),
longitude: Number( faker.location.longitude( ) ),
taxon: {
id: undefined,
rank_level: undefined,
},
identifications: [],
// casual is the default, so using needs_id here ensures test
// is using our mock observation, not just showing the default screen
quality_grade: "needs_id",
votes: [],
} );
const mockUserID = "some_user_id";
// Mock useCurrentUser hook
jest.mock( "sharedHooks/useCurrentUser", ( ) => ( {
__esModule: true,
default: jest.fn( ( ) => ( {
id: mockUserID,
} ) ),
} ) );
jest.mock( "sharedHooks/useAuthenticatedQuery", () => ( {
__esModule: true,
default: () => ( {
data: [],
} ),
} ) );
const mockMutate = jest.fn();
jest.mock( "sharedHooks/useAuthenticatedMutation", () => ( {
__esModule: true,
default: () => ( {
mutate: mockMutate,
} ),
} ) );
jest.mock( "sharedHooks/useRemoteObservation", () => ( {
__esModule: true,
default: jest.fn( ( ) => ( {
remoteObservation: mockObservation,
} ) ),
} ) );
useRoute.mockImplementation( ( ) => ( {
params: {
observationUUID: mockObservation.uuid,
},
} ) );
async function expectMutateToHaveBeenCalled() {
expect( await mockMutate ).toHaveBeenCalled();
// Since we mocked the mutate() method, we're expecting mutation not to
// succeed. We want to wait for this so there are no extra things happening
// outside of act()
screen.queryByText( "ERROR LOADING IN DQA" );
}
describe( "DQA Vote Buttons", ( ) => {
beforeEach( ( ) => {
jest.useFakeTimers( );
} );
test( "renders DQA vote buttons", async ( ) => {
renderComponent( <DQAContainer /> );
const emptyDisagreeButtons = await screen.findAllByTestId( "DQAVoteButton.EmptyDisagree" );
expect( emptyDisagreeButtons ).toBeTruthy( );
} );
test( "calls api when DQA disagree button is pressed", async ( ) => {
renderComponent( <DQAContainer /> );
const emptyDisagreeButtons = await screen.findAllByTestId( "DQAVoteButton.EmptyDisagree" );
fireEvent.press( emptyDisagreeButtons[0] );
await expectMutateToHaveBeenCalled();
} );
test( "calls api when DQA agree button is pressed", async ( ) => {
renderComponent( <DQAContainer /> );
const emptyDisagreeButtons = await screen.findAllByTestId( "DQAVoteButton.EmptyAgree" );
fireEvent.press( emptyDisagreeButtons[0] );
await expectMutateToHaveBeenCalled();
} );
} );