mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
51fba1c2cf
* Adds tests for FE date calculations during DST changeover times * Fixes unparsed offset in SiteContext * Fixes unparsed embedded in SiteContext * Adds tests for SiteContext
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
/** @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',
|
|
offset: 0,
|
|
hasGoals: false,
|
|
hasProps: false,
|
|
funnelsAvailable: false,
|
|
propsAvailable: false,
|
|
conversionsOptedOut: false,
|
|
funnelsOptedOut: false,
|
|
propsOptedOut: false,
|
|
revenueGoals: [],
|
|
funnels: [],
|
|
statsBegin: '',
|
|
nativeStatsBegin: '',
|
|
embedded: false,
|
|
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>
|
|
)
|
|
}
|