2024-08-15 12:27:22 +03:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
import React, { ReactNode } from 'react'
|
|
|
|
import SiteContextProvider, {
|
|
|
|
PlausibleSite
|
|
|
|
} from '../js/dashboard/site-context'
|
|
|
|
import UserContextProvider, { Role } from '../js/dashboard/user-context'
|
|
|
|
import { MemoryRouter, MemoryRouterProps } from 'react-router-dom'
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
|
import QueryContextProvider from '../js/dashboard/query-context'
|
|
|
|
import { getRouterBasepath } from '../js/dashboard/router'
|
|
|
|
|
|
|
|
type TestContextProvidersProps = {
|
|
|
|
children: ReactNode
|
|
|
|
routerProps?: Pick<MemoryRouterProps, 'initialEntries'>
|
|
|
|
siteOptions?: Partial<PlausibleSite>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const TestContextProviders = ({
|
|
|
|
children,
|
|
|
|
routerProps,
|
|
|
|
siteOptions
|
|
|
|
}: TestContextProvidersProps) => {
|
|
|
|
const defaultSite: PlausibleSite = {
|
|
|
|
domain: 'plausible.io/unit',
|
2024-08-28 11:14:29 +03:00
|
|
|
offset: 0,
|
2024-08-15 12:27:22 +03:00
|
|
|
hasGoals: false,
|
|
|
|
hasProps: false,
|
|
|
|
funnelsAvailable: false,
|
|
|
|
propsAvailable: false,
|
|
|
|
conversionsOptedOut: false,
|
|
|
|
funnelsOptedOut: false,
|
|
|
|
propsOptedOut: false,
|
|
|
|
revenueGoals: [],
|
|
|
|
funnels: [],
|
|
|
|
statsBegin: '',
|
|
|
|
nativeStatsBegin: '',
|
2024-08-28 11:14:29 +03:00
|
|
|
embedded: false,
|
2024-08-15 12:27:22 +03:00
|
|
|
background: '',
|
|
|
|
isDbip: false,
|
|
|
|
flags: {},
|
|
|
|
validIntervalsByPeriod: {},
|
|
|
|
shared: false
|
|
|
|
}
|
|
|
|
|
|
|
|
const site = { ...defaultSite, ...siteOptions }
|
|
|
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
defaultOptions: {
|
|
|
|
queries: {
|
|
|
|
refetchOnWindowFocus: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const defaultInitialEntries = [getRouterBasepath(site)]
|
|
|
|
|
|
|
|
return (
|
|
|
|
// <ThemeContextProvider> not interactive component, default value is suitable
|
|
|
|
<SiteContextProvider site={site}>
|
|
|
|
<UserContextProvider role={Role.admin} loggedIn={true}>
|
|
|
|
<MemoryRouter
|
|
|
|
basename={getRouterBasepath(site)}
|
|
|
|
initialEntries={defaultInitialEntries}
|
|
|
|
{...routerProps}
|
|
|
|
>
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<QueryContextProvider>{children}</QueryContextProvider>
|
|
|
|
</QueryClientProvider>
|
|
|
|
</MemoryRouter>
|
|
|
|
</UserContextProvider>
|
|
|
|
</SiteContextProvider>
|
|
|
|
// </ThemeContextProvider>
|
|
|
|
)
|
|
|
|
}
|