grafana/public/test/helpers/TestProvider.tsx
Ashley Harrison 670960f70c
Chore: Upgrade redux (#86877)
* update packages

* fix type errors

* upgrade redux toolkit as well

* don't need eslint-disable command

* remove comment

* fix unit tests

* call rtk query selector directly

* remove unnecessary checks
2024-05-10 14:28:51 +01:00

45 lines
1.4 KiB
TypeScript

import { Store } from '@reduxjs/toolkit';
import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { locationService } from '@grafana/runtime';
import { ModalRoot } from '@grafana/ui';
import { GrafanaContext, GrafanaContextType } from 'app/core/context/GrafanaContext';
import { ModalsContextProvider } from 'app/core/context/ModalsContextProvider';
import { configureStore } from 'app/store/configureStore';
import { StoreState } from 'app/types/store';
export interface Props {
storeState?: Partial<StoreState>;
store?: Store<StoreState>;
children: React.ReactNode;
grafanaContext?: GrafanaContextType;
}
/**
* Wrapps component in redux store provider, Router and GrafanaContext
*
* @deprecated Use `test/test-utils` `render` method instead
*/
export function TestProvider(props: Props) {
const { store = configureStore(props.storeState), children } = props;
const context = {
...getGrafanaContextMock(),
...props.grafanaContext,
};
return (
<Provider store={store}>
<Router history={locationService.getHistory()}>
<ModalsContextProvider>
<GrafanaContext.Provider value={context}>{children}</GrafanaContext.Provider>
<ModalRoot />
</ModalsContextProvider>
</Router>
</Provider>
);
}