-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestProvider.tsx
62 lines (58 loc) · 1.71 KB
/
TestProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { ReactNode } from 'react'
import { MemoryRouter } from 'react-router-dom'
import {
StoreProvider,
type StateSchema,
} from '@/app/providers/StoreProvider'
import { I18nextProvider } from 'react-i18next'
import i18nForTests from '@/shared/config/i18n/i18nForTests'
import type { FeatureFlags } from '@/shared/types/featureFlags'
import type { AsyncReducersList } from '@/app/providers/StoreProvider/config/stateSchema'
import { setFeatureFlags } from '../../features'
export interface TestProviderOptions {
route?: string
preloadedState?: DeepPartial<StateSchema>
asyncReducers?: AsyncReducersList
featureFlags?: FeatureFlags
}
interface TestProviderProps {
children: ReactNode
options?: TestProviderOptions
}
/**
* This component is used to wrap the component that is being tested. It wraps with providers required for the component to work. Also it accepts options to configure the test.
*
*
* @options
* ```md
* preloadedState - initial state for the store,
* asyncReducers - reducers that are not loaded by default,
* route - route to be used for the test,
* featureFlags - feature flags to be used for the test,
* ```
*
* @returns {ReactNode} wrapped component
*/
export const TestProvider = ({
children,
options: {
preloadedState,
asyncReducers = {},
route = '/',
featureFlags,
} = {},
}: TestProviderProps) => {
setFeatureFlags(featureFlags as FeatureFlags)
return (
<MemoryRouter initialEntries={[route]}>
<StoreProvider
preloadedAsyncReducers={asyncReducers}
preloadedState={preloadedState}
>
<I18nextProvider i18n={i18nForTests}>
{children}
</I18nextProvider>
</StoreProvider>
</MemoryRouter>
)
}