95 lines
4 KiB
TypeScript
95 lines
4 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* Reset helpers. Call `resetAllMocks()` in `beforeEach` so no Zustand store,
|
|
* storage key, procedure fixture or navigation spy leaks between cases.
|
|
*/
|
|
import { resetTrpcMocks, seedDefaultProcedures } from '../mocks/trpc-client'
|
|
import { resetJsonMocks } from '../mocks/fetch-json'
|
|
import { __reset as resetSecureStore } from '../mocks/secure-store-mock'
|
|
import { __reset as resetLocation } from '../mocks/expo-location-mock'
|
|
import { __reset as resetNotifications } from '../mocks/expo-notifications-mock'
|
|
import { __resetRouterMock } from '../mocks/expo-router-mock'
|
|
import { __resetAuthState } from '../mocks/auth-context'
|
|
|
|
import { REGIONS } from '../fixtures'
|
|
import { useAppStore } from '@/src/store/appStore'
|
|
import { useAddressStore } from '@/src/store/addressStore'
|
|
import { useCartStore } from '@/src/store/cartStore'
|
|
import { useFlashCartStore } from '@/src/store/flashCartStore'
|
|
import { useNavigationStore } from '@/src/store/navigationStore'
|
|
import { useQuickDeliveryStore } from '@/src/store/quickDeliveryStore'
|
|
import { useStoreHeaderStore } from '@/src/store/storeHeaderStore'
|
|
import { useCheckoutStore } from '@/src/store/checkoutStore'
|
|
import { useCentralProductStore } from '@/src/store/centralProductStore'
|
|
import { useCentralSlotStore } from '@/src/store/centralSlotStore'
|
|
import { useRegionStore } from '@/src/store/regionStore'
|
|
import { useNeoRegionStore } from '@/src/store/neoRegionStore'
|
|
import { useLocationStore } from '@/src/store/locationStore'
|
|
import { useSlotStore } from '@/components/stores/slotStore'
|
|
import { useFlashNavigationStore } from '@/components/stores/flashNavigationStore'
|
|
import { useHomeTagStore } from '@/src/store/homeTagStore'
|
|
import { useFlashTabStore } from '@/src/store/flashTabStore'
|
|
|
|
export function resetStores() {
|
|
useAppStore.setState({ hideTabsNav: {} })
|
|
useAddressStore.setState({ selectedAddressId: null })
|
|
useCartStore.setState({ addedToCartProduct: null })
|
|
useFlashCartStore.setState({ addedFlashProduct: null })
|
|
useNavigationStore.setState({ isNavigatedFromHome: false, selectedStoreId: null })
|
|
useQuickDeliveryStore.setState({ isDrawerHidden: false, selectedSlotId: null })
|
|
useStoreHeaderStore.setState({ title: '' })
|
|
useCheckoutStore.setState({ userNotes: '' })
|
|
useCentralProductStore.setState({ products: [], productsById: {}, refetchProducts: null })
|
|
useCentralSlotStore.setState({
|
|
slots: [],
|
|
productSlotsMap: {},
|
|
isSlotsLoaded: false,
|
|
refetchSlots: null,
|
|
})
|
|
useRegionStore.setState({
|
|
selectedRegionId: null,
|
|
selectedRegion: null,
|
|
selectedBoundId: null,
|
|
regionGeneration: 0,
|
|
// Most cases exercise the launch decision with an empty store; they do not
|
|
// test the SecureStore hydration, so start settled (the persistence tests
|
|
// flip this back to false).
|
|
hydrated: true,
|
|
})
|
|
// Most component tests mount a screen directly (no LocationWrapperNeo), so
|
|
// the store starts ready. No-region cases call clearNeoRegion() explicitly.
|
|
useNeoRegionStore.setState({
|
|
regionId: 1,
|
|
boundId: 7,
|
|
regionName: 'Mahabubnagar',
|
|
coords: { latitude: 16.7488, longitude: 77.9851 },
|
|
origin: 'manual',
|
|
regions: REGIONS as any,
|
|
addresses: [],
|
|
selectedAddressId: null,
|
|
needsAddressFormFlow: false,
|
|
needsAddressConfirmation: false,
|
|
deviceOutOfService: false,
|
|
})
|
|
useSlotStore.setState({ slotId: undefined, storeId: undefined })
|
|
useFlashNavigationStore.setState({ shouldNavigateToCart: false })
|
|
useHomeTagStore.setState({ selectedTagId: null, expandedByTagId: {} })
|
|
useFlashTabStore.setState({ selectedTagId: null, selectedStoreId: null, searchQuery: '' })
|
|
useLocationStore.getState().stop()
|
|
useLocationStore.setState({ coords: null, status: 'idle', error: null })
|
|
}
|
|
|
|
export function resetAllMocks() {
|
|
jest.clearAllMocks()
|
|
jest.useRealTimers()
|
|
resetStores()
|
|
resetTrpcMocks()
|
|
resetJsonMocks()
|
|
resetSecureStore()
|
|
resetLocation()
|
|
resetNotifications()
|
|
__resetRouterMock()
|
|
__resetAuthState()
|
|
}
|
|
|
|
export { seedDefaultProcedures }
|