-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathsetup.js
More file actions
67 lines (56 loc) · 1.92 KB
/
setup.js
File metadata and controls
67 lines (56 loc) · 1.92 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { createIntl, createIntlCache, IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
import { createTheme } from '@mui/material/styles';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import Enzyme from 'enzyme';
import PropTypes from 'prop-types';
import 'jest-canvas-mock';
import '@testing-library/jest-dom';
// define all mocks/polyfills
import './mocks/requestAnimationFrame';
import './mocks/ResizeObserver';
import './mocks/matchMedia';
Enzyme.configure({ adapter: new Adapter() });
const timeZone = 'Asia/Singapore';
const intlCache = createIntlCache();
const intl = createIntl({ locale: 'en', timeZone }, intlCache);
const courseId = '1';
const muiTheme = createTheme();
const buildContextOptions = (store) => {
// eslint-disable-next-line react/prop-types
const WrapWithProviders = ({ children }) => (
<IntlProvider {...intl}>
<Provider store={store}>{children}</Provider>
</IntlProvider>
);
return {
context: { muiTheme },
childContextTypes: {
muiTheme: PropTypes.object,
intl: PropTypes.object,
},
wrappingComponent: store ? WrapWithProviders : IntlProvider,
wrappingComponentProps: store ? null : intl,
};
};
// Global variables
global.courseId = courseId;
global.window = window;
global.muiTheme = muiTheme;
global.buildContextOptions = buildContextOptions;
window.history.pushState({}, '', `/courses/${courseId}`);
// Global helper functions
// Sleep for a given period in ms.
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
global.sleep = sleep;
// summernote does not work well with jsdom in tests, stub it to normal text field.
jest.mock('lib/components/form/fields/RichTextField', () =>
jest.requireActual('lib/components/form/fields/TextField'),
);
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: jest.fn(),
unstable_usePrompt: jest.fn(),
}));