-
Notifications
You must be signed in to change notification settings - Fork 12
/
testUtils.js
49 lines (43 loc) · 1.6 KB
/
testUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import { IntlProvider } from 'react-intl';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import configureStore from '@app/configureStore';
import { DEFAULT_LOCALE, translationMessages } from '@app/i18n';
import ConnectedLanguageProvider from '@containers/LanguageProvider';
import { BrowserRouter as Router, browserHistory } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
export const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
export const apiResponseGenerator = (ok, data) => ({
ok,
data,
});
export const renderProvider = children => {
const store = configureStore({}, browserHistory);
const theme = { main: 'violet' };
return render(
<Provider store={store}>
<ConnectedLanguageProvider messages={translationMessages}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</ConnectedLanguageProvider>
</Provider>,
);
};
export const renderWithIntl = children =>
render(
<IntlProvider
locale={DEFAULT_LOCALE}
messages={translationMessages[DEFAULT_LOCALE]}
>
{children}
</IntlProvider>,
);
export const getComponentStyles = (Component, props = {}) => {
renderWithIntl(Component(props));
const { styledComponentId } = Component(props).type;
const componentRoots = document.getElementsByClassName(styledComponentId);
// eslint-disable-next-line no-underscore-dangle
return window.getComputedStyle(componentRoots[0])._values;
};
export const renderWithRouterAndIntl = children =>
renderWithIntl(<Router>{children}</Router>);