|
|
@ -6,6 +6,7 @@ import { Fragment, PropsWithChildren } from 'react'; |
|
|
|
import * as React from 'react'; |
|
|
|
import * as React from 'react'; |
|
|
|
import { Provider } from 'react-redux'; |
|
|
|
import { Provider } from 'react-redux'; |
|
|
|
import { Router } from 'react-router-dom'; |
|
|
|
import { Router } from 'react-router-dom'; |
|
|
|
|
|
|
|
import { CompatRouter } from 'react-router-dom-v5-compat'; |
|
|
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; |
|
|
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; |
|
|
|
|
|
|
|
|
|
|
|
import { HistoryWrapper, LocationServiceProvider, setLocationService } from '@grafana/runtime'; |
|
|
|
import { HistoryWrapper, LocationServiceProvider, setLocationService } from '@grafana/runtime'; |
|
|
@ -49,10 +50,6 @@ const getWrapper = ({ |
|
|
|
grafanaContext?: Partial<GrafanaContextType>; |
|
|
|
grafanaContext?: Partial<GrafanaContextType>; |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const reduxStore = store || configureStore(); |
|
|
|
const reduxStore = store || configureStore(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Conditional router - either a MemoryRouter or just a Fragment |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const PotentialRouter = renderWithRouter ? Router : Fragment; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a fresh location service for each test - otherwise we run the risk
|
|
|
|
// Create a fresh location service for each test - otherwise we run the risk
|
|
|
|
// of it being stateful in between runs
|
|
|
|
// of it being stateful in between runs
|
|
|
@ -60,6 +57,15 @@ const getWrapper = ({ |
|
|
|
const locationService = new HistoryWrapper(history); |
|
|
|
const locationService = new HistoryWrapper(history); |
|
|
|
setLocationService(locationService); |
|
|
|
setLocationService(locationService); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Conditional router - either a MemoryRouter or just a Fragment |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const PotentialRouter = renderWithRouter |
|
|
|
|
|
|
|
? ({ children }: PropsWithChildren) => <Router history={history}>{children}</Router> |
|
|
|
|
|
|
|
: ({ children }: PropsWithChildren) => <Fragment>{children}</Fragment>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const PotentialCompatRouter = renderWithRouter ? CompatRouter : Fragment; |
|
|
|
|
|
|
|
|
|
|
|
const context = { |
|
|
|
const context = { |
|
|
|
...getGrafanaContextMock(), |
|
|
|
...getGrafanaContextMock(), |
|
|
|
...grafanaContext, |
|
|
|
...grafanaContext, |
|
|
@ -73,9 +79,11 @@ const getWrapper = ({ |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Provider store={reduxStore}> |
|
|
|
<Provider store={reduxStore}> |
|
|
|
<GrafanaContext.Provider value={context}> |
|
|
|
<GrafanaContext.Provider value={context}> |
|
|
|
<PotentialRouter history={history}> |
|
|
|
<PotentialRouter> |
|
|
|
<LocationServiceProvider service={locationService}> |
|
|
|
<LocationServiceProvider service={locationService}> |
|
|
|
|
|
|
|
<PotentialCompatRouter> |
|
|
|
<ModalsContextProvider>{children}</ModalsContextProvider> |
|
|
|
<ModalsContextProvider>{children}</ModalsContextProvider> |
|
|
|
|
|
|
|
</PotentialCompatRouter> |
|
|
|
</LocationServiceProvider> |
|
|
|
</LocationServiceProvider> |
|
|
|
</PotentialRouter> |
|
|
|
</PotentialRouter> |
|
|
|
</GrafanaContext.Provider> |
|
|
|
</GrafanaContext.Provider> |
|
|
|