import { ReactElement } from 'react' ; import { DeepPartial } from '@reduxjs/toolkit' ; import { render } from '@testing-library/react' ; import * as ReactRedux from 'react-redux' ; import { expectSaga } from 'redux-saga-test-plan' ; import { SCHEMA_BASE } from '@database/data/schema' ; import { marshallState } from '@services/Store/DataManager/utils' ; import { AppState , persistenceSlice } from '@store' ; import { DataStore , TAction } from '@types' ; import { noOp } from '@utils' ; import { ProvidersWrapper , withOptions } from './providersWrapper' ; export const APP_STATE = marshallState ( SCHEMA_BASE ) ; window . matchMedia = window . matchMedia || ( ( ) => ( { matches : false , addListener : noOp , removeListener : noOp } ) ) ; window . requestAnimationFrame = window . requestAnimationFrame || ( ( callback ) => { setTimeout ( callback , 0 ) ; } ) ; /**
 * For testing redux store interactions
 */ export const mockUseDispatch = ( ) => { const mockDispatch = jest . fn ( ) ; jest . spyOn ( ReactRedux , 'useDispatch' ) . mockReturnValue ( mockDispatch ) ; return mockDispatch ; } ; export const mockUseSelector = ( ) => { const mockSelector = jest . fn ( ) ; return mockSelector ; } ; export const actionWithPayload = ( payload ) => expect . objectContaining ( { payload } ) ; expectSaga . DEFAULT_TIMEOUT = 100 ; export const simpleRender = ( ui , options ? ) => { if ( options ?. initialState || options ?. initialRoute ) { return render ( ui , { wrapper : withOptions ( options . initialState , options . initialRoute ) , ... options } ) ; } else { return render ( ui , { wrapper : ProvidersWrapper , ... options } ) ; } } ; export const createStore = < S > ( reducer ) => ( action ) => ( state ) => reducer ( state , action ) ; export * from '@testing-library/react' ; export { ProvidersWrapper } ; export * from 'redux-saga-test-plan' ; /**
 * Provides a mock state. Can mock the entire DataStore of a specific key.
 */ export function mockAppState ( sliceState ? ) { if ( sliceState ) { return ( { [ persistenceSlice . name ] : sliceState } as unknown ) as AppState ; } else { return ( { [ persistenceSlice . name ] : APP_STATE } as unknown ) as AppState ; } } param func export const expectToThrow = ( func , error ? ) : void => { const spy = jest . spyOn ( console , 'error' ) ; spy . mockImplementation ( noOp ) ; expect ( func ) . toThrow ( error ) ; spy . mockRestore ( ) ; } ; type JestToErrorArg = Parameters < jest . Matchers < unknown , ( ) => unknown > [ 'toThrow' ] > [ 0 ] ; export function mockStore ( { storeSlice , dataStoreState } ) { return { ... mockAppState ( dataStoreState ) , ... storeSlice } as AppState ; }