diff --git a/tests/unit/components/Explore/ExploreV2/buildQueryParams.test.js b/tests/unit/components/Explore/ExploreV2/buildQueryParams.test.js index e84c419c0..ec85a0b62 100644 --- a/tests/unit/components/Explore/ExploreV2/buildQueryParams.test.js +++ b/tests/unit/components/Explore/ExploreV2/buildQueryParams.test.js @@ -37,6 +37,17 @@ describe( "buildExploreV2QueryParams", ( ) => { const params = buildExploreV2QueryParams( state ); expect( params.project_id ).toBe( 12 ); } ); + + it( "maps an unobserved subject to unobserved_by_user_id", ( ) => { + const state = { + ...initialExploreV2State, + subject: { type: "unobserved", user: { id: 99 } }, + }; + const params = buildExploreV2QueryParams( state ); + expect( params.unobserved_by_user_id ).toBe( 99 ); + expect( params.user_id ).toBeUndefined( ); + expect( params.taxon_id ).toBeUndefined( ); + } ); } ); describe( "location", ( ) => { diff --git a/tests/unit/components/Explore/ExploreV2/components/ExploreV2Header.test.js b/tests/unit/components/Explore/ExploreV2/components/ExploreV2Header.test.js index 09b709ef3..6f220b089 100644 --- a/tests/unit/components/Explore/ExploreV2/components/ExploreV2Header.test.js +++ b/tests/unit/components/Explore/ExploreV2/components/ExploreV2Header.test.js @@ -124,6 +124,19 @@ describe( "ExploreV2Header", () => { expect( screen.getByTestId( "IconicTaxonName.iconicTaxonIcon" ) ).toBeTruthy(); } ); + it( "renders the Unobserved title and location without a subject thumbnail", () => { + setState( + { type: "unobserved", user: { id: 7, login: "seth_msp" } }, + { placeMode: EXPLORE_V2_PLACE_MODE.WORLDWIDE }, + ); + renderComponent( ); + + expect( screen.getByText( "Unobserved" ) ).toBeTruthy(); + expect( screen.getByText( "Worldwide" ) ).toBeTruthy(); + expect( screen.getByTestId( "ExploreV2Header.unobserved" ) ).toBeTruthy(); + expect( screen.queryByTestId( "ExploreV2Header.subject" ) ).toBeNull(); + } ); + it( "renders only the place name when there is no subject", () => { setState( null ); renderComponent( ); diff --git a/tests/unit/components/Explore/ExploreV2/screens/UniversalSearch.test.js b/tests/unit/components/Explore/ExploreV2/screens/UniversalSearch.test.js index 2daccd82d..631c63c7b 100644 --- a/tests/unit/components/Explore/ExploreV2/screens/UniversalSearch.test.js +++ b/tests/unit/components/Explore/ExploreV2/screens/UniversalSearch.test.js @@ -382,6 +382,30 @@ describe( "UniversalSearch screen", ( ) => { ); } ); + it( "stages an unobserved subject when the unobserved row is tapped", async ( ) => { + renderComponent( ); + + await actor.press( screen.getByTestId( "DefaultSearchOptions.unobserved" ) ); + + // the selection is staged locally, not written to context until Search + expect( mockDispatch ).not.toHaveBeenCalled( ); + // the subject field shows the "Species I haven't observed" label + expect( + screen.getByDisplayValue( i18next.t( "Species-I-havent-observed" ) ), + ).toBeTruthy( ); + + await actor.press( screen.getByTestId( "UniversalSearch.searchButton" ) ); + expect( mockDispatch ).toHaveBeenCalledWith( + expect.objectContaining( { + type: "SET_SUBJECT", + subject: expect.objectContaining( { + type: "unobserved", + user: expect.objectContaining( { id: 99 } ), + } ), + } ), + ); + } ); + it( "hides the current user row when logged out", ( ) => { useCurrentUser.mockReturnValue( null ); renderComponent( );