MOB-512 minimal unit test fix and prop spreading allowed for tests

This commit is contained in:
sepeterson
2025-11-21 10:12:59 -06:00
parent cf53c791ad
commit 19cb7064a6
3 changed files with 47 additions and 7 deletions

View File

@@ -164,6 +164,12 @@ module.exports = {
"@typescript-eslint/no-require-imports": "off"
}
},
{
files: ["*.test.js", "*.test.tsx"],
rules: {
"react/jsx-props-no-spreading": "off"
}
},
{
files: ["**/__mocks__/**/*", "**/*mock*", "**/*.mock.*"],
rules: {

View File

@@ -1,7 +1,7 @@
import { screen, waitFor } from "@testing-library/react-native";
import ObsDetailsContainer from "components/ObsDetails/ObsDetailsContainer";
import DefaultModeObsDetailsContainer
from "components/ObsDetailsDefaultMode/ObsDetailsDefaultModeContainer";
import ObsDetailsDefaultModeScreensWrapper
from "components/ObsDetailsDefaultMode/ObsDetailsDefaultModeScreensWrapper";
import inatjs from "inaturalistjs";
import React from "react";
import Observation from "realmModels/Observation";
@@ -71,7 +71,7 @@ jest.mock( "@react-navigation/native", () => {
// Run the same suite of tests for multiple ObsDetails container
describe.each( [
{ Container: ObsDetailsContainer, name: "ObsDetailsContainer" },
{ Container: DefaultModeObsDetailsContainer, name: "DefaultModeObsDetailsContainer" }
{ Container: ObsDetailsDefaultModeScreensWrapper, name: "ObsDetailsDefaultModeScreensWrapper" }
] )( "ObsDetails", ( { Container, name } ) => {
beforeAll( async () => {
jest.useFakeTimers( );

View File

@@ -128,8 +128,32 @@ jest.mock( "sharedHooks/useObservationsUpdates", () => ( {
} ) )
} ) );
const renderObsDetails = ( ) => renderComponent(
<ObsDetailsContainer />
const mockRefetchRemoteObservation = jest.fn();
const mockMarkViewedLocally = jest.fn();
const mockMarkDeletedLocally = jest.fn();
const mockSetRemoteObsWasDeleted = jest.fn();
const defaultProps = {
belongsToCurrentUser: false,
currentUser: mockUser,
fetchRemoteObservationError: null,
isConnected: true,
isRefetching: false,
isSimpleMode: false,
localObservation: null,
markDeletedLocally: mockMarkDeletedLocally,
markViewedLocally: mockMarkViewedLocally,
observation: mockObservation,
refetchRemoteObservation: mockRefetchRemoteObservation,
remoteObservation: mockObservation,
remoteObsWasDeleted: false,
setRemoteObsWasDeleted: mockSetRemoteObsWasDeleted,
targetActivityItemID: null,
uuid: mockObservation.uuid
};
const renderObsDetails = ( props = {} ) => renderComponent(
<ObsDetailsContainer {...defaultProps} {...props} />
);
describe( "ObsDetails", () => {
@@ -156,7 +180,11 @@ describe( "ObsDetails", () => {
} );
it( "should render fallback image icon instead of photos", async () => {
renderObsDetails( );
renderObsDetails( {
observation: mockNoEvidenceObservation,
remoteObservation: mockNoEvidenceObservation,
uuid: mockNoEvidenceObservation.uuid
} );
const labelText = t( "Observation-has-no-photos-and-no-sounds" );
const fallbackImage = await screen.findByLabelText( labelText );
@@ -194,7 +222,13 @@ describe( "ObsDetails", () => {
} );
jest.spyOn( useCurrentUser, "default" ).mockImplementation( () => mockUser );
renderObsDetails( );
renderObsDetails( {
observation: otherUserObservation,
remoteObservation: otherUserObservation,
uuid: otherUserObservation.uuid,
belongsToCurrentUser: false,
localObservation: null
} );
const agreeButton = screen.getByTestId(
`ActivityItem.AgreeIdButton.${firstIdentification.taxon.id}`
);