MOB-1345: tests

This commit is contained in:
sepeterson
2026-07-20 12:30:40 -05:00
parent 8beb115350
commit 3911b362bb
3 changed files with 48 additions and 0 deletions

View File

@@ -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", ( ) => {

View File

@@ -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( <ExploreV2Header /> );
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( <ExploreV2Header /> );

View File

@@ -382,6 +382,30 @@ describe( "UniversalSearch screen", ( ) => {
);
} );
it( "stages an unobserved subject when the unobserved row is tapped", async ( ) => {
renderComponent( <UniversalSearch /> );
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( <UniversalSearch /> );