richie-education 2.25.0-b2.dev148 → 2.25.0-b2.dev155
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,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PropsWithChildren } from 'react';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
1
|
+
import { screen, waitFor } from '@testing-library/react';
|
|
5
2
|
import userEvent from '@testing-library/user-event';
|
|
6
3
|
import fetchMock from 'fetch-mock';
|
|
7
4
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
8
5
|
import { Certificate, ProductType } from 'types/Joanie';
|
|
9
|
-
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
10
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
11
6
|
import { DashboardItemCertificate } from 'widgets/Dashboard/components/DashboardItem/Certificate/index';
|
|
12
7
|
import { DEFAULT_DATE_FORMAT } from 'hooks/useDateFormat';
|
|
13
8
|
import {
|
|
@@ -17,12 +12,15 @@ import {
|
|
|
17
12
|
NestedCredentialOrderFactory,
|
|
18
13
|
} from 'utils/test/factories/joanie';
|
|
19
14
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
15
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
16
|
+
import { render } from 'utils/test/render';
|
|
17
|
+
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
|
|
20
18
|
|
|
21
19
|
jest.mock('utils/context', () => ({
|
|
22
20
|
__esModule: true,
|
|
23
21
|
default: mockRichieContextFactory({
|
|
24
22
|
authentication: { backend: 'fonzie', endpoint: 'https://auth.test' },
|
|
25
|
-
joanie_backend: { endpoint: 'https://joanie.
|
|
23
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
26
24
|
}).one(),
|
|
27
25
|
}));
|
|
28
26
|
|
|
@@ -49,15 +47,7 @@ describe.each([
|
|
|
49
47
|
}),
|
|
50
48
|
},
|
|
51
49
|
])('<DashboardCertificate/> $label', ({ overrideFactory }) => {
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<QueryClientProvider client={createTestQueryClient({ user: true })}>
|
|
55
|
-
<IntlProvider locale="en">
|
|
56
|
-
<SessionProvider>{children}</SessionProvider>
|
|
57
|
-
</IntlProvider>
|
|
58
|
-
</QueryClientProvider>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
50
|
+
setupJoanieSession();
|
|
61
51
|
|
|
62
52
|
beforeAll(() => {
|
|
63
53
|
// eslint-disable-next-line compat/compat
|
|
@@ -67,23 +57,11 @@ describe.each([
|
|
|
67
57
|
HTMLAnchorElement.prototype.click = jest.fn();
|
|
68
58
|
});
|
|
69
59
|
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
// SessionProvider queries
|
|
72
|
-
fetchMock.get('https://joanie.test/api/v1.0/orders/', []);
|
|
73
|
-
fetchMock.get('https://joanie.test/api/v1.0/addresses/', []);
|
|
74
|
-
fetchMock.get('https://joanie.test/api/v1.0/credit-cards/', []);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
afterEach(() => {
|
|
78
|
-
jest.clearAllMocks();
|
|
79
|
-
fetchMock.restore();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
60
|
it('displays a certificate', async () => {
|
|
83
61
|
const certificate: Certificate = CertificateFactory(overrideFactory()).one();
|
|
84
62
|
render(
|
|
85
63
|
<DashboardItemCertificate certificate={certificate} productType={ProductType.CREDENTIAL} />,
|
|
86
|
-
{ wrapper:
|
|
64
|
+
{ wrapper: BaseJoanieAppWrapper },
|
|
87
65
|
);
|
|
88
66
|
|
|
89
67
|
await waitFor(() => screen.getByText(certificate.certificate_definition.title));
|
|
@@ -107,18 +85,20 @@ describe.each([
|
|
|
107
85
|
it('downloads the certificate', async () => {
|
|
108
86
|
const certificate: Certificate = CertificateFactory(overrideFactory()).one();
|
|
109
87
|
|
|
110
|
-
fetchMock.get(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
88
|
+
fetchMock.get(
|
|
89
|
+
`https://joanie.endpoint/api/v1.0/certificates/${certificate.id}/download/`,
|
|
90
|
+
() => ({
|
|
91
|
+
status: HttpStatusCode.OK,
|
|
92
|
+
body: new Blob(['test']),
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Disposition': 'attachment; filename="test.pdf";',
|
|
95
|
+
'Content-Type': 'application/pdf',
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
119
99
|
render(
|
|
120
100
|
<DashboardItemCertificate certificate={certificate} productType={ProductType.CREDENTIAL} />,
|
|
121
|
-
{ wrapper:
|
|
101
|
+
{ wrapper: BaseJoanieAppWrapper },
|
|
122
102
|
);
|
|
123
103
|
|
|
124
104
|
await waitFor(() => screen.getByText(certificate.certificate_definition.title));
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
3
|
import { ProductType } from 'types/Joanie';
|
|
4
4
|
import { CertificateFactory } from 'utils/test/factories/joanie';
|
|
5
|
-
import
|
|
5
|
+
import { render } from 'utils/test/render';
|
|
6
|
+
import { IntlWrapper } from 'utils/test/wrappers/IntlWrapper';
|
|
7
|
+
import CertificateStatus from '.';
|
|
6
8
|
|
|
7
9
|
describe('<CertificateStatus/>', () => {
|
|
8
|
-
const Wrapper = ({ certificate, productType }: CertificateStatusProps) => (
|
|
9
|
-
<IntlProvider locale="en">
|
|
10
|
-
<CertificateStatus certificate={certificate} productType={productType} />
|
|
11
|
-
</IntlProvider>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
10
|
it('should display message for issued certificate.', () => {
|
|
15
11
|
const certificate = CertificateFactory({
|
|
16
12
|
issued_on: new Date('01/01/2021').toISOString(),
|
|
17
13
|
}).one();
|
|
18
|
-
render(<
|
|
14
|
+
render(<CertificateStatus certificate={certificate} productType={ProductType.CERTIFICATE} />, {
|
|
15
|
+
wrapper: ({ children }: PropsWithChildren) => <IntlWrapper>{children}</IntlWrapper>,
|
|
16
|
+
});
|
|
19
17
|
expect(screen.getByText('Issued on Jan 01, 2021')).toBeInTheDocument();
|
|
20
18
|
|
|
21
19
|
expect(
|
|
@@ -31,7 +29,9 @@ describe('<CertificateStatus/>', () => {
|
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
it('should display message for no certificate of product type certificate.', () => {
|
|
34
|
-
render(<
|
|
32
|
+
render(<CertificateStatus productType={ProductType.CERTIFICATE} />, {
|
|
33
|
+
wrapper: ({ children }: PropsWithChildren) => <IntlWrapper>{children}</IntlWrapper>,
|
|
34
|
+
});
|
|
35
35
|
|
|
36
36
|
expect(
|
|
37
37
|
screen.getByText(
|
|
@@ -48,7 +48,9 @@ describe('<CertificateStatus/>', () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('should display message for no certificate of product type credential.', () => {
|
|
51
|
-
render(<
|
|
51
|
+
render(<CertificateStatus productType={ProductType.CREDENTIAL} />, {
|
|
52
|
+
wrapper: ({ children }: PropsWithChildren) => <IntlWrapper>{children}</IntlWrapper>,
|
|
53
|
+
});
|
|
52
54
|
expect(
|
|
53
55
|
screen.getByText(
|
|
54
56
|
'When all your courses have been passed, you will be able to download your certificate here.',
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PropsWithChildren } from 'react';
|
|
3
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
5
|
-
import fetchMock from 'fetch-mock';
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
6
2
|
import { faker } from '@faker-js/faker';
|
|
7
|
-
import { MemoryRouter } from 'react-router-dom';
|
|
8
3
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
9
4
|
import { Contract, NestedCredentialOrder } from 'types/Joanie';
|
|
10
|
-
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
11
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
12
5
|
import { DashboardItemContract } from 'widgets/Dashboard/components/DashboardItem/Contract/index';
|
|
13
6
|
import { DEFAULT_DATE_FORMAT } from 'hooks/useDateFormat';
|
|
14
7
|
import {
|
|
@@ -16,12 +9,14 @@ import {
|
|
|
16
9
|
CredentialOrderFactory,
|
|
17
10
|
NestedCredentialOrderFactory,
|
|
18
11
|
} from 'utils/test/factories/joanie';
|
|
12
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
13
|
+
import { render } from 'utils/test/render';
|
|
19
14
|
|
|
20
15
|
jest.mock('utils/context', () => ({
|
|
21
16
|
__esModule: true,
|
|
22
17
|
default: mockRichieContextFactory({
|
|
23
18
|
authentication: { backend: 'fonzie', endpoint: 'https://auth.test' },
|
|
24
|
-
joanie_backend: { endpoint: 'https://joanie.
|
|
19
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
25
20
|
}).one(),
|
|
26
21
|
}));
|
|
27
22
|
|
|
@@ -35,34 +30,13 @@ describe.each([
|
|
|
35
30
|
OrderSerializer: CredentialOrderFactory,
|
|
36
31
|
},
|
|
37
32
|
])('<DashboardContract/> $label', ({ OrderSerializer }) => {
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<QueryClientProvider client={createTestQueryClient({ user: true })}>
|
|
41
|
-
<IntlProvider locale="en">
|
|
42
|
-
<SessionProvider>
|
|
43
|
-
<MemoryRouter>{children}</MemoryRouter>
|
|
44
|
-
</SessionProvider>
|
|
45
|
-
</IntlProvider>
|
|
46
|
-
</QueryClientProvider>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
33
|
+
setupJoanieSession();
|
|
49
34
|
|
|
50
35
|
beforeAll(() => {
|
|
51
36
|
// eslint-disable-next-line compat/compat
|
|
52
37
|
URL.createObjectURL = jest.fn();
|
|
53
38
|
});
|
|
54
39
|
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
fetchMock.get('https://joanie.test/api/v1.0/orders/', []);
|
|
57
|
-
fetchMock.get('https://joanie.test/api/v1.0/addresses/', []);
|
|
58
|
-
fetchMock.get('https://joanie.test/api/v1.0/credit-cards/', []);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
afterEach(() => {
|
|
62
|
-
jest.clearAllMocks();
|
|
63
|
-
fetchMock.restore();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
40
|
it.each([
|
|
67
41
|
{ label: 'writable', writable: true },
|
|
68
42
|
{ label: 'none-writable', writable: false },
|
|
@@ -81,9 +55,6 @@ describe.each([
|
|
|
81
55
|
contract={contract}
|
|
82
56
|
writable={writable}
|
|
83
57
|
/>,
|
|
84
|
-
{
|
|
85
|
-
wrapper: Wrapper,
|
|
86
|
-
},
|
|
87
58
|
);
|
|
88
59
|
|
|
89
60
|
expect(await screen.findByText(contract.definition.title)).toBeInTheDocument();
|
|
@@ -118,9 +89,6 @@ describe.each([
|
|
|
118
89
|
contract={contract}
|
|
119
90
|
writable={writable}
|
|
120
91
|
/>,
|
|
121
|
-
{
|
|
122
|
-
wrapper: Wrapper,
|
|
123
|
-
},
|
|
124
92
|
);
|
|
125
93
|
|
|
126
94
|
expect(await screen.findByText(contract.definition.title)).toBeInTheDocument();
|
|
@@ -149,9 +117,6 @@ describe.each([
|
|
|
149
117
|
contract={contract}
|
|
150
118
|
writable={true}
|
|
151
119
|
/>,
|
|
152
|
-
{
|
|
153
|
-
wrapper: Wrapper,
|
|
154
|
-
},
|
|
155
120
|
);
|
|
156
121
|
|
|
157
122
|
expect(await screen.findByText(contract.definition.title)).toBeInTheDocument();
|
|
@@ -179,9 +144,6 @@ describe.each([
|
|
|
179
144
|
contract={contract}
|
|
180
145
|
writable={false}
|
|
181
146
|
/>,
|
|
182
|
-
{
|
|
183
|
-
wrapper: Wrapper,
|
|
184
|
-
},
|
|
185
147
|
);
|
|
186
148
|
|
|
187
149
|
expect(await screen.findByText(contract.definition.title)).toBeInTheDocument();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
2
|
+
import { createIntl } from 'react-intl';
|
|
3
3
|
import { PropsWithChildren } from 'react';
|
|
4
4
|
import { CredentialOrderFactory, EnrollmentFactory } from 'utils/test/factories/joanie';
|
|
5
5
|
import { Priority } from 'types';
|
|
@@ -9,6 +9,8 @@ import { CourseRunFactoryFromPriority } from 'utils/test/factories/richie';
|
|
|
9
9
|
import { noop } from 'utils';
|
|
10
10
|
import { computeState } from 'utils/CourseRuns';
|
|
11
11
|
import { formatRelativeDate } from 'utils/relativeDate';
|
|
12
|
+
import { IntlWrapper } from 'utils/test/wrappers/IntlWrapper';
|
|
13
|
+
import { render } from 'utils/test/render';
|
|
12
14
|
import { DashboardItemCourseEnrollingRun, Enrolled } from '.';
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -16,10 +18,6 @@ import { DashboardItemCourseEnrollingRun, Enrolled } from '.';
|
|
|
16
18
|
* DashboardItemOrder.spec.tsx. But here are some tests that are more straightforward.
|
|
17
19
|
*/
|
|
18
20
|
describe('<Enrolled/>', () => {
|
|
19
|
-
const wrapper = ({ children }: PropsWithChildren) => {
|
|
20
|
-
return <IntlProvider locale="en">{children}</IntlProvider>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
21
|
it.each([
|
|
24
22
|
{
|
|
25
23
|
buttonTestLabel: 'and access course button',
|
|
@@ -87,7 +85,9 @@ describe('<Enrolled/>', () => {
|
|
|
87
85
|
async ({ priority, expectButton, expectLabelTemplate }) => {
|
|
88
86
|
const enrollment: Enrollment = EnrollmentFactory().one();
|
|
89
87
|
enrollment.course_run.state.priority = priority;
|
|
90
|
-
render(<Enrolled enrollment={enrollment} />, {
|
|
88
|
+
render(<Enrolled enrollment={enrollment} />, {
|
|
89
|
+
wrapper: ({ children }: PropsWithChildren) => <IntlWrapper>{children}</IntlWrapper>,
|
|
90
|
+
});
|
|
91
91
|
const intl = createIntl({ locale: 'en' });
|
|
92
92
|
|
|
93
93
|
const fromDate = new Intl.DateTimeFormat('en', DEFAULT_DATE_FORMAT).format(
|
|
@@ -138,14 +138,15 @@ describe('<DashboardItemCourseEnrollingRun/>', () => {
|
|
|
138
138
|
joanieCourseRun.course = order.course;
|
|
139
139
|
|
|
140
140
|
render(
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
<DashboardItemCourseEnrollingRun
|
|
142
|
+
order={order}
|
|
143
|
+
courseRun={joanieCourseRun}
|
|
144
|
+
selected={false}
|
|
145
|
+
enroll={noop}
|
|
146
|
+
/>,
|
|
147
|
+
{
|
|
148
|
+
wrapper: ({ children }: PropsWithChildren) => <IntlWrapper>{children}</IntlWrapper>,
|
|
149
|
+
},
|
|
149
150
|
);
|
|
150
151
|
|
|
151
152
|
if (expectEnrollmentNotYetOpened) {
|
package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.spec.tsx
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
1
|
+
import { screen } from '@testing-library/react';
|
|
3
2
|
import { faker } from '@faker-js/faker';
|
|
4
|
-
import { QueryClientProvider } from '@tanstack/react-query';
|
|
5
3
|
import { Enrollment } from 'types/Joanie';
|
|
6
4
|
import {
|
|
7
5
|
CourseStateFactory,
|
|
@@ -10,28 +8,20 @@ import {
|
|
|
10
8
|
import { CourseRunWithCourseFactory, EnrollmentFactory } from 'utils/test/factories/joanie';
|
|
11
9
|
import { DEFAULT_DATE_FORMAT } from 'hooks/useDateFormat';
|
|
12
10
|
import { Priority } from 'types';
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
11
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
12
|
+
import { render } from 'utils/test/render';
|
|
15
13
|
import { DashboardItemEnrollment } from './DashboardItemEnrollment';
|
|
16
14
|
|
|
17
15
|
jest.mock('utils/context', () => ({
|
|
18
16
|
__esModule: true,
|
|
19
17
|
default: mockRichieContextFactory({
|
|
20
18
|
authentication: { backend: 'fonzie', endpoint: 'https://auth.endpoint.test' },
|
|
21
|
-
joanie_backend: { endpoint: 'https://joanie.endpoint
|
|
19
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
22
20
|
}).one(),
|
|
23
21
|
}));
|
|
24
22
|
|
|
25
23
|
describe('<DashboardItemEnrollment/>', () => {
|
|
26
|
-
|
|
27
|
-
<IntlProvider locale="en">
|
|
28
|
-
<QueryClientProvider client={createTestQueryClient()}>
|
|
29
|
-
<JoanieSessionProvider>
|
|
30
|
-
<DashboardItemEnrollment enrollment={enrollment} />
|
|
31
|
-
</JoanieSessionProvider>
|
|
32
|
-
</QueryClientProvider>
|
|
33
|
-
</IntlProvider>
|
|
34
|
-
);
|
|
24
|
+
setupJoanieSession();
|
|
35
25
|
|
|
36
26
|
it('renders a opened enrollment', () => {
|
|
37
27
|
const enrollment: Enrollment = EnrollmentFactory({
|
|
@@ -44,7 +34,7 @@ describe('<DashboardItemEnrollment/>', () => {
|
|
|
44
34
|
}).one();
|
|
45
35
|
enrollment.course_run.state.priority = Priority.ONGOING_OPEN;
|
|
46
36
|
|
|
47
|
-
render(<
|
|
37
|
+
render(<DashboardItemEnrollment enrollment={enrollment} />);
|
|
48
38
|
screen.getByText(enrollment.course_run.course!.title);
|
|
49
39
|
screen.getByText('Ref. ' + enrollment.course_run.course!.code);
|
|
50
40
|
const link = screen.getByRole('link', { name: 'Access to course' });
|
|
@@ -71,7 +61,7 @@ describe('<DashboardItemEnrollment/>', () => {
|
|
|
71
61
|
}).one(),
|
|
72
62
|
}).one();
|
|
73
63
|
|
|
74
|
-
render(<
|
|
64
|
+
render(<DashboardItemEnrollment enrollment={enrollment} />);
|
|
75
65
|
screen.getByText(enrollment.course_run.course!.title);
|
|
76
66
|
screen.getByText('Ref. ' + enrollment.course_run.course!.code);
|
|
77
67
|
const link = screen.getByRole('link', { name: 'Access to course' });
|
|
@@ -86,7 +76,7 @@ describe('<DashboardItemEnrollment/>', () => {
|
|
|
86
76
|
course_run: CourseRunWithCourseFactory().one(),
|
|
87
77
|
}).one();
|
|
88
78
|
|
|
89
|
-
render(<
|
|
79
|
+
render(<DashboardItemEnrollment enrollment={enrollment} />);
|
|
90
80
|
screen.getByText(enrollment.course_run.course!.title);
|
|
91
81
|
screen.getByText('Ref. ' + enrollment.course_run.course!.code);
|
|
92
82
|
screen.getByText('Not enrolled');
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
|
|
3
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
1
|
+
import { screen, waitForElementToBeRemoved } from '@testing-library/react';
|
|
4
2
|
import fetchMock from 'fetch-mock';
|
|
5
3
|
import userEvent from '@testing-library/user-event';
|
|
6
4
|
import { CertificateProduct, CourseLight, OrderState, ProductType } from 'types/Joanie';
|
|
7
5
|
import {
|
|
8
6
|
CourseStateFactory,
|
|
9
|
-
UserFactory,
|
|
10
7
|
RichieContextFactory as mockRichieContextFactory,
|
|
11
8
|
} from 'utils/test/factories/richie';
|
|
12
9
|
import {
|
|
@@ -18,21 +15,21 @@ import {
|
|
|
18
15
|
CertificateProductFactory,
|
|
19
16
|
} from 'utils/test/factories/joanie';
|
|
20
17
|
import { Priority } from 'types';
|
|
21
|
-
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
22
|
-
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
|
|
23
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
24
18
|
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
|
|
25
19
|
import { LearnerDashboardPaths } from 'widgets/Dashboard/utils/learnerRouteMessages';
|
|
26
20
|
import { expectNoSpinner } from 'utils/test/expectSpinner';
|
|
27
21
|
import { PER_PAGE } from 'settings';
|
|
28
22
|
import { SaleTunnelProps } from 'components/SaleTunnel';
|
|
29
|
-
import
|
|
23
|
+
import { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
|
|
24
|
+
import { render } from 'utils/test/render';
|
|
25
|
+
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
|
|
26
|
+
import ProductCertificateFooter from '.';
|
|
30
27
|
|
|
31
28
|
jest.mock('utils/context', () => ({
|
|
32
29
|
__esModule: true,
|
|
33
30
|
default: mockRichieContextFactory({
|
|
34
31
|
authentication: { backend: 'fonzie', endpoint: 'https://auth.endpoint.test' },
|
|
35
|
-
joanie_backend: { endpoint: 'https://joanie.endpoint
|
|
32
|
+
joanie_backend: { endpoint: 'https://joanie.endpoint' },
|
|
36
33
|
}).one(),
|
|
37
34
|
}));
|
|
38
35
|
jest.mock('components/SaleTunnel', () => ({
|
|
@@ -55,32 +52,15 @@ jest.mock('components/SaleTunnel', () => ({
|
|
|
55
52
|
}));
|
|
56
53
|
|
|
57
54
|
describe('<ProductCertificateFooter/>', () => {
|
|
58
|
-
const Wrapper = ({ product, enrollment }: ProductCertificateFooterProps) => (
|
|
59
|
-
<IntlProvider locale="en">
|
|
60
|
-
<QueryClientProvider client={createTestQueryClient({ user: UserFactory().one() })}>
|
|
61
|
-
<JoanieSessionProvider>
|
|
62
|
-
<ProductCertificateFooter product={product} enrollment={enrollment} />
|
|
63
|
-
</JoanieSessionProvider>
|
|
64
|
-
</QueryClientProvider>
|
|
65
|
-
</IntlProvider>
|
|
66
|
-
);
|
|
67
55
|
let product: CertificateProduct;
|
|
68
56
|
let course: CourseLight;
|
|
57
|
+
setupJoanieSession();
|
|
69
58
|
|
|
70
59
|
beforeEach(() => {
|
|
71
|
-
fetchMock.get('https://joanie.endpoint.test/api/v1.0/addresses/', []);
|
|
72
|
-
fetchMock.get('https://joanie.endpoint.test/api/v1.0/credit-cards/', []);
|
|
73
|
-
fetchMock.get('https://joanie.endpoint.test/api/v1.0/orders/', []);
|
|
74
|
-
|
|
75
60
|
product = CertificateProductFactory({ type: ProductType.CERTIFICATE }).one();
|
|
76
61
|
course = CourseLightFactory().one();
|
|
77
62
|
});
|
|
78
63
|
|
|
79
|
-
afterEach(() => {
|
|
80
|
-
jest.clearAllMocks();
|
|
81
|
-
fetchMock.restore();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
64
|
it.each([
|
|
85
65
|
{
|
|
86
66
|
label: 'state: ONGOING_OPEN',
|
|
@@ -106,7 +86,7 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
106
86
|
'should display purchase button for a open course run without order (state $courseRunStateData.priority).',
|
|
107
87
|
async ({ courseRunStateData }) => {
|
|
108
88
|
render(
|
|
109
|
-
<
|
|
89
|
+
<ProductCertificateFooter
|
|
110
90
|
product={product}
|
|
111
91
|
enrollment={EnrollmentFactory({
|
|
112
92
|
course_run: CourseRunFactory({
|
|
@@ -137,7 +117,7 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
137
117
|
"shouldn't display purchase button for a closed course run without order (state $courseRunStateData.priority).",
|
|
138
118
|
async ({ courseRunStateData }) => {
|
|
139
119
|
render(
|
|
140
|
-
<
|
|
120
|
+
<ProductCertificateFooter
|
|
141
121
|
product={product}
|
|
142
122
|
enrollment={EnrollmentFactory({
|
|
143
123
|
course_run: CourseRunFactory({
|
|
@@ -147,6 +127,7 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
147
127
|
}).one()}
|
|
148
128
|
/>,
|
|
149
129
|
);
|
|
130
|
+
|
|
150
131
|
expect(screen.queryByTestId('PurchaseButton__cta')).not.toBeInTheDocument();
|
|
151
132
|
},
|
|
152
133
|
);
|
|
@@ -162,10 +143,10 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
162
143
|
course_run: CourseRunFactory({ course }).one(),
|
|
163
144
|
}).one();
|
|
164
145
|
fetchMock.get(
|
|
165
|
-
'https://joanie.endpoint
|
|
146
|
+
'https://joanie.endpoint/api/v1.0/certificates/FAKE_CERTIFICATE_ID/',
|
|
166
147
|
CertificateFactory({ id: order.certificate_id }).one(),
|
|
167
148
|
);
|
|
168
|
-
render(<
|
|
149
|
+
render(<ProductCertificateFooter product={product} enrollment={enrollment} />);
|
|
169
150
|
expect(await screen.findByRole('button', { name: 'Download' })).toBeInTheDocument();
|
|
170
151
|
expect(screen.queryByTestId('PurchaseButton__cta')).not.toBeInTheDocument();
|
|
171
152
|
});
|
|
@@ -179,31 +160,15 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
179
160
|
orders: [order],
|
|
180
161
|
course_run: CourseRunFactory({ course }).one(),
|
|
181
162
|
}).one();
|
|
182
|
-
render(<
|
|
163
|
+
render(<ProductCertificateFooter product={product} enrollment={enrollment} />);
|
|
183
164
|
expect(await screen.queryByRole('button', { name: 'Download' })).not.toBeInTheDocument();
|
|
184
165
|
expect(screen.queryByTestId('PurchaseButton__cta')).not.toBeInTheDocument();
|
|
185
166
|
});
|
|
186
167
|
|
|
187
168
|
// From https://github.com/openfun/richie/issues/2237
|
|
188
169
|
it('should hide purchase button after payment', async () => {
|
|
189
|
-
const TestWrapper = ({ client }: { client?: QueryClient }) => {
|
|
190
|
-
const user = UserFactory().one();
|
|
191
|
-
return (
|
|
192
|
-
<QueryClientProvider client={client ?? createTestQueryClient({ user })}>
|
|
193
|
-
<IntlProvider locale="en">
|
|
194
|
-
{/* <HistoryContext.Provider value={makeHistoryOf({})}> */}
|
|
195
|
-
<SessionProvider>
|
|
196
|
-
<DashboardTest initialRoute={LearnerDashboardPaths.COURSES} />
|
|
197
|
-
</SessionProvider>
|
|
198
|
-
{/* </HistoryContext.Provider> */}
|
|
199
|
-
</IntlProvider>
|
|
200
|
-
</QueryClientProvider>
|
|
201
|
-
);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const client = createTestQueryClient({ user: true });
|
|
205
170
|
fetchMock.get(
|
|
206
|
-
`https://joanie.endpoint
|
|
171
|
+
`https://joanie.endpoint/api/v1.0/orders/?product_type=credential&state_exclude=canceled&page=1&page_size=${PER_PAGE.useOrdersEnrollments}`,
|
|
207
172
|
{
|
|
208
173
|
results: [],
|
|
209
174
|
next: null,
|
|
@@ -221,7 +186,7 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
221
186
|
enrollment.product_relations[0].product = CertificateProductFactory().one();
|
|
222
187
|
|
|
223
188
|
fetchMock.get(
|
|
224
|
-
`https://joanie.endpoint
|
|
189
|
+
`https://joanie.endpoint/api/v1.0/enrollments/?was_created_by_order=false&page=1&page_size=${PER_PAGE.useOrdersEnrollments}`,
|
|
225
190
|
{
|
|
226
191
|
results: [enrollment],
|
|
227
192
|
next: null,
|
|
@@ -230,7 +195,10 @@ describe('<ProductCertificateFooter/>', () => {
|
|
|
230
195
|
},
|
|
231
196
|
);
|
|
232
197
|
|
|
233
|
-
render(<
|
|
198
|
+
render(<DashboardTest initialRoute={LearnerDashboardPaths.COURSES} />, {
|
|
199
|
+
wrapper: BaseJoanieAppWrapper,
|
|
200
|
+
});
|
|
201
|
+
// <TestWrapper client={client} />);
|
|
234
202
|
const user = userEvent.setup();
|
|
235
203
|
await expectNoSpinner('Loading orders and enrollments...');
|
|
236
204
|
await screen.findByRole('heading', {
|