-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathAppProvider.test.jsx
More file actions
101 lines (91 loc) · 2.96 KB
/
AppProvider.test.jsx
File metadata and controls
101 lines (91 loc) · 2.96 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from 'react';
import { createStore } from 'redux';
import { render, screen, waitFor } from '@testing-library/react';
import AppProvider from './AppProvider';
import { initialize } from '../initialize';
jest.mock('../auth', () => ({
configure: () => {},
getAuthenticatedUser: () => null,
fetchAuthenticatedUser: () => null,
getAuthenticatedHttpClient: () => ({}),
AUTHENTICATED_USER_CHANGED: 'user_changed',
}));
jest.mock('../analytics', () => ({
configure: () => {},
identifyAnonymousUser: jest.fn(),
identifyAuthenticatedUser: jest.fn(),
}));
jest.mock('./hooks', () => ({
...jest.requireActual('./hooks'),
useTrackColorSchemeChoice: jest.fn(),
}));
describe('AppProvider', () => {
beforeEach(async () => {
await initialize({
loggingService: jest.fn(() => ({
logError: jest.fn(),
logInfo: jest.fn(),
})),
messages: {
ar: {},
'es-419': {},
fr: {},
'zh-cn': {},
ca: {},
he: {},
id: {},
'ko-kr': {},
pl: {},
'pt-br': {},
ru: {},
th: {},
uk: {},
},
});
});
it('should render its children with a router', async () => {
const component = (
<AppProvider store={createStore(state => state)}>
<div className="child">Child One</div>
<div className="child">Child Two</div>
</AppProvider>
);
const wrapper = render(component);
await waitFor(() => {
expect(screen.getByText('Child One')).toBeInTheDocument();
expect(screen.getByText('Child Two')).toBeInTheDocument();
});
expect(wrapper.getByTestId('browser-router')).toBeInTheDocument();
const reduxProvider = wrapper.getByTestId('redux-provider');
expect(reduxProvider).toBeInTheDocument();
});
it('should render its children without a router', async () => {
const component = (
<AppProvider store={createStore(state => state)} wrapWithRouter={false}>
<div className="child">Child One</div>
<div className="child">Child Two</div>
</AppProvider>
);
const wrapper = render(component);
await waitFor(() => {
expect(screen.getByText('Child One')).toBeInTheDocument();
expect(screen.getByText('Child Two')).toBeInTheDocument();
});
expect(wrapper.queryByTestId('browser-router')).not.toBeInTheDocument();
const reduxProvider = wrapper.getByTestId('redux-provider');
expect(reduxProvider).toBeInTheDocument();
});
it('should skip redux Provider if not given a store', async () => {
const component = (
<AppProvider>
<div className="child">Child One</div>
<div className="child">Child Two</div>
</AppProvider>
);
const wrapper = render(component);
expect(screen.getByText('Child One')).toBeInTheDocument();
expect(screen.getByText('Child Two')).toBeInTheDocument();
const reduxProvider = wrapper.queryByTestId('redux-provider');
expect(reduxProvider).not.toBeInTheDocument();
});
});