UNPKG

@navinc/base-react-components

Version:
18 lines 1.59 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { StyleSheetManager, ThemeProvider } from 'styled-components'; import { Route, Routes } from 'react-router-dom'; // eslint-disable-next-line no-restricted-imports -- only allowed here - this extends render to include our required providers import { render } from '@testing-library/react'; import { theme } from '../theme.js'; import { ToastProvider } from '../toast-hook.js'; import { shouldForwardProp } from '../is-prop-valid.js'; import { AppContextMemoryRouter } from '../app-context-memory-router.jsx'; export const withAppContext = (ComponentIn) => (props) => (_jsx(ThemeProvider, { theme: theme, children: _jsx(ComponentIn, Object.assign({}, props)) })); export const renderWithContext = (ui, options = {}) => { const { initialEntries = ['/'], initialIndex = initialEntries.length - 1, routePath = new URL(initialEntries[initialIndex], 'http://local').pathname, } = options; const [TestRouter, history] = AppContextMemoryRouter({ initialEntries, initialIndex }); const Context = ({ children }) => (_jsx(StyleSheetManager, { shouldForwardProp: shouldForwardProp, children: _jsx(ToastProvider, { children: _jsx(ThemeProvider, { theme: theme, children: _jsx(TestRouter, { children: _jsxs(Routes, { children: [_jsx(Route, { path: routePath, element: children }), _jsx(Route, { path: "*", element: null })] }) }) }) }) })); const view = render(ui, Object.assign({ wrapper: Context }, options)); return Object.assign(Object.assign({}, view), { history }); }; //# sourceMappingURL=with-app-context.js.map