2022-06-30 19:26:22 +03:00
|
|
|
import { i18n } from '@lingui/core'
|
|
|
|
import { I18nProvider } from '@lingui/react'
|
2023-01-05 02:14:44 +03:00
|
|
|
import { render, renderHook } from '@testing-library/react'
|
2022-07-01 02:38:02 +03:00
|
|
|
import Web3Provider from 'components/Web3Provider'
|
2022-06-30 19:26:22 +03:00
|
|
|
import { DEFAULT_LOCALE } from 'constants/locales'
|
2022-10-21 20:38:30 +03:00
|
|
|
import { BlockNumberProvider } from 'lib/hooks/useBlockNumber'
|
2022-06-30 19:26:22 +03:00
|
|
|
import { en } from 'make-plural/plurals'
|
|
|
|
import { ReactElement, ReactNode } from 'react'
|
2022-10-21 20:38:30 +03:00
|
|
|
import { QueryClient, QueryClientProvider } from 'react-query'
|
2021-07-26 20:41:08 +03:00
|
|
|
import { Provider } from 'react-redux'
|
2022-10-21 20:38:30 +03:00
|
|
|
import { HashRouter } from 'react-router-dom'
|
2021-09-22 02:21:28 +03:00
|
|
|
import store from 'state'
|
|
|
|
import ThemeProvider from 'theme'
|
2021-07-26 20:41:08 +03:00
|
|
|
|
2022-06-30 19:26:22 +03:00
|
|
|
import catalog from './locales/en-US'
|
|
|
|
|
|
|
|
i18n.load({
|
|
|
|
[DEFAULT_LOCALE]: catalog.messages,
|
|
|
|
})
|
|
|
|
i18n.loadLocaleData({
|
|
|
|
[DEFAULT_LOCALE]: { plurals: en },
|
|
|
|
})
|
|
|
|
i18n.activate(DEFAULT_LOCALE)
|
|
|
|
|
|
|
|
const MockedI18nProvider = ({ children }: any) => <I18nProvider i18n={i18n}>{children}</I18nProvider>
|
2022-10-21 20:38:30 +03:00
|
|
|
const queryClient = new QueryClient()
|
2022-06-30 19:26:22 +03:00
|
|
|
|
|
|
|
const WithProviders = ({ children }: { children?: ReactNode }) => {
|
2021-07-26 20:41:08 +03:00
|
|
|
return (
|
2022-06-30 19:26:22 +03:00
|
|
|
<MockedI18nProvider>
|
|
|
|
<Provider store={store}>
|
2022-10-21 20:38:30 +03:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<HashRouter>
|
|
|
|
<Web3Provider>
|
|
|
|
<BlockNumberProvider>
|
|
|
|
<ThemeProvider>{children}</ThemeProvider>
|
|
|
|
</BlockNumberProvider>
|
|
|
|
</Web3Provider>
|
|
|
|
</HashRouter>
|
|
|
|
</QueryClientProvider>
|
2022-06-30 19:26:22 +03:00
|
|
|
</Provider>
|
|
|
|
</MockedI18nProvider>
|
2021-07-26 20:41:08 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-30 19:26:22 +03:00
|
|
|
const customRender = (ui: ReactElement) => render(ui, { wrapper: WithProviders })
|
2023-01-05 02:14:44 +03:00
|
|
|
const customRenderHook = <Result, Props>(hook: (initialProps: Props) => Result) =>
|
|
|
|
renderHook(hook, { wrapper: WithProviders })
|
2021-07-26 20:41:08 +03:00
|
|
|
|
|
|
|
export * from '@testing-library/react'
|
|
|
|
export { customRender as render }
|
2023-01-05 02:14:44 +03:00
|
|
|
export { customRenderHook as renderHook }
|