2020-06-09 19:29:50 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import renderer from 'react-test-renderer';
|
2020-06-09 20:04:22 -07:00
|
|
|
import { Provider } from 'react-redux';
|
2020-06-09 19:29:50 -07:00
|
|
|
import { IntlProvider } from 'react-intl';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2020-06-09 20:04:22 -07:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2020-06-09 19:29:50 -07:00
|
|
|
|
|
|
|
// Mock Redux
|
|
|
|
// https://redux.js.org/recipes/writing-tests/
|
|
|
|
const middlewares = [thunk];
|
|
|
|
export const mockStore = configureMockStore(middlewares);
|
|
|
|
|
2020-06-09 20:04:22 -07:00
|
|
|
// Test Redux connected components
|
|
|
|
export const createComponentWithStore = (children, props = { store: mockStore(ImmutableMap()) }) => {
|
|
|
|
return renderer.create(<Provider {...props}>{children}</Provider>);
|
|
|
|
};
|
|
|
|
|
2020-06-09 19:29:50 -07:00
|
|
|
// Testing i18n components
|
|
|
|
// https://formatjs.io/docs/react-intl/testing/#helper-function-2
|
|
|
|
export const createComponentWithIntl = (children, props = { locale: 'en' }) => {
|
|
|
|
return renderer.create(<IntlProvider {...props}>{children}</IntlProvider>);
|
|
|
|
};
|