richie-education 2.25.0-b2.dev148 → 2.25.0-b2.dev152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/contexts/JoanieApiContext/index.spec.tsx +1 -1
- package/js/contexts/SessionContext/JoanieSessionProvider.spec.tsx +44 -37
- package/js/contexts/SessionContext/index.spec.tsx +42 -21
- package/js/contexts/SessionContext/no-authentication.spec.tsx +3 -2
- package/js/hooks/useCourseSearchParams/index.spec.tsx +0 -1
- package/js/hooks/useUnionResource/index.spec.tsx +11 -9
- package/js/utils/test/render.tsx +5 -1
- package/js/utils/test/wrappers/BaseAppWrapper.tsx +5 -8
- package/js/utils/test/wrappers/BaseJoanieAppWrapper.tsx +4 -7
- package/js/utils/test/wrappers/IntlWrapper.tsx +4 -2
- package/js/utils/test/wrappers/PresentationalAppWrapper.tsx +1 -1
- package/js/utils/test/wrappers/ReactQueryAppWrapper.tsx +16 -0
- package/js/widgets/Dashboard/components/DashboardAvatar/index.spec.tsx +8 -5
- package/js/widgets/Dashboard/components/DashboardBox/index.spec.tsx +3 -1
- package/js/widgets/Dashboard/components/DashboardItem/Certificate/index.spec.tsx +19 -39
- package/js/widgets/Dashboard/components/DashboardItem/CertificateStatus/index.spec.tsx +14 -12
- package/js/widgets/Dashboard/components/DashboardItem/Contract/index.spec.tsx +5 -43
- package/js/widgets/Dashboard/components/DashboardItem/CourseEnrolling/index.spec.tsx +16 -15
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.spec.tsx +8 -18
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +19 -51
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.spec.tsx +40 -70
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.spec.tsx +31 -32
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateLearnerMessage/index.spec.tsx +19 -31
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateTeacherMessage/index.spec.tsx +26 -37
- package/js/widgets/Dashboard/components/DashboardItem/index.spec.tsx +28 -23
- package/js/widgets/Dashboard/components/DashboardLayoutRoute/index.spec.tsx +53 -51
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.spec.tsx +24 -49
- package/js/widgets/Dashboard/components/DashboardSidebar/components/MenuNavLink/index.spec.tsx +5 -14
- package/js/widgets/Dashboard/components/ProtectedOutlet/AuthenticatedOutlet.spec.tsx +62 -54
- package/js/widgets/Dashboard/components/ProtectedOutlet/ProtectedOutlet.spec.tsx +67 -42
- package/js/widgets/Dashboard/components/RouterButton/index.spec.tsx +12 -14
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.spec.tsx +14 -39
- package/js/widgets/Dashboard/hooks/useDashboardRouter/index.spec.tsx +2 -4
- package/js/widgets/Dashboard/hooks/useEnroll/index.spec.tsx +7 -28
- package/js/widgets/Dashboard/hooks/useRouteInfo/index.spec.tsx +25 -33
- package/js/widgets/Dashboard/index.spec.tsx +49 -43
- package/js/widgets/LanguageSelector/index.spec.tsx +7 -7
- package/js/widgets/LtiConsumer/index.spec.tsx +46 -48
- package/js/widgets/RootSearchSuggestField/index.spec.tsx +8 -6
- package/js/widgets/Search/components/PaginateCourseSearch/index.spec.tsx +10 -3
- package/js/widgets/Search/components/SearchFilterGroup/index.spec.tsx +5 -3
- package/js/widgets/Search/components/SearchFilterGroupModal/index.spec.tsx +8 -4
- package/js/widgets/Search/components/SearchFilterValueLeaf/index.spec.tsx +7 -3
- package/js/widgets/Search/components/SearchFilterValueParent/index.spec.tsx +12 -7
- package/js/widgets/Search/components/SearchFiltersPane/index.spec.tsx +5 -1
- package/js/widgets/Search/hooks/useCourseSearch/index.spec.tsx +4 -12
- package/js/widgets/Search/hooks/useFilterValue/index.spec.tsx +0 -2
- package/js/widgets/Search/index.spec.tsx +14 -6
- package/js/widgets/SearchSuggestField/index.spec.tsx +14 -1
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCertificateItem/index.spec.tsx +16 -31
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/index.spec.tsx +46 -72
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseRunItem/index.spec.tsx +5 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +147 -162
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/CourseRunUnenrollmentButton/index.spec.tsx +6 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.joanie.spec.tsx +22 -99
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.openedx.spec.tsx +27 -83
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunItem/index.spec.tsx +4 -1
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunItemWithEnrollment/index.spec.tsx +28 -35
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/hooks/useCourseWish/index.spec.tsx +9 -28
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/index.login.spec.tsx +23 -48
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/index.logout.spec.tsx +20 -29
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusSimpleCourseRunsList/index.spec.tsx +9 -4
- package/js/widgets/SyllabusCourseRunsList/hooks/useCourseEnrollment/index.spec.tsx +8 -10
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +28 -39
- package/js/widgets/UserLogin/components/UserMenu/index.spec.tsx +9 -6
- package/js/widgets/UserLogin/index.not.isJoanieEnabled.spec.tsx +21 -32
- package/js/widgets/UserLogin/index.spec.tsx +15 -37
- package/js/widgets/index.spec.tsx +12 -17
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import fetchMock from 'fetch-mock';
|
|
2
|
-
import {
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import { act, render, renderHook, waitFor } from '@testing-library/react';
|
|
2
|
+
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
5
3
|
import { PropsWithChildren } from 'react';
|
|
6
4
|
import {
|
|
7
5
|
RichieContextFactory as mockRichieContextFactory,
|
|
@@ -11,7 +9,9 @@ import { Deferred } from 'utils/test/deferred';
|
|
|
11
9
|
import { REACT_QUERY_SETTINGS, RICHIE_USER_TOKEN } from 'settings';
|
|
12
10
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
13
11
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
14
|
-
import
|
|
12
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
13
|
+
import { render } from 'utils/test/render';
|
|
14
|
+
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
|
|
15
15
|
import { useSession } from '.';
|
|
16
16
|
|
|
17
17
|
jest.mock('utils/errors/handle');
|
|
@@ -19,7 +19,7 @@ jest.mock('utils/context', () => ({
|
|
|
19
19
|
__esModule: true,
|
|
20
20
|
default: mockRichieContextFactory({
|
|
21
21
|
authentication: { backend: 'fonzie', endpoint: 'https://auth.endpoint.test' },
|
|
22
|
-
joanie_backend: { endpoint: 'https://joanie.endpoint
|
|
22
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
23
23
|
}).one(),
|
|
24
24
|
}));
|
|
25
25
|
jest.mock('utils/indirection/window', () => ({
|
|
@@ -30,23 +30,10 @@ jest.mock('utils/indirection/window', () => ({
|
|
|
30
30
|
|
|
31
31
|
// - Joanie Session Provider test suite
|
|
32
32
|
describe('JoanieSessionProvider', () => {
|
|
33
|
-
|
|
34
|
-
<IntlProvider locale="en">
|
|
35
|
-
<QueryClientProvider client={createTestQueryClient({ persister: true })}>
|
|
36
|
-
<JoanieSessionProvider>{children}</JoanieSessionProvider>
|
|
37
|
-
</QueryClientProvider>
|
|
38
|
-
</IntlProvider>
|
|
39
|
-
);
|
|
40
|
-
|
|
33
|
+
setupJoanieSession();
|
|
41
34
|
beforeEach(() => {
|
|
42
|
-
fetchMock.restore();
|
|
43
35
|
jest.useFakeTimers();
|
|
44
36
|
sessionStorage.clear();
|
|
45
|
-
|
|
46
|
-
fetchMock
|
|
47
|
-
.get('https://joanie.endpoint.test/api/v1.0/addresses/', [])
|
|
48
|
-
.get('https://joanie.endpoint.test/api/v1.0/credit-cards/', [])
|
|
49
|
-
.get('https://joanie.endpoint.test/api/v1.0/orders/', []);
|
|
50
37
|
});
|
|
51
38
|
|
|
52
39
|
afterEach(() => {
|
|
@@ -59,9 +46,13 @@ describe('JoanieSessionProvider', () => {
|
|
|
59
46
|
|
|
60
47
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', user);
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
render(
|
|
50
|
+
<BaseJoanieAppWrapper
|
|
51
|
+
queryOptions={{ client: createTestQueryClient({ persister: true }) }}
|
|
52
|
+
/>,
|
|
53
|
+
{ wrapper: null },
|
|
54
|
+
);
|
|
55
|
+
|
|
65
56
|
await waitFor(async () => {
|
|
66
57
|
expect(fetchMock.lastUrl()).toEqual('https://auth.endpoint.test/api/v1.0/user/me');
|
|
67
58
|
});
|
|
@@ -74,9 +65,12 @@ describe('JoanieSessionProvider', () => {
|
|
|
74
65
|
sessionStorage.setItem(RICHIE_USER_TOKEN, 'richie');
|
|
75
66
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', HttpStatusCode.FORBIDDEN);
|
|
76
67
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
render(
|
|
69
|
+
<BaseJoanieAppWrapper
|
|
70
|
+
queryOptions={{ client: createTestQueryClient({ persister: true }) }}
|
|
71
|
+
/>,
|
|
72
|
+
{ wrapper: null },
|
|
73
|
+
);
|
|
80
74
|
await waitFor(async () => {
|
|
81
75
|
expect(fetchMock.lastUrl()).toEqual('https://auth.endpoint.test/api/v1.0/user/me');
|
|
82
76
|
});
|
|
@@ -89,9 +83,12 @@ describe('JoanieSessionProvider', () => {
|
|
|
89
83
|
|
|
90
84
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', deferredUser.promise);
|
|
91
85
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
render(
|
|
87
|
+
<BaseJoanieAppWrapper
|
|
88
|
+
queryOptions={{ client: createTestQueryClient({ persister: true }) }}
|
|
89
|
+
/>,
|
|
90
|
+
{ wrapper: null },
|
|
91
|
+
);
|
|
95
92
|
|
|
96
93
|
await act(async () => deferredUser.resolve(user));
|
|
97
94
|
|
|
@@ -99,9 +96,9 @@ describe('JoanieSessionProvider', () => {
|
|
|
99
96
|
const calls = fetchMock.calls();
|
|
100
97
|
expect(calls).toHaveLength(4);
|
|
101
98
|
expect(calls[0][0]).toEqual('https://auth.endpoint.test/api/v1.0/user/me');
|
|
102
|
-
expect(calls[1][0]).toEqual('https://joanie.endpoint
|
|
103
|
-
expect(calls[2][0]).toEqual('https://joanie.endpoint
|
|
104
|
-
expect(calls[3][0]).toEqual('https://joanie.endpoint
|
|
99
|
+
expect(calls[1][0]).toEqual('https://joanie.endpoint/api/v1.0/addresses/');
|
|
100
|
+
expect(calls[2][0]).toEqual('https://joanie.endpoint/api/v1.0/credit-cards/');
|
|
101
|
+
expect(calls[3][0]).toEqual('https://joanie.endpoint/api/v1.0/orders/');
|
|
105
102
|
});
|
|
106
103
|
});
|
|
107
104
|
|
|
@@ -110,10 +107,12 @@ describe('JoanieSessionProvider', () => {
|
|
|
110
107
|
|
|
111
108
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', deferredUser.promise);
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
render(
|
|
111
|
+
<BaseJoanieAppWrapper
|
|
112
|
+
queryOptions={{ client: createTestQueryClient({ persister: true }) }}
|
|
113
|
+
/>,
|
|
114
|
+
{ wrapper: null },
|
|
115
|
+
);
|
|
117
116
|
await act(async () => deferredUser.resolve(null));
|
|
118
117
|
|
|
119
118
|
await waitFor(async () =>
|
|
@@ -130,7 +129,11 @@ describe('JoanieSessionProvider', () => {
|
|
|
130
129
|
|
|
131
130
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', userDeferred.promise);
|
|
132
131
|
const { result, rerender } = renderHook(useSession, {
|
|
133
|
-
wrapper:
|
|
132
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
133
|
+
<BaseJoanieAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
134
|
+
{children}
|
|
135
|
+
</BaseJoanieAppWrapper>
|
|
136
|
+
),
|
|
134
137
|
});
|
|
135
138
|
|
|
136
139
|
await act(async () => {
|
|
@@ -162,7 +165,11 @@ describe('JoanieSessionProvider', () => {
|
|
|
162
165
|
|
|
163
166
|
fetchMock.get('https://auth.endpoint.test/api/v1.0/user/me', userDeferred.promise);
|
|
164
167
|
const { result, rerender } = renderHook(useSession, {
|
|
165
|
-
wrapper:
|
|
168
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
169
|
+
<BaseJoanieAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
170
|
+
{children}
|
|
171
|
+
</BaseJoanieAppWrapper>
|
|
172
|
+
),
|
|
166
173
|
});
|
|
167
174
|
|
|
168
175
|
await act(async () => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
1
|
import { faker } from '@faker-js/faker';
|
|
3
2
|
import fetchMock from 'fetch-mock';
|
|
4
|
-
import { act,
|
|
3
|
+
import { act, renderHook, screen, waitFor } from '@testing-library/react';
|
|
5
4
|
import { PropsWithChildren } from 'react';
|
|
6
5
|
import {
|
|
7
6
|
RichieContextFactory as mockRichieContextFactory,
|
|
@@ -12,7 +11,8 @@ import { REACT_QUERY_SETTINGS } from 'settings';
|
|
|
12
11
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
13
12
|
import { User } from 'types/User';
|
|
14
13
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
15
|
-
import
|
|
14
|
+
import { render } from 'utils/test/render';
|
|
15
|
+
import { BaseAppWrapper } from 'utils/test/wrappers/BaseAppWrapper';
|
|
16
16
|
import { useSession } from '.';
|
|
17
17
|
|
|
18
18
|
jest.mock('utils/context', () => ({
|
|
@@ -23,7 +23,7 @@ jest.mock('utils/context', () => ({
|
|
|
23
23
|
backend: 'openedx-hawthorn',
|
|
24
24
|
},
|
|
25
25
|
joanie_backend: {
|
|
26
|
-
endpoint: 'https://joanie.
|
|
26
|
+
endpoint: 'https://joanie.endpoint',
|
|
27
27
|
},
|
|
28
28
|
}).one(),
|
|
29
29
|
}));
|
|
@@ -35,18 +35,9 @@ jest.mock('utils/indirection/window', () => ({
|
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
37
|
describe('SessionProvider', () => {
|
|
38
|
-
const wrapper =
|
|
39
|
-
(client?: QueryClient) =>
|
|
40
|
-
({ children }: PropsWithChildren) => (
|
|
41
|
-
<QueryClientProvider client={client ?? createTestQueryClient({ persister: true })}>
|
|
42
|
-
<BaseSessionProvider>{children}</BaseSessionProvider>
|
|
43
|
-
</QueryClientProvider>
|
|
44
|
-
);
|
|
45
|
-
|
|
46
38
|
beforeEach(() => {
|
|
47
39
|
jest.useFakeTimers();
|
|
48
40
|
jest.resetModules();
|
|
49
|
-
fetchMock.restore();
|
|
50
41
|
sessionStorage.clear();
|
|
51
42
|
});
|
|
52
43
|
|
|
@@ -69,7 +60,7 @@ describe('SessionProvider', () => {
|
|
|
69
60
|
}));
|
|
70
61
|
const { SessionProvider: Provider } = require('.');
|
|
71
62
|
|
|
72
|
-
render(<Provider
|
|
63
|
+
render(<Provider />, { wrapper: null });
|
|
73
64
|
|
|
74
65
|
await screen.findByText('BaseSessionProvider');
|
|
75
66
|
});
|
|
@@ -88,7 +79,7 @@ describe('SessionProvider', () => {
|
|
|
88
79
|
}));
|
|
89
80
|
const { SessionProvider: Provider } = require('.');
|
|
90
81
|
|
|
91
|
-
render(<Provider
|
|
82
|
+
render(<Provider />, { wrapper: null });
|
|
92
83
|
|
|
93
84
|
await screen.findByText('JoanieSessionProvider');
|
|
94
85
|
});
|
|
@@ -100,7 +91,11 @@ describe('SessionProvider', () => {
|
|
|
100
91
|
fetchMock.get('https://endpoint.test/api/user/v1/me', userDeferred.promise);
|
|
101
92
|
|
|
102
93
|
const { result } = renderHook(() => useSession(), {
|
|
103
|
-
wrapper:
|
|
94
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
95
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
96
|
+
{children}
|
|
97
|
+
</BaseAppWrapper>
|
|
98
|
+
),
|
|
104
99
|
});
|
|
105
100
|
|
|
106
101
|
await act(async () => {
|
|
@@ -127,7 +122,13 @@ describe('SessionProvider', () => {
|
|
|
127
122
|
const username = faker.internet.userName();
|
|
128
123
|
const userDeferred = new Deferred();
|
|
129
124
|
fetchMock.get('https://endpoint.test/api/user/v1/me', userDeferred.promise);
|
|
130
|
-
const { result } = renderHook(useSession, {
|
|
125
|
+
const { result } = renderHook(useSession, {
|
|
126
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
127
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
128
|
+
{children}
|
|
129
|
+
</BaseAppWrapper>
|
|
130
|
+
),
|
|
131
|
+
});
|
|
131
132
|
|
|
132
133
|
await act(async () => {
|
|
133
134
|
userDeferred.resolve({ username });
|
|
@@ -150,7 +151,13 @@ describe('SessionProvider', () => {
|
|
|
150
151
|
|
|
151
152
|
fetchMock.get('https://endpoint.test/api/user/v1/me', userDeferred.promise);
|
|
152
153
|
fetchMock.get('https://endpoint.test/logout', HttpStatusCode.OK);
|
|
153
|
-
const { result } = renderHook(useSession, {
|
|
154
|
+
const { result } = renderHook(useSession, {
|
|
155
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
156
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
157
|
+
{children}
|
|
158
|
+
</BaseAppWrapper>
|
|
159
|
+
),
|
|
160
|
+
});
|
|
154
161
|
|
|
155
162
|
await act(async () => {
|
|
156
163
|
userDeferred.resolve({ username });
|
|
@@ -178,7 +185,11 @@ describe('SessionProvider', () => {
|
|
|
178
185
|
fetchMock.get('https://endpoint.test/api/user/v1/me', HttpStatusCode.OK);
|
|
179
186
|
|
|
180
187
|
const { result } = renderHook(useSession, {
|
|
181
|
-
wrapper:
|
|
188
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
189
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ user }) }}>
|
|
190
|
+
{children}
|
|
191
|
+
</BaseAppWrapper>
|
|
192
|
+
),
|
|
182
193
|
});
|
|
183
194
|
|
|
184
195
|
expect(result.current.user).toStrictEqual(user);
|
|
@@ -190,7 +201,13 @@ describe('SessionProvider', () => {
|
|
|
190
201
|
const userDeferred = new Deferred();
|
|
191
202
|
|
|
192
203
|
fetchMock.get('https://endpoint.test/api/user/v1/me', userDeferred.promise);
|
|
193
|
-
const { result, rerender } = renderHook(useSession, {
|
|
204
|
+
const { result, rerender } = renderHook(useSession, {
|
|
205
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
206
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
207
|
+
{children}
|
|
208
|
+
</BaseAppWrapper>
|
|
209
|
+
),
|
|
210
|
+
});
|
|
194
211
|
|
|
195
212
|
await act(async () => {
|
|
196
213
|
userDeferred.resolve(user);
|
|
@@ -225,7 +242,11 @@ describe('SessionProvider', () => {
|
|
|
225
242
|
|
|
226
243
|
fetchMock.get('https://endpoint.test/api/user/v1/me', userDeferred.promise);
|
|
227
244
|
const { result, rerender } = renderHook(useSession, {
|
|
228
|
-
wrapper:
|
|
245
|
+
wrapper: ({ children }: PropsWithChildren) => (
|
|
246
|
+
<BaseAppWrapper queryOptions={{ client: createTestQueryClient({ persister: true }) }}>
|
|
247
|
+
{children}
|
|
248
|
+
</BaseAppWrapper>
|
|
249
|
+
),
|
|
229
250
|
});
|
|
230
251
|
|
|
231
252
|
await act(async () => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderHook, screen } from '@testing-library/react';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
4
4
|
import { handle as mockHandle } from 'utils/errors/handle';
|
|
5
5
|
import { noop } from 'utils';
|
|
6
|
+
import { render } from 'utils/test/render';
|
|
6
7
|
import { SessionProvider, useSession } from '.';
|
|
7
8
|
|
|
8
9
|
jest.mock('utils/errors/handle');
|
|
@@ -15,7 +16,7 @@ jest.mock('utils/context', () => ({
|
|
|
15
16
|
|
|
16
17
|
describe('SessionProvider with no authentication', () => {
|
|
17
18
|
it('uses any Provider', async () => {
|
|
18
|
-
render(<SessionProvider>Children</SessionProvider
|
|
19
|
+
render(<SessionProvider>Children</SessionProvider>, { wrapper: null });
|
|
19
20
|
await screen.findByText('Children');
|
|
20
21
|
});
|
|
21
22
|
|
|
@@ -23,7 +23,6 @@ describe('hooks/useCourseSearchParams', () => {
|
|
|
23
23
|
// Remove any keys added to the mockWindow location object, reset pathname to /search
|
|
24
24
|
Object.keys(mockWindow.location).forEach((key) => delete (mockWindow.location as any)[key]);
|
|
25
25
|
mockWindow.location.pathname = '/search';
|
|
26
|
-
jest.resetAllMocks();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
it('initializes with the URL query string', async () => {
|
|
@@ -7,7 +7,7 @@ import { noop } from 'utils';
|
|
|
7
7
|
import { mockPaginatedResponse } from 'utils/test/mockPaginatedResponse';
|
|
8
8
|
import { PER_PAGE } from 'settings';
|
|
9
9
|
import { HttpError, HttpStatusCode } from 'utils/errors/HttpError';
|
|
10
|
-
import {
|
|
10
|
+
import { ReactQueryAppWrapper } from 'utils/test/wrappers/ReactQueryAppWrapper';
|
|
11
11
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
12
12
|
import { QueryConfig, FetchDataFunction } from './utils/fetchEntity';
|
|
13
13
|
import useUnionResource from '.';
|
|
@@ -98,7 +98,7 @@ describe('useUnionResource', () => {
|
|
|
98
98
|
queryAConfig,
|
|
99
99
|
queryBConfig,
|
|
100
100
|
}),
|
|
101
|
-
{ wrapper:
|
|
101
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
102
102
|
);
|
|
103
103
|
|
|
104
104
|
expect(result.current.isLoading).toBe(true);
|
|
@@ -122,7 +122,7 @@ describe('useUnionResource', () => {
|
|
|
122
122
|
queryAConfig,
|
|
123
123
|
queryBConfig,
|
|
124
124
|
}),
|
|
125
|
-
{ wrapper:
|
|
125
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
126
126
|
);
|
|
127
127
|
|
|
128
128
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
@@ -141,7 +141,7 @@ describe('useUnionResource', () => {
|
|
|
141
141
|
queryAConfig,
|
|
142
142
|
queryBConfig,
|
|
143
143
|
}),
|
|
144
|
-
{ wrapper:
|
|
144
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
145
145
|
);
|
|
146
146
|
|
|
147
147
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
@@ -160,7 +160,7 @@ describe('useUnionResource', () => {
|
|
|
160
160
|
queryAConfig,
|
|
161
161
|
queryBConfig,
|
|
162
162
|
}),
|
|
163
|
-
{ wrapper:
|
|
163
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
164
164
|
);
|
|
165
165
|
|
|
166
166
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
@@ -203,7 +203,7 @@ describe('useUnionResource', () => {
|
|
|
203
203
|
queryAConfig,
|
|
204
204
|
queryBConfig,
|
|
205
205
|
}),
|
|
206
|
-
{ wrapper:
|
|
206
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
207
207
|
);
|
|
208
208
|
|
|
209
209
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
@@ -266,7 +266,7 @@ describe('useUnionResource', () => {
|
|
|
266
266
|
queryAConfig,
|
|
267
267
|
queryBConfig,
|
|
268
268
|
}),
|
|
269
|
-
{ wrapper:
|
|
269
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
270
270
|
);
|
|
271
271
|
|
|
272
272
|
expect(result.current.isLoading).toBe(true);
|
|
@@ -293,7 +293,7 @@ describe('useUnionResource', () => {
|
|
|
293
293
|
queryAConfig: queries?.queryA || queryAConfig,
|
|
294
294
|
queryBConfig: queries?.queryB || queryBConfig,
|
|
295
295
|
}),
|
|
296
|
-
{ wrapper:
|
|
296
|
+
{ wrapper: ReactQueryAppWrapper },
|
|
297
297
|
);
|
|
298
298
|
|
|
299
299
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
@@ -344,7 +344,9 @@ describe('useUnionResource', () => {
|
|
|
344
344
|
}),
|
|
345
345
|
{
|
|
346
346
|
wrapper: ({ children }) => (
|
|
347
|
-
<
|
|
347
|
+
<ReactQueryAppWrapper queryOptions={{ client: queryClient }}>
|
|
348
|
+
{children}
|
|
349
|
+
</ReactQueryAppWrapper>
|
|
348
350
|
),
|
|
349
351
|
},
|
|
350
352
|
);
|
package/js/utils/test/render.tsx
CHANGED
|
@@ -65,7 +65,11 @@ export const render: RenderFunction = (
|
|
|
65
65
|
rerenderOptions?: Partial<Omit<AppWrapperProps, 'testingLibraryOptions'>>,
|
|
66
66
|
) => {
|
|
67
67
|
return renderResult.rerender(
|
|
68
|
-
Wrapper === null ?
|
|
68
|
+
Wrapper === null ? (
|
|
69
|
+
rerenderElement
|
|
70
|
+
) : (
|
|
71
|
+
<Wrapper {...rerenderOptions}>{rerenderElement}</Wrapper>
|
|
72
|
+
),
|
|
69
73
|
);
|
|
70
74
|
},
|
|
71
75
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { IntlWrapper } from './IntlWrapper';
|
|
4
|
-
import { ReactQueryWrapper } from './ReactQueryWrapper';
|
|
2
|
+
import BaseSessionProvider from 'contexts/SessionContext/BaseSessionProvider';
|
|
5
3
|
import { AppWrapperProps } from './types';
|
|
4
|
+
import { ReactQueryAppWrapper } from './ReactQueryAppWrapper';
|
|
6
5
|
|
|
7
6
|
export const BaseAppWrapper = ({
|
|
8
7
|
children,
|
|
@@ -10,10 +9,8 @@ export const BaseAppWrapper = ({
|
|
|
10
9
|
queryOptions,
|
|
11
10
|
}: PropsWithChildren<AppWrapperProps>) => {
|
|
12
11
|
return (
|
|
13
|
-
<
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
</ReactQueryWrapper>
|
|
17
|
-
</IntlWrapper>
|
|
12
|
+
<ReactQueryAppWrapper queryOptions={queryOptions} intlOptions={intlOptions}>
|
|
13
|
+
<BaseSessionProvider>{children}</BaseSessionProvider>
|
|
14
|
+
</ReactQueryAppWrapper>
|
|
18
15
|
);
|
|
19
16
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
|
|
3
3
|
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
|
|
4
|
-
import { IntlWrapper } from './IntlWrapper';
|
|
5
|
-
import { ReactQueryWrapper } from './ReactQueryWrapper';
|
|
6
4
|
import { AppWrapperProps } from './types';
|
|
5
|
+
import { ReactQueryAppWrapper } from './ReactQueryAppWrapper';
|
|
7
6
|
|
|
8
7
|
export const BaseJoanieAppWrapper = ({
|
|
9
8
|
children,
|
|
@@ -11,10 +10,8 @@ export const BaseJoanieAppWrapper = ({
|
|
|
11
10
|
queryOptions,
|
|
12
11
|
}: PropsWithChildren<AppWrapperProps>) => {
|
|
13
12
|
return (
|
|
14
|
-
<
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
</ReactQueryWrapper>
|
|
18
|
-
</IntlWrapper>
|
|
13
|
+
<ReactQueryAppWrapper queryOptions={queryOptions} intlOptions={intlOptions}>
|
|
14
|
+
<JoanieSessionProvider>{children}</JoanieSessionProvider>
|
|
15
|
+
</ReactQueryAppWrapper>
|
|
19
16
|
);
|
|
20
17
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ComponentProps
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
2
|
import { IntlProvider, ReactIntlErrorCode } from 'react-intl';
|
|
3
3
|
|
|
4
|
-
export interface IntlWrapperProps extends
|
|
4
|
+
export interface IntlWrapperProps extends Omit<ComponentProps<typeof IntlProvider>, 'locale'> {
|
|
5
|
+
locale?: string;
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
export const IntlWrapper = ({ children, ...options }: IntlWrapperProps) => (
|
|
7
9
|
<IntlProvider
|
|
@@ -9,7 +9,7 @@ export const PresentationalAppWrapper = ({
|
|
|
9
9
|
routerOptions,
|
|
10
10
|
}: PropsWithChildren<{ intlOptions?: IntlWrapperProps; routerOptions?: RouterWrapperProps }>) => {
|
|
11
11
|
return (
|
|
12
|
-
<IntlWrapper {...
|
|
12
|
+
<IntlWrapper {...intlOptions}>
|
|
13
13
|
<CunninghamProvider>
|
|
14
14
|
<RouterWrapper {...routerOptions}>{children}</RouterWrapper>
|
|
15
15
|
</CunninghamProvider>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { IntlWrapper } from './IntlWrapper';
|
|
3
|
+
import { ReactQueryWrapper } from './ReactQueryWrapper';
|
|
4
|
+
import { AppWrapperProps } from './types';
|
|
5
|
+
|
|
6
|
+
export const ReactQueryAppWrapper = ({
|
|
7
|
+
children,
|
|
8
|
+
intlOptions,
|
|
9
|
+
queryOptions,
|
|
10
|
+
}: PropsWithChildren<AppWrapperProps>) => {
|
|
11
|
+
return (
|
|
12
|
+
<IntlWrapper {...intlOptions}>
|
|
13
|
+
<ReactQueryWrapper {...queryOptions}>{children}</ReactQueryWrapper>
|
|
14
|
+
</IntlWrapper>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
2
2
|
import { JoanieFileFactory } from 'utils/test/factories/joanie';
|
|
3
|
+
import { render } from 'utils/test/render';
|
|
3
4
|
import { DashboardAvatar, DashboardAvatarVariantEnum } from '.';
|
|
4
5
|
|
|
5
6
|
describe('<DashboardAvatar/>', () => {
|
|
6
7
|
it('should work with empty title', () => {
|
|
7
|
-
render(<DashboardAvatar title=""
|
|
8
|
+
render(<DashboardAvatar title="" />, { wrapper: null });
|
|
8
9
|
expect(screen.getByTestId('dashboard-avatar')).toHaveTextContent('');
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
it('should display the first letter of the title', () => {
|
|
12
|
-
render(<DashboardAvatar title="Bob"
|
|
13
|
+
render(<DashboardAvatar title="Bob" />, { wrapper: null });
|
|
13
14
|
expect(screen.getByTestId('dashboard-avatar')).toHaveTextContent('B');
|
|
14
15
|
});
|
|
15
16
|
|
|
@@ -18,14 +19,16 @@ describe('<DashboardAvatar/>', () => {
|
|
|
18
19
|
src: 'http://my.awesome.image',
|
|
19
20
|
srcset: '200w http://my.awesome.image/200',
|
|
20
21
|
}).one();
|
|
21
|
-
render(<DashboardAvatar title="Bob" image={image}
|
|
22
|
+
render(<DashboardAvatar title="Bob" image={image} />, { wrapper: null });
|
|
22
23
|
const img = screen.getByAltText('Bob');
|
|
23
24
|
expect(img).toHaveAttribute('src', 'http://my.awesome.image');
|
|
24
25
|
expect(img).toHaveAttribute('srcset', '200w http://my.awesome.image/200');
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
it('should contain the variant class for SQUARE', () => {
|
|
28
|
-
render(<DashboardAvatar title="Bob" variant={DashboardAvatarVariantEnum.SQUARE}
|
|
29
|
+
render(<DashboardAvatar title="Bob" variant={DashboardAvatarVariantEnum.SQUARE} />, {
|
|
30
|
+
wrapper: null,
|
|
31
|
+
});
|
|
29
32
|
expect(screen.getByTestId('dashboard-avatar')).toHaveClass('dashboard__avatar--square');
|
|
30
33
|
});
|
|
31
34
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
2
|
+
import { render } from 'utils/test/render';
|
|
2
3
|
import { DashboardBox } from '.';
|
|
3
4
|
|
|
4
5
|
describe('<DashboardBox/>', () => {
|
|
@@ -7,6 +8,7 @@ describe('<DashboardBox/>', () => {
|
|
|
7
8
|
<DashboardBox header="Header" footer="Footer">
|
|
8
9
|
Content
|
|
9
10
|
</DashboardBox>,
|
|
11
|
+
{ wrapper: null },
|
|
10
12
|
);
|
|
11
13
|
screen.getByText('Header');
|
|
12
14
|
screen.getByText('Content');
|