2023-02-02 02:53:06 -06:00
|
|
|
import { ToolkitStore } from '@reduxjs/toolkit/dist/configureStore';
|
2022-01-17 10:58:49 -06:00
|
|
|
import React from 'react';
|
2023-02-02 02:53:06 -06:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { Router } from 'react-router-dom';
|
|
|
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2023-02-02 02:53:06 -06:00
|
|
|
import { locationService } from '@grafana/runtime';
|
|
|
|
import { GrafanaContext, GrafanaContextType } from 'app/core/context/GrafanaContext';
|
|
|
|
import { configureStore } from 'app/store/configureStore';
|
|
|
|
import { StoreState } from 'app/types/store';
|
2022-01-17 10:58:49 -06:00
|
|
|
|
2023-02-02 02:53:06 -06:00
|
|
|
export interface Props {
|
|
|
|
storeState?: Partial<StoreState>;
|
|
|
|
store?: ToolkitStore;
|
|
|
|
children: React.ReactNode;
|
|
|
|
grafanaContext?: GrafanaContextType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapps component in redux store provider, Router and GrafanaContext
|
|
|
|
*/
|
|
|
|
export function TestProvider(props: Props) {
|
2023-06-21 04:06:28 -05:00
|
|
|
const { store = configureStore(props.storeState), children } = props;
|
|
|
|
|
|
|
|
const context = {
|
|
|
|
...getGrafanaContextMock(),
|
|
|
|
...props.grafanaContext,
|
|
|
|
};
|
2023-02-02 02:53:06 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<Router history={locationService.getHistory()}>
|
2023-06-21 04:06:28 -05:00
|
|
|
<GrafanaContext.Provider value={context}>{children}</GrafanaContext.Provider>
|
2023-02-02 02:53:06 -06:00
|
|
|
</Router>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|