-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { render } from '@testing-library/react'; | ||
import PropTypes from 'prop-types'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { thunk } from 'redux-thunk'; | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import createRootReducer from 'mirador/dist/es/src/state/reducers/rootReducer'; | ||
import settings from 'mirador/dist/es/src/config/settings'; | ||
|
||
const rootReducer = createRootReducer(); | ||
const theme = createTheme(settings.theme); | ||
|
||
/** | ||
* Hook up our rendered object to redux | ||
*/ | ||
function renderWithProviders( | ||
ui, | ||
{ | ||
preloadedState = {}, | ||
// Automatically create a store instance if no store was passed in | ||
store = createStore(rootReducer, preloadedState, applyMiddleware(thunk)), | ||
...renderOptions | ||
} = {}, | ||
) { | ||
/** :nodoc: */ | ||
function Wrapper({ children }) { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<Provider store={store}>{children}</Provider> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
Wrapper.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
const rendered = render(ui, { wrapper: Wrapper, ...renderOptions }); | ||
|
||
// Return an object with the store and all of RTL's query functions | ||
return { | ||
store, | ||
...rendered, | ||
rerender: (newUi, options) => render( | ||
newUi, | ||
{ container: rendered.container, wrapper: Wrapper, ...options }, | ||
), | ||
}; | ||
} | ||
|
||
export * from '@testing-library/react'; | ||
export { renderWithProviders as render }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
import '@testing-library/jest-dom' |