@thepalaceproject/circulation-admin 1.21.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { Provider, ProviderProps } from "react-redux";
|
|
2
3
|
import ContextProvider, {
|
|
3
4
|
ContextProviderProps,
|
|
4
5
|
} from "../../../src/components/ContextProvider";
|
|
5
6
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
6
7
|
import { render, RenderOptions, RenderResult } from "@testing-library/react";
|
|
7
8
|
import { defaultFeatureFlags } from "../../../src/utils/featureFlags";
|
|
9
|
+
import { store } from "../../../src/store";
|
|
8
10
|
|
|
9
11
|
export type TestProviderWrapperOptions = {
|
|
12
|
+
reduxProviderProps?: ProviderProps;
|
|
10
13
|
contextProviderProps?: Partial<ContextProviderProps>;
|
|
11
14
|
queryClient?: QueryClient;
|
|
12
15
|
};
|
|
@@ -14,6 +17,10 @@ export type TestRenderWrapperOptions = TestProviderWrapperOptions & {
|
|
|
14
17
|
renderOptions?: Omit<RenderOptions, "queries">;
|
|
15
18
|
};
|
|
16
19
|
|
|
20
|
+
// The `store` argument is required for the Redux Provider and should
|
|
21
|
+
// be the same for both the Redux Provider and the ContextProvider.
|
|
22
|
+
const defaultReduxStore = store;
|
|
23
|
+
|
|
17
24
|
// The `csrfToken` context provider prop is required, so we provide
|
|
18
25
|
// a default value here, so it can be easily merged with other props.
|
|
19
26
|
const defaultContextProviderProps: ContextProviderProps = {
|
|
@@ -26,11 +33,15 @@ const defaultContextProviderProps: ContextProviderProps = {
|
|
|
26
33
|
* a React element for testing.
|
|
27
34
|
*
|
|
28
35
|
* @param {TestProviderWrapperOptions} options
|
|
36
|
+
* @param options.reduxProviderProps Props to pass to the Redux `Provider` wrapper
|
|
29
37
|
* @param {ContextProviderProps} options.contextProviderProps Props to pass to the ContextProvider wrapper
|
|
30
38
|
* @param {QueryClient} options.queryClient A `tanstack/react-query` QueryClient
|
|
31
39
|
* @returns {React.FunctionComponent} A React component that wraps children with our providers
|
|
32
40
|
*/
|
|
33
41
|
export const componentWithProviders = ({
|
|
42
|
+
reduxProviderProps = {
|
|
43
|
+
store: defaultReduxStore,
|
|
44
|
+
},
|
|
34
45
|
contextProviderProps = {
|
|
35
46
|
csrfToken: "",
|
|
36
47
|
featureFlags: defaultFeatureFlags,
|
|
@@ -40,11 +51,16 @@ export const componentWithProviders = ({
|
|
|
40
51
|
const effectiveContextProviderProps = {
|
|
41
52
|
...defaultContextProviderProps,
|
|
42
53
|
...contextProviderProps,
|
|
54
|
+
...reduxProviderProps.store, // Context and Redux Provider stores must match.
|
|
43
55
|
};
|
|
44
56
|
const wrapper = ({ children }) => (
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
|
|
57
|
+
<Provider {...reduxProviderProps}>
|
|
58
|
+
<ContextProvider {...effectiveContextProviderProps}>
|
|
59
|
+
<QueryClientProvider client={queryClient}>
|
|
60
|
+
{children}
|
|
61
|
+
</QueryClientProvider>
|
|
62
|
+
</ContextProvider>
|
|
63
|
+
</Provider>
|
|
48
64
|
);
|
|
49
65
|
wrapper.displayName = "TestWrapperComponent";
|
|
50
66
|
return wrapper;
|