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
package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.joanie.spec.tsx
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { act, fireEvent,
|
|
1
|
+
import { act, fireEvent, screen } from '@testing-library/react';
|
|
2
2
|
import fetchMock from 'fetch-mock';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
5
3
|
|
|
6
4
|
import { faker } from '@faker-js/faker';
|
|
7
5
|
import { Deferred } from 'utils/test/deferred';
|
|
@@ -9,12 +7,12 @@ import { EnrollmentFactory as JoanieEnrollment } from 'utils/test/factories/joan
|
|
|
9
7
|
import {
|
|
10
8
|
CourseRunFactory,
|
|
11
9
|
RichieContextFactory as mockRichieContextFactory,
|
|
12
|
-
UserFactory,
|
|
13
10
|
} from 'utils/test/factories/richie';
|
|
14
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
15
|
-
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
16
11
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
17
12
|
import { Priority } from 'types';
|
|
13
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
14
|
+
import { render } from 'utils/test/render';
|
|
15
|
+
import { expectNoSpinner, expectSpinner } from 'utils/test/expectSpinner';
|
|
18
16
|
import CourseRunEnrollment from './index';
|
|
19
17
|
|
|
20
18
|
jest.mock('utils/errors/handle');
|
|
@@ -40,22 +38,15 @@ jest.mock('utils/context', () => ({
|
|
|
40
38
|
}));
|
|
41
39
|
|
|
42
40
|
describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
41
|
+
setupJoanieSession();
|
|
43
42
|
const endpoint = 'https://joanie.endpoint';
|
|
44
43
|
|
|
45
44
|
beforeEach(() => {
|
|
46
45
|
jest.useFakeTimers();
|
|
47
46
|
sessionStorage.clear();
|
|
48
|
-
fetchMock
|
|
49
|
-
.get('https://joanie.endpoint/api/v1.0/addresses/', [])
|
|
50
|
-
.get('https://joanie.endpoint/api/v1.0/credit-cards/', [])
|
|
51
|
-
.get('https://joanie.endpoint/api/v1.0/orders/', []);
|
|
52
47
|
});
|
|
53
48
|
|
|
54
|
-
afterEach(() => {
|
|
55
|
-
fetchMock.restore();
|
|
56
|
-
});
|
|
57
49
|
it('shows an "Enroll" button and allows the user to enroll', async () => {
|
|
58
|
-
const user = UserFactory().one();
|
|
59
50
|
const courseRun = CourseRunFactory().one();
|
|
60
51
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${courseRun.id}`;
|
|
61
52
|
|
|
@@ -65,19 +56,8 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
65
56
|
enrollmentDeferred.promise,
|
|
66
57
|
);
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
71
|
-
<IntlProvider locale="en">
|
|
72
|
-
<SessionProvider>
|
|
73
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
74
|
-
</SessionProvider>
|
|
75
|
-
</IntlProvider>
|
|
76
|
-
</QueryClientProvider>,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
59
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
60
|
+
await expectSpinner('Loading enrollment information...');
|
|
81
61
|
|
|
82
62
|
await act(async () => {
|
|
83
63
|
enrollmentDeferred.resolve({
|
|
@@ -85,6 +65,7 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
85
65
|
results: [],
|
|
86
66
|
});
|
|
87
67
|
});
|
|
68
|
+
await expectNoSpinner('Loading enrollment information...');
|
|
88
69
|
|
|
89
70
|
const button = await screen.findByRole('button', { name: 'Enroll now' });
|
|
90
71
|
const enrollActionDeferred = new Deferred();
|
|
@@ -93,11 +74,11 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
93
74
|
await act(async () => {
|
|
94
75
|
enrollActionDeferred.resolve(true);
|
|
95
76
|
});
|
|
96
|
-
|
|
77
|
+
|
|
78
|
+
expect(await screen.findByText('Unenroll from this course')).toBeInTheDocument();
|
|
97
79
|
});
|
|
98
80
|
|
|
99
81
|
it('shows an error message when enrollment get request failed', async () => {
|
|
100
|
-
const user = UserFactory().one();
|
|
101
82
|
const courseRun = CourseRunFactory().one();
|
|
102
83
|
const joanieEnrollmentId = faker.string.uuid();
|
|
103
84
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${joanieEnrollmentId}`;
|
|
@@ -107,25 +88,14 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
107
88
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
108
89
|
);
|
|
109
90
|
|
|
110
|
-
|
|
111
|
-
render(
|
|
112
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
113
|
-
<IntlProvider locale="en">
|
|
114
|
-
<SessionProvider>
|
|
115
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
116
|
-
</SessionProvider>
|
|
117
|
-
</IntlProvider>
|
|
118
|
-
</QueryClientProvider>,
|
|
119
|
-
);
|
|
120
|
-
});
|
|
91
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
121
92
|
|
|
122
|
-
await screen.findByText('Enrollment fetching failed');
|
|
93
|
+
expect(await screen.findByText('Enrollment fetching failed')).toBeInTheDocument();
|
|
123
94
|
});
|
|
124
95
|
|
|
125
96
|
it('shows a link to the course if the user is already enrolled', async () => {
|
|
126
97
|
// Joanie session requests
|
|
127
98
|
let nbApiCalls = 3;
|
|
128
|
-
const user = UserFactory().one();
|
|
129
99
|
const joanieEnrollment = JoanieEnrollment({ is_active: true }).one();
|
|
130
100
|
const courseRun = CourseRunFactory().one();
|
|
131
101
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${joanieEnrollment.course_run.id}/`;
|
|
@@ -142,17 +112,7 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
142
112
|
);
|
|
143
113
|
nbApiCalls += 1;
|
|
144
114
|
|
|
145
|
-
|
|
146
|
-
render(
|
|
147
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
148
|
-
<IntlProvider locale="en">
|
|
149
|
-
<SessionProvider>
|
|
150
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
151
|
-
</SessionProvider>
|
|
152
|
-
</IntlProvider>
|
|
153
|
-
</QueryClientProvider>,
|
|
154
|
-
);
|
|
155
|
-
});
|
|
115
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
156
116
|
|
|
157
117
|
const $goToCourseButton = await screen.findByRole('link', { name: 'Go to course' });
|
|
158
118
|
expect($goToCourseButton).toBeInTheDocument();
|
|
@@ -162,7 +122,6 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
162
122
|
});
|
|
163
123
|
|
|
164
124
|
it('shows an "Unenroll" text and allows the user to unenroll', async () => {
|
|
165
|
-
const user = UserFactory().one();
|
|
166
125
|
const courseRun = CourseRunFactory().one();
|
|
167
126
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${courseRun.id}`;
|
|
168
127
|
|
|
@@ -172,19 +131,8 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
172
131
|
enrollmentDeferred.promise,
|
|
173
132
|
);
|
|
174
133
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
178
|
-
<IntlProvider locale="en">
|
|
179
|
-
<SessionProvider>
|
|
180
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
181
|
-
</SessionProvider>
|
|
182
|
-
</IntlProvider>
|
|
183
|
-
</QueryClientProvider>,
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
134
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
135
|
+
await expectSpinner('Loading enrollment information...');
|
|
188
136
|
|
|
189
137
|
await act(async () => {
|
|
190
138
|
enrollmentDeferred.resolve({
|
|
@@ -213,11 +161,10 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
213
161
|
enrollActionDeferred.resolve(false);
|
|
214
162
|
});
|
|
215
163
|
|
|
216
|
-
await screen.findByRole('button', { name: 'Enroll now' });
|
|
164
|
+
expect(await screen.findByRole('button', { name: 'Enroll now' })).toBeInTheDocument();
|
|
217
165
|
});
|
|
218
166
|
|
|
219
167
|
it('shows an error message when the enrollment fails', async () => {
|
|
220
|
-
const user = UserFactory().one();
|
|
221
168
|
const courseRun = CourseRunFactory().one();
|
|
222
169
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${courseRun.id}`;
|
|
223
170
|
|
|
@@ -227,19 +174,9 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
227
174
|
enrollmentDeferred.promise,
|
|
228
175
|
);
|
|
229
176
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
233
|
-
<IntlProvider locale="en">
|
|
234
|
-
<SessionProvider>
|
|
235
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
236
|
-
</SessionProvider>
|
|
237
|
-
</IntlProvider>
|
|
238
|
-
</QueryClientProvider>,
|
|
239
|
-
);
|
|
240
|
-
});
|
|
177
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
178
|
+
await expectSpinner('Loading enrollment information...');
|
|
241
179
|
|
|
242
|
-
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
243
180
|
await act(async () => {
|
|
244
181
|
enrollmentDeferred.resolve({
|
|
245
182
|
count: 0,
|
|
@@ -249,14 +186,11 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
249
186
|
|
|
250
187
|
const button = await screen.findByRole('button', { name: 'Enroll now' });
|
|
251
188
|
fetchMock.post(`${endpoint}/api/v1.0/enrollments/`, HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
await screen.findByText('Your enrollment request failed.');
|
|
189
|
+
fireEvent.click(button);
|
|
190
|
+
expect(await screen.findByText('Your enrollment request failed.')).toBeInTheDocument();
|
|
256
191
|
});
|
|
257
192
|
|
|
258
193
|
it('shows an error message when the unenrollment fails', async () => {
|
|
259
|
-
const user = UserFactory().one();
|
|
260
194
|
const courseRun = CourseRunFactory().one();
|
|
261
195
|
courseRun.resource_link = `https://joanie.endpoint/api/v1.0/course-runs/${courseRun.id}`;
|
|
262
196
|
|
|
@@ -266,19 +200,8 @@ describe('<CourseRunEnrollment /> with joanie backend ', () => {
|
|
|
266
200
|
enrollmentDeferred.promise,
|
|
267
201
|
);
|
|
268
202
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
272
|
-
<IntlProvider locale="en">
|
|
273
|
-
<SessionProvider>
|
|
274
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
275
|
-
</SessionProvider>
|
|
276
|
-
</IntlProvider>
|
|
277
|
-
</QueryClientProvider>,
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
203
|
+
render(<CourseRunEnrollment courseRun={courseRun} />);
|
|
204
|
+
await expectSpinner('Loading enrollment information...');
|
|
282
205
|
|
|
283
206
|
await act(async () => {
|
|
284
207
|
enrollmentDeferred.resolve({
|
package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.openedx.spec.tsx
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { act, fireEvent,
|
|
1
|
+
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
import fetchMock from 'fetch-mock';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
5
3
|
import { CourseRun } from 'types';
|
|
6
4
|
import { Deferred } from 'utils/test/deferred';
|
|
7
5
|
import {
|
|
@@ -10,10 +8,12 @@ import {
|
|
|
10
8
|
UserFactory,
|
|
11
9
|
} from 'utils/test/factories/richie';
|
|
12
10
|
import { handle } from 'utils/errors/handle';
|
|
13
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
14
11
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
15
12
|
import { User } from 'types/User';
|
|
16
13
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
14
|
+
import { BaseAppWrapper } from 'utils/test/wrappers/BaseAppWrapper';
|
|
15
|
+
import { render } from 'utils/test/render';
|
|
16
|
+
import { expectNoSpinner, expectSpinner } from 'utils/test/expectSpinner';
|
|
17
17
|
import CourseRunEnrollment from './index';
|
|
18
18
|
|
|
19
19
|
jest.mock('utils/errors/handle');
|
|
@@ -43,14 +43,6 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
43
43
|
beforeEach(() => {
|
|
44
44
|
jest.useFakeTimers();
|
|
45
45
|
sessionStorage.clear();
|
|
46
|
-
fetchMock
|
|
47
|
-
.get('https://joanie.endpoint/api/v1.0/addresses/', [])
|
|
48
|
-
.get('https://joanie.endpoint/api/v1.0/credit-cards/', [])
|
|
49
|
-
.get('https://joanie.endpoint/api/v1.0/orders/', []);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
afterEach(() => {
|
|
53
|
-
fetchMock.restore();
|
|
54
46
|
});
|
|
55
47
|
|
|
56
48
|
it('shows an "Enroll" button and allows the user to enroll', async () => {
|
|
@@ -65,22 +57,16 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
65
57
|
enrollmentsDeferred.promise,
|
|
66
58
|
);
|
|
67
59
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<IntlProvider locale="en">
|
|
72
|
-
<SessionProvider>
|
|
73
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
74
|
-
</SessionProvider>
|
|
75
|
-
</IntlProvider>
|
|
76
|
-
</QueryClientProvider>,
|
|
77
|
-
);
|
|
60
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
61
|
+
wrapper: BaseAppWrapper,
|
|
62
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
78
63
|
});
|
|
79
|
-
|
|
64
|
+
await expectSpinner('Loading enrollment information...');
|
|
80
65
|
|
|
81
66
|
await act(async () => {
|
|
82
67
|
enrollmentsDeferred.resolve({});
|
|
83
68
|
});
|
|
69
|
+
await expectNoSpinner('Loading enrollment information...');
|
|
84
70
|
|
|
85
71
|
const button = await screen.findByRole('button', { name: 'Enroll now' });
|
|
86
72
|
|
|
@@ -110,16 +96,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
110
96
|
enrollmentDeferred.promise,
|
|
111
97
|
);
|
|
112
98
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<IntlProvider locale="en">
|
|
117
|
-
<SessionProvider>
|
|
118
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
119
|
-
</SessionProvider>
|
|
120
|
-
</IntlProvider>
|
|
121
|
-
</QueryClientProvider>,
|
|
122
|
-
);
|
|
99
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
100
|
+
wrapper: BaseAppWrapper,
|
|
101
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
123
102
|
});
|
|
124
103
|
|
|
125
104
|
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
@@ -160,16 +139,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
160
139
|
enrollmentDeferred.promise,
|
|
161
140
|
);
|
|
162
141
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
<IntlProvider locale="en">
|
|
167
|
-
<SessionProvider>
|
|
168
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
169
|
-
</SessionProvider>
|
|
170
|
-
</IntlProvider>
|
|
171
|
-
</QueryClientProvider>,
|
|
172
|
-
);
|
|
142
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
143
|
+
wrapper: BaseAppWrapper,
|
|
144
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
173
145
|
});
|
|
174
146
|
|
|
175
147
|
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
@@ -206,16 +178,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
206
178
|
enrollmentsDeferred.promise,
|
|
207
179
|
);
|
|
208
180
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
<IntlProvider locale="en">
|
|
213
|
-
<SessionProvider>
|
|
214
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
215
|
-
</SessionProvider>
|
|
216
|
-
</IntlProvider>
|
|
217
|
-
</QueryClientProvider>,
|
|
218
|
-
);
|
|
181
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
182
|
+
wrapper: BaseAppWrapper,
|
|
183
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
219
184
|
});
|
|
220
185
|
|
|
221
186
|
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
@@ -244,16 +209,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
244
209
|
enrollmentsDeferred.promise,
|
|
245
210
|
);
|
|
246
211
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
<IntlProvider locale="en">
|
|
251
|
-
<SessionProvider>
|
|
252
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
253
|
-
</SessionProvider>
|
|
254
|
-
</IntlProvider>
|
|
255
|
-
</QueryClientProvider>,
|
|
256
|
-
);
|
|
212
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
213
|
+
wrapper: BaseAppWrapper,
|
|
214
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
257
215
|
});
|
|
258
216
|
|
|
259
217
|
screen.getByRole('status', { name: 'Loading enrollment information...' });
|
|
@@ -277,16 +235,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
277
235
|
courseRun.resource_link = 'https://openedx.endpoint' + courseRun.resource_link;
|
|
278
236
|
courseRun.state.priority = 4;
|
|
279
237
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
<IntlProvider locale="en">
|
|
284
|
-
<SessionProvider>
|
|
285
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
286
|
-
</SessionProvider>
|
|
287
|
-
</IntlProvider>
|
|
288
|
-
</QueryClientProvider>,
|
|
289
|
-
);
|
|
238
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
239
|
+
wrapper: BaseAppWrapper,
|
|
240
|
+
queryOptions: { client: createTestQueryClient({ user: null }) },
|
|
290
241
|
});
|
|
291
242
|
|
|
292
243
|
screen.getByText('Enrollment in this course run is closed at the moment');
|
|
@@ -298,16 +249,9 @@ describe('<CourseRunEnrollment />', () => {
|
|
|
298
249
|
courseRun.resource_link = 'https://openedx.endpoint' + courseRun.resource_link;
|
|
299
250
|
courseRun.state.priority = 0;
|
|
300
251
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
<IntlProvider locale="en">
|
|
305
|
-
<SessionProvider>
|
|
306
|
-
<CourseRunEnrollment courseRun={courseRun} />
|
|
307
|
-
</SessionProvider>
|
|
308
|
-
</IntlProvider>
|
|
309
|
-
</QueryClientProvider>,
|
|
310
|
-
);
|
|
252
|
+
render(<CourseRunEnrollment courseRun={courseRun} />, {
|
|
253
|
+
wrapper: BaseAppWrapper,
|
|
254
|
+
queryOptions: { client: createTestQueryClient({ user: null }) },
|
|
311
255
|
});
|
|
312
256
|
|
|
313
257
|
screen.getByRole('button', { name: 'Log in to enroll' });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
2
2
|
import { IntlProvider } from 'react-intl';
|
|
3
3
|
import { CourseRunFactory } from 'utils/test/factories/richie';
|
|
4
|
+
import { render } from 'utils/test/render';
|
|
4
5
|
import CourseRunItem from '.';
|
|
5
6
|
|
|
6
7
|
describe('CourseRunItem', () => {
|
|
@@ -15,6 +16,7 @@ describe('CourseRunItem', () => {
|
|
|
15
16
|
<IntlProvider locale="en">
|
|
16
17
|
<CourseRunItem item={courseRun} />
|
|
17
18
|
</IntlProvider>,
|
|
19
|
+
{ wrapper: null },
|
|
18
20
|
);
|
|
19
21
|
|
|
20
22
|
// First title letter should have been capitalized
|
|
@@ -33,6 +35,7 @@ describe('CourseRunItem', () => {
|
|
|
33
35
|
<IntlProvider locale="en">
|
|
34
36
|
<CourseRunItem item={courseRun} />
|
|
35
37
|
</IntlProvider>,
|
|
38
|
+
{ wrapper: null },
|
|
36
39
|
);
|
|
37
40
|
|
|
38
41
|
// Only dates should have been displayed.
|
package/js/widgets/SyllabusCourseRunsList/components/CourseRunItemWithEnrollment/index.spec.tsx
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IntlProvider } from 'react-intl';
|
|
3
|
-
import { PropsWithChildren } from 'react';
|
|
4
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
1
|
+
import { screen, waitFor } from '@testing-library/react';
|
|
5
2
|
import fetchMock from 'fetch-mock';
|
|
6
3
|
import {
|
|
7
4
|
CourseRunFactory,
|
|
@@ -9,7 +6,8 @@ import {
|
|
|
9
6
|
UserFactory,
|
|
10
7
|
} from 'utils/test/factories/richie';
|
|
11
8
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
12
|
-
import
|
|
9
|
+
import { BaseAppWrapper } from 'utils/test/wrappers/BaseAppWrapper';
|
|
10
|
+
import { render } from 'utils/test/render';
|
|
13
11
|
import CourseRunItemWithEnrollment from '.';
|
|
14
12
|
|
|
15
13
|
jest.mock('utils/context', () => ({
|
|
@@ -26,32 +24,21 @@ jest.mock('utils/context', () => ({
|
|
|
26
24
|
}));
|
|
27
25
|
|
|
28
26
|
describe('CourseRunItemWithEnrollment', () => {
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<QueryClientProvider client={client ?? createTestQueryClient({ user: true })}>
|
|
32
|
-
<IntlProvider locale="en">
|
|
33
|
-
<BaseSessionProvider>{children}</BaseSessionProvider>
|
|
34
|
-
</IntlProvider>
|
|
35
|
-
</QueryClientProvider>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
fetchMock.restore();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should not render enrollment information when user is anonymous', () => {
|
|
27
|
+
it('should not render enrollment information when user is anonymous', async () => {
|
|
44
28
|
const courseRun = CourseRunFactory({
|
|
45
29
|
title: 'run',
|
|
46
30
|
start: new Date('2023-01-01').toISOString(),
|
|
47
31
|
end: new Date('2023-12-31').toISOString(),
|
|
48
32
|
}).one();
|
|
49
33
|
|
|
50
|
-
render(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
render(<CourseRunItemWithEnrollment item={courseRun} />, {
|
|
35
|
+
wrapper: BaseAppWrapper,
|
|
36
|
+
queryOptions: { client: createTestQueryClient({ user: null }) },
|
|
37
|
+
});
|
|
38
|
+
// session loader
|
|
39
|
+
await waitFor(() => {
|
|
40
|
+
expect(screen.queryByText('loading...')).not.toBeInTheDocument();
|
|
41
|
+
});
|
|
55
42
|
|
|
56
43
|
// First title letter should have been capitalized
|
|
57
44
|
// Dates should have been formatted as "Month day, year"
|
|
@@ -76,11 +63,14 @@ describe('CourseRunItemWithEnrollment', () => {
|
|
|
76
63
|
},
|
|
77
64
|
);
|
|
78
65
|
|
|
79
|
-
render(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
render(<CourseRunItemWithEnrollment item={courseRun} />, {
|
|
67
|
+
wrapper: BaseAppWrapper,
|
|
68
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
69
|
+
});
|
|
70
|
+
// session loader
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
expect(screen.queryByText('loading...')).not.toBeInTheDocument();
|
|
73
|
+
});
|
|
84
74
|
|
|
85
75
|
// Only dates should have been displayed.
|
|
86
76
|
screen.getByText('Run, from Jan 01, 2023 to Dec 31, 2023');
|
|
@@ -107,11 +97,14 @@ describe('CourseRunItemWithEnrollment', () => {
|
|
|
107
97
|
},
|
|
108
98
|
);
|
|
109
99
|
|
|
110
|
-
render(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
render(<CourseRunItemWithEnrollment item={courseRun} />, {
|
|
101
|
+
wrapper: BaseAppWrapper,
|
|
102
|
+
queryOptions: { client: createTestQueryClient({ user }) },
|
|
103
|
+
});
|
|
104
|
+
// session loader
|
|
105
|
+
await waitFor(() => {
|
|
106
|
+
expect(screen.queryByText('loading...')).not.toBeInTheDocument();
|
|
107
|
+
});
|
|
115
108
|
|
|
116
109
|
// Only dates should have been displayed.
|
|
117
110
|
screen.getByText('Run, from Jan 01, 2023 to Dec 31, 2023');
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
2
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
3
|
-
import { IntlProvider } from 'react-intl';
|
|
4
2
|
import fetchMock from 'fetch-mock';
|
|
5
|
-
import { PropsWithChildren } from 'react';
|
|
6
3
|
import { Deferred } from 'utils/test/deferred';
|
|
7
4
|
import {
|
|
8
5
|
CourseLightFactory,
|
|
9
6
|
RichieContextFactory as mockRichieContextFactory,
|
|
10
7
|
} from 'utils/test/factories/richie';
|
|
11
|
-
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
12
|
-
import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
13
|
-
import BaseSessionProvider from 'contexts/SessionContext/BaseSessionProvider';
|
|
14
8
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
9
|
+
import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
15
10
|
import { useCourseWish } from '.';
|
|
16
11
|
|
|
17
12
|
jest.mock('utils/context', () => ({
|
|
@@ -22,37 +17,23 @@ jest.mock('utils/context', () => ({
|
|
|
22
17
|
endpoint: 'https://authentication.test',
|
|
23
18
|
},
|
|
24
19
|
joanie_backend: {
|
|
25
|
-
endpoint: 'https://joanie.
|
|
20
|
+
endpoint: 'https://joanie.endpoint',
|
|
26
21
|
},
|
|
27
22
|
}).one(),
|
|
28
23
|
}));
|
|
29
24
|
|
|
30
25
|
describe('useCourseWish', () => {
|
|
26
|
+
setupJoanieSession();
|
|
31
27
|
const course = CourseLightFactory().one();
|
|
32
28
|
|
|
33
|
-
afterEach(() => {
|
|
34
|
-
jest.clearAllMocks();
|
|
35
|
-
fetchMock.restore();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const Wrapper = ({ children }: PropsWithChildren) => (
|
|
39
|
-
<IntlProvider locale="en">
|
|
40
|
-
<QueryClientProvider client={createTestQueryClient({ user: true })}>
|
|
41
|
-
<JoanieApiProvider>
|
|
42
|
-
<BaseSessionProvider>{children}</BaseSessionProvider>
|
|
43
|
-
</JoanieApiProvider>
|
|
44
|
-
</QueryClientProvider>
|
|
45
|
-
</IntlProvider>
|
|
46
|
-
);
|
|
47
|
-
|
|
48
29
|
it('retrieves course wish', async () => {
|
|
49
30
|
const responseDeferred = new Deferred();
|
|
50
31
|
|
|
51
|
-
const urlGetWishlistById = `https://joanie.
|
|
32
|
+
const urlGetWishlistById = `https://joanie.endpoint/api/v1.0/courses/${course.id}/wish/`;
|
|
52
33
|
fetchMock.get(urlGetWishlistById, responseDeferred.promise);
|
|
53
34
|
|
|
54
35
|
const { result } = renderHook(() => useCourseWish(course.id), {
|
|
55
|
-
wrapper:
|
|
36
|
+
wrapper: JoanieAppWrapper,
|
|
56
37
|
});
|
|
57
38
|
|
|
58
39
|
await waitFor(() => expect(result.current.states.fetching).toBe(true));
|
|
@@ -72,7 +53,7 @@ describe('useCourseWish', () => {
|
|
|
72
53
|
});
|
|
73
54
|
|
|
74
55
|
it('adds a course wish', async () => {
|
|
75
|
-
const urlWishlist = `https://joanie.
|
|
56
|
+
const urlWishlist = `https://joanie.endpoint/api/v1.0/courses/${course.code}/wish/`;
|
|
76
57
|
fetchMock.get(urlWishlist, {
|
|
77
58
|
status: HttpStatusCode.OK,
|
|
78
59
|
body: {
|
|
@@ -80,7 +61,7 @@ describe('useCourseWish', () => {
|
|
|
80
61
|
},
|
|
81
62
|
});
|
|
82
63
|
const { result } = renderHook(() => useCourseWish(course.code!), {
|
|
83
|
-
wrapper:
|
|
64
|
+
wrapper: JoanieAppWrapper,
|
|
84
65
|
});
|
|
85
66
|
fetchMock.restore();
|
|
86
67
|
|
|
@@ -106,7 +87,7 @@ describe('useCourseWish', () => {
|
|
|
106
87
|
});
|
|
107
88
|
|
|
108
89
|
it('removes a course to user wishlist', async () => {
|
|
109
|
-
const url = `https://joanie.
|
|
90
|
+
const url = `https://joanie.endpoint/api/v1.0/courses/${course.code}/wish/`;
|
|
110
91
|
fetchMock.get(url, {
|
|
111
92
|
status: HttpStatusCode.OK,
|
|
112
93
|
body: {
|
|
@@ -114,7 +95,7 @@ describe('useCourseWish', () => {
|
|
|
114
95
|
},
|
|
115
96
|
});
|
|
116
97
|
const { result } = renderHook(() => useCourseWish(course.code!), {
|
|
117
|
-
wrapper:
|
|
98
|
+
wrapper: JoanieAppWrapper,
|
|
118
99
|
});
|
|
119
100
|
fetchMock.restore();
|
|
120
101
|
|