From 03d6d5a8664bf4562d26925374873322f6889c7a Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Thu, 11 Jun 2026 15:59:50 -0700 Subject: [PATCH 1/7] add myobs reducer, action enum, initial state, provider and hook --- src/providers/MyObservationsContext.tsx | 106 ++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/providers/MyObservationsContext.tsx diff --git a/src/providers/MyObservationsContext.tsx b/src/providers/MyObservationsContext.tsx new file mode 100644 index 000000000..3f315763c --- /dev/null +++ b/src/providers/MyObservationsContext.tsx @@ -0,0 +1,106 @@ +import * as React from "react"; +import { OBSERVATIONS_SORT } from "sharedHelpers/observationsSort"; +import { SPECIES_SORT } from "sharedHelpers/speciesSort"; + +export enum MY_OBSERVATIONS_ACTION { + SET_OBSERVATIONS_SORT = "SET_OBSERVATIONS_SORT", + SET_SPECIES_SORT = "SET_SPECIES_SORT", + SET_TAXON_SEARCH = "SET_TAXON_SEARCH", + CLEAR_TAXON_SEARCH = "CLEAR_TAXON_SEARCH", +} + +export interface MyObservationsTaxon { + id: number; + name?: string; + preferred_common_name?: string; +} + +export interface MyObservationsState { + observationsSort: OBSERVATIONS_SORT; + speciesSort: SPECIES_SORT; + searchedTaxon: MyObservationsTaxon | null; +} + +export type MyObservationsAction = + | { + type: MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT; + observationsSort: OBSERVATIONS_SORT; + } + | { + type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT; + speciesSort: SPECIES_SORT; + } + | { + type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH; + searchTaxon: MyObservationsTaxon; + } + | { type: MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH }; + +export const initialMyObservationsState: MyObservationsState = { + observationsSort: OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST, + speciesSort: SPECIES_SORT.COUNT_DESC, + searchedTaxon: null, +}; + +export function myObservationsReducer( + state: MyObservationsState, + action: MyObservationsAction, +): MyObservationsState { + switch ( action.type ) { + case MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT: + return { ...state, observationsSort: action.observationsSort }; + case MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT: + return { ...state, speciesSort: action.speciesSort }; + case MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH: + return { ...state, searchedTaxon: action.searchTaxon }; + case MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH: + return { ...state, searchedTaxon: null }; + default: { + // https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking + const _exhaustive: never = action; + return _exhaustive; + } + } +} + +interface MyObservationsContextValue { + state: MyObservationsState; + dispatch: ( action: MyObservationsAction ) => void; +} + +const MyObservationsContext = React.createContext< + MyObservationsContextValue | undefined +>( undefined ); + +interface MyObservationsProviderProps { + children: React.ReactNode; +} + +export const MyObservationsProvider = ( { + children, +}: MyObservationsProviderProps ) => { + const [state, dispatch] = React.useReducer( + myObservationsReducer, + initialMyObservationsState, + ); + + const value = React.useMemo( + () => ( { state, dispatch } ), + [state], + ); + + return ( + + {children} + + ); +}; + +export function useMyObservations( ): MyObservationsContextValue { + const context = React.useContext( MyObservationsContext ); + // Pattern from https://kentcdodds.com/blog/how-to-use-react-context-effectively + if ( context === undefined ) { + throw new Error( "useMyObservations must be used within a MyObservationsProvider" ); + } + return context; +} From fa5e25c163a51776699a3ae382180fa81ec4f9a0 Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Thu, 11 Jun 2026 16:45:09 -0700 Subject: [PATCH 2/7] hook up myobs provider --- .../MyObservations/MyObservationsContainer.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/MyObservations/MyObservationsContainer.tsx b/src/components/MyObservations/MyObservationsContainer.tsx index 37d7ad075..e0de312a4 100644 --- a/src/components/MyObservations/MyObservationsContainer.tsx +++ b/src/components/MyObservations/MyObservationsContainer.tsx @@ -5,6 +5,7 @@ import { useFocusEffect, useNavigation } from "@react-navigation/native"; import type { FlashListRef } from "@shopify/flash-list"; import { fetchSpeciesCounts } from "api/observations"; import { RealmContext } from "providers/contexts"; +import { MyObservationsProvider } from "providers/MyObservationsContext"; import React, { useCallback, useEffect, @@ -62,7 +63,7 @@ interface SyncOptions { skipSomeUploads?: string[]; } -const MyObservationsContainer = ( ) => { +const MyObservationsWithProvider = ( ) => { const { isDefaultMode, loggedInWhileInDefaultMode } = useLayoutPrefs(); const { t } = useTranslation( ); const realm = useRealm( ); @@ -456,4 +457,10 @@ const MyObservationsContainer = ( ) => { ); }; +const MyObservationsContainer = ( ) => ( + + + +); + export default MyObservationsContainer; From b4460480d5990bab6c450d7d67defcfb9914c50a Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Thu, 11 Jun 2026 17:52:52 -0700 Subject: [PATCH 3/7] migrate species sort to myobs context --- .../MyObservationsContainer.tsx | 30 ++++++++++++------- .../MyObservations/MyObservationsSimple.tsx | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/MyObservations/MyObservationsContainer.tsx b/src/components/MyObservations/MyObservationsContainer.tsx index e0de312a4..49d64b510 100644 --- a/src/components/MyObservations/MyObservationsContainer.tsx +++ b/src/components/MyObservations/MyObservationsContainer.tsx @@ -5,7 +5,11 @@ import { useFocusEffect, useNavigation } from "@react-navigation/native"; import type { FlashListRef } from "@shopify/flash-list"; import { fetchSpeciesCounts } from "api/observations"; import { RealmContext } from "providers/contexts"; -import { MyObservationsProvider } from "providers/MyObservationsContext"; +import { + MY_OBSERVATIONS_ACTION, + MyObservationsProvider, + useMyObservations, +} from "providers/MyObservationsContext"; import React, { useCallback, useEffect, @@ -17,9 +21,9 @@ import { Alert } from "react-native"; import Observation from "realmModels/Observation"; import Taxon from "realmModels/Taxon"; import type { RealmObservation } from "realmModels/types"; +import type { SPECIES_SORT } from "sharedHelpers/speciesSort"; import { sortSpeciesCounts, - SPECIES_SORT, speciesSortToApiParams, } from "sharedHelpers/speciesSort"; import startupPerformanceTracker from "sharedHelpers/startupPerformanceTracker"; @@ -72,6 +76,8 @@ const MyObservationsWithProvider = ( ) => { const taxaListRef = useRef>( null ); const navigateToObsEdit = useNavigateToObsEdit( ); + const { state: myObsState, dispatch: myObsDispatch } = useMyObservations( ); + const setStartUploadObservations = useStore( state => state.setStartUploadObservations ); const uploadQueue = useStore( state => state.uploadQueue ); const addToUploadQueue = useStore( state => state.addToUploadQueue ); @@ -127,8 +133,12 @@ const MyObservationsWithProvider = ( ) => { const [openSheet, setOpenSheet] = useState( ACTIVE_SHEET.NONE ); - const [speciesSortOptionId, setSpeciesSortOptionId] - = useState( SPECIES_SORT.COUNT_DESC ); + const setSpeciesSortOptionId = ( value: SPECIES_SORT ) => { + myObsDispatch( { + type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, + speciesSort: value, + } ); + }; const toggleLayout = ( ) => { writeLayoutToStorage( layout === "grid" @@ -323,8 +333,8 @@ const MyObservationsWithProvider = ( ) => { // Map the selected sort option to API params const sortAPIParams = useMemo( - () => speciesSortToApiParams( speciesSortOptionId ), - [speciesSortOptionId], + () => speciesSortToApiParams( myObsState.speciesSort ), + [myObsState.speciesSort], ); const { @@ -334,7 +344,7 @@ const MyObservationsWithProvider = ( ) => { totalResults: numTotalTaxaRemote, refetch: refetchTaxa, } = useInfiniteScroll( - `MyObsSimple-fetchSpeciesCounts-${currentUser?.id}-${speciesSortOptionId}`, + `MyObsSimple-fetchSpeciesCounts-${currentUser?.id}-${myObsState.speciesSort}`, fetchSpeciesCounts, { user_id: currentUser?.id, @@ -395,13 +405,13 @@ const MyObservationsWithProvider = ( ) => { } // For logged-out users: apply client-side sorting to local data - return sortSpeciesCounts( unsortedTaxa || [], speciesSortOptionId ); + return sortSpeciesCounts( unsortedTaxa || [], myObsState.speciesSort ); }, [ currentUser, isConnected, remoteObservedTaxaCounts, localObservedSpeciesCount, - speciesSortOptionId, + myObsState.speciesSort, ] ); if ( !layout ) { return null; } @@ -450,7 +460,7 @@ const MyObservationsWithProvider = ( ) => { setOpenSheet={setOpenSheet} setSpeciesSortOptionId={setSpeciesSortOptionId} showNoResults={showNoResults} - speciesSortOptionId={speciesSortOptionId} + speciesSortOptionId={myObsState.speciesSort} taxa={taxa} toggleLayout={toggleLayout} /> diff --git a/src/components/MyObservations/MyObservationsSimple.tsx b/src/components/MyObservations/MyObservationsSimple.tsx index 970b83d5b..630c4653e 100644 --- a/src/components/MyObservations/MyObservationsSimple.tsx +++ b/src/components/MyObservations/MyObservationsSimple.tsx @@ -67,7 +67,7 @@ interface Props { openSheet: ACTIVE_SHEET; setActiveTab: ( newTab: string ) => void; setOpenSheet: ( value: ACTIVE_SHEET ) => void; - setSpeciesSortOptionId: React.Dispatch>; + setSpeciesSortOptionId: ( value: SPECIES_SORT ) => void; showNoResults: boolean; speciesSortOptionId: SPECIES_SORT; taxa?: SpeciesCount[]; From f74c0488acbaf28094838e91aebb8032a003b8da Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Thu, 11 Jun 2026 17:54:34 -0700 Subject: [PATCH 4/7] add myobs reducer tests --- .../providers/MyObservationsContext.test.js | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tests/unit/providers/MyObservationsContext.test.js diff --git a/tests/unit/providers/MyObservationsContext.test.js b/tests/unit/providers/MyObservationsContext.test.js new file mode 100644 index 000000000..38b6cf1b1 --- /dev/null +++ b/tests/unit/providers/MyObservationsContext.test.js @@ -0,0 +1,132 @@ +import { + initialMyObservationsState, + MY_OBSERVATIONS_ACTION, + myObservationsReducer, +} from "providers/MyObservationsContext"; +import { OBSERVATIONS_SORT } from "sharedHelpers/observationsSort"; +import { SPECIES_SORT } from "sharedHelpers/speciesSort"; + +describe( "initialMyObservationsState", ( ) => { + it( "starts with obs sorted by date uploaded (newest), species sort desc, and no taxon", ( ) => { + expect( initialMyObservationsState.observationsSort ) + .toBe( OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST ); + expect( initialMyObservationsState.speciesSort ).toBe( SPECIES_SORT.COUNT_DESC ); + expect( initialMyObservationsState.searchedTaxon ).toBeNull( ); + } ); +} ); + +describe( "myObservationsReducer", ( ) => { + describe( MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, ( ) => { + it( "updates observationsSort", ( ) => { + const next = myObservationsReducer( initialMyObservationsState, { + type: MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, + observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, + } ); + expect( next.observationsSort ).toBe( OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST ); + } ); + + it( "preserves speciesSort and searchedTaxon", ( ) => { + const taxon = { id: 42, name: "Canis latrans" }; + const state = { + observationsSort: OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST, + speciesSort: SPECIES_SORT.COUNT_ASC, + searchedTaxon: taxon, + }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, + observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_OLDEST, + } ); + expect( next.speciesSort ).toBe( state.speciesSort ); + expect( next.searchedTaxon ).toEqual( taxon ); + } ); + } ); + + describe( MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, ( ) => { + it( "updates speciesSort", ( ) => { + const next = myObservationsReducer( initialMyObservationsState, { + type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, + speciesSort: SPECIES_SORT.COUNT_ASC, + } ); + expect( next.speciesSort ).toBe( SPECIES_SORT.COUNT_ASC ); + } ); + + it( "preserves observationsSort and searchedTaxon", ( ) => { + const taxon = { id: 42, name: "Canis latrans" }; + const state = { + observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, + speciesSort: SPECIES_SORT.COUNT_DESC, + searchedTaxon: taxon, + }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, + speciesSort: SPECIES_SORT.COUNT_ASC, + } ); + expect( next.observationsSort ).toBe( state.observationsSort ); + expect( next.searchedTaxon ).toEqual( taxon ); + } ); + } ); + + describe( MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, ( ) => { + it( "sets the searched taxon", ( ) => { + const taxon = { id: 42, name: "Canis latrans", preferred_common_name: "Coyote" }; + const next = myObservationsReducer( initialMyObservationsState, { + type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, + searchTaxon: taxon, + } ); + expect( next.searchedTaxon ).toEqual( taxon ); + } ); + + it( "replaces a previously searched taxon", ( ) => { + const state = { + ...initialMyObservationsState, + searchedTaxon: { id: 1, name: "Canis latrans" }, + }; + const taxon = { id: 2, name: "Otala lactea" }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, + searchTaxon: taxon, + } ); + expect( next.searchedTaxon ).toEqual( taxon ); + } ); + + it( "preserves observationsSort and speciesSort", ( ) => { + const state = { + observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, + speciesSort: SPECIES_SORT.COUNT_ASC, + searchedTaxon: null, + }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, + searchTaxon: { id: 99, name: "Canis latrans" }, + } ); + expect( next.observationsSort ).toBe( state.observationsSort ); + expect( next.speciesSort ).toBe( state.speciesSort ); + } ); + } ); + + describe( MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, ( ) => { + it( "clears the searched taxon", ( ) => { + const state = { + ...initialMyObservationsState, + searchedTaxon: { id: 42, name: "Canis latrans" }, + }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, + } ); + expect( next.searchedTaxon ).toBeNull( ); + } ); + + it( "preserves observationsSort and speciesSort", ( ) => { + const state = { + observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, + speciesSort: SPECIES_SORT.COUNT_ASC, + searchedTaxon: { id: 1, name: "Canis latrans" }, + }; + const next = myObservationsReducer( state, { + type: MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, + } ); + expect( next.observationsSort ).toBe( state.observationsSort ); + expect( next.speciesSort ).toBe( state.speciesSort ); + } ); + } ); +} ); From eb9c1f660ba9bf2fe61eec38ff1406746ca3b065 Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Thu, 11 Jun 2026 18:15:47 -0700 Subject: [PATCH 5/7] taxon name should be required --- src/providers/MyObservationsContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/MyObservationsContext.tsx b/src/providers/MyObservationsContext.tsx index 3f315763c..9195f6ccd 100644 --- a/src/providers/MyObservationsContext.tsx +++ b/src/providers/MyObservationsContext.tsx @@ -11,7 +11,7 @@ export enum MY_OBSERVATIONS_ACTION { export interface MyObservationsTaxon { id: number; - name?: string; + name: string; preferred_common_name?: string; } From c91371de802c57ad300be9ab2cac7787425321ce Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Tue, 16 Jun 2026 11:48:56 -0700 Subject: [PATCH 6/7] use PropsWithChildren for MyObs provider --- src/providers/MyObservationsContext.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/providers/MyObservationsContext.tsx b/src/providers/MyObservationsContext.tsx index 9195f6ccd..8ccad9dce 100644 --- a/src/providers/MyObservationsContext.tsx +++ b/src/providers/MyObservationsContext.tsx @@ -72,13 +72,9 @@ const MyObservationsContext = React.createContext< MyObservationsContextValue | undefined >( undefined ); -interface MyObservationsProviderProps { - children: React.ReactNode; -} - export const MyObservationsProvider = ( { children, -}: MyObservationsProviderProps ) => { +}: React.PropsWithChildren ) => { const [state, dispatch] = React.useReducer( myObservationsReducer, initialMyObservationsState, From 70adad950376f87f1e6629df83c689ba18d67da9 Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Tue, 16 Jun 2026 11:56:28 -0700 Subject: [PATCH 7/7] drop reducer tests except intital state check --- .../providers/MyObservationsContext.test.js | 122 +----------------- 1 file changed, 1 insertion(+), 121 deletions(-) diff --git a/tests/unit/providers/MyObservationsContext.test.js b/tests/unit/providers/MyObservationsContext.test.js index 38b6cf1b1..778c6db09 100644 --- a/tests/unit/providers/MyObservationsContext.test.js +++ b/tests/unit/providers/MyObservationsContext.test.js @@ -1,8 +1,4 @@ -import { - initialMyObservationsState, - MY_OBSERVATIONS_ACTION, - myObservationsReducer, -} from "providers/MyObservationsContext"; +import { initialMyObservationsState } from "providers/MyObservationsContext"; import { OBSERVATIONS_SORT } from "sharedHelpers/observationsSort"; import { SPECIES_SORT } from "sharedHelpers/speciesSort"; @@ -14,119 +10,3 @@ describe( "initialMyObservationsState", ( ) => { expect( initialMyObservationsState.searchedTaxon ).toBeNull( ); } ); } ); - -describe( "myObservationsReducer", ( ) => { - describe( MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, ( ) => { - it( "updates observationsSort", ( ) => { - const next = myObservationsReducer( initialMyObservationsState, { - type: MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, - observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, - } ); - expect( next.observationsSort ).toBe( OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST ); - } ); - - it( "preserves speciesSort and searchedTaxon", ( ) => { - const taxon = { id: 42, name: "Canis latrans" }; - const state = { - observationsSort: OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST, - speciesSort: SPECIES_SORT.COUNT_ASC, - searchedTaxon: taxon, - }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.SET_OBSERVATIONS_SORT, - observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_OLDEST, - } ); - expect( next.speciesSort ).toBe( state.speciesSort ); - expect( next.searchedTaxon ).toEqual( taxon ); - } ); - } ); - - describe( MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, ( ) => { - it( "updates speciesSort", ( ) => { - const next = myObservationsReducer( initialMyObservationsState, { - type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, - speciesSort: SPECIES_SORT.COUNT_ASC, - } ); - expect( next.speciesSort ).toBe( SPECIES_SORT.COUNT_ASC ); - } ); - - it( "preserves observationsSort and searchedTaxon", ( ) => { - const taxon = { id: 42, name: "Canis latrans" }; - const state = { - observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, - speciesSort: SPECIES_SORT.COUNT_DESC, - searchedTaxon: taxon, - }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.SET_SPECIES_SORT, - speciesSort: SPECIES_SORT.COUNT_ASC, - } ); - expect( next.observationsSort ).toBe( state.observationsSort ); - expect( next.searchedTaxon ).toEqual( taxon ); - } ); - } ); - - describe( MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, ( ) => { - it( "sets the searched taxon", ( ) => { - const taxon = { id: 42, name: "Canis latrans", preferred_common_name: "Coyote" }; - const next = myObservationsReducer( initialMyObservationsState, { - type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, - searchTaxon: taxon, - } ); - expect( next.searchedTaxon ).toEqual( taxon ); - } ); - - it( "replaces a previously searched taxon", ( ) => { - const state = { - ...initialMyObservationsState, - searchedTaxon: { id: 1, name: "Canis latrans" }, - }; - const taxon = { id: 2, name: "Otala lactea" }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, - searchTaxon: taxon, - } ); - expect( next.searchedTaxon ).toEqual( taxon ); - } ); - - it( "preserves observationsSort and speciesSort", ( ) => { - const state = { - observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, - speciesSort: SPECIES_SORT.COUNT_ASC, - searchedTaxon: null, - }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.SET_TAXON_SEARCH, - searchTaxon: { id: 99, name: "Canis latrans" }, - } ); - expect( next.observationsSort ).toBe( state.observationsSort ); - expect( next.speciesSort ).toBe( state.speciesSort ); - } ); - } ); - - describe( MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, ( ) => { - it( "clears the searched taxon", ( ) => { - const state = { - ...initialMyObservationsState, - searchedTaxon: { id: 42, name: "Canis latrans" }, - }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, - } ); - expect( next.searchedTaxon ).toBeNull( ); - } ); - - it( "preserves observationsSort and speciesSort", ( ) => { - const state = { - observationsSort: OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST, - speciesSort: SPECIES_SORT.COUNT_ASC, - searchedTaxon: { id: 1, name: "Canis latrans" }, - }; - const next = myObservationsReducer( state, { - type: MY_OBSERVATIONS_ACTION.CLEAR_TAXON_SEARCH, - } ); - expect( next.observationsSort ).toBe( state.observationsSort ); - expect( next.speciesSort ).toBe( state.speciesSort ); - } ); - } ); -} );