richie-education 3.1.3-dev12 → 3.1.3-dev17
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/api/joanie.ts +8 -8
- package/js/components/ContractFrame/OrganizationContractFrame.spec.tsx +12 -11
- package/js/components/ContractFrame/OrganizationContractFrame.tsx +4 -4
- package/js/components/CourseGlimpse/utils.ts +28 -22
- package/js/components/CourseGlimpseList/utils.ts +2 -2
- package/js/components/PurchaseButton/index.tsx +3 -3
- package/js/components/SaleTunnel/GenericSaleTunnel.tsx +3 -3
- package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +5 -3
- package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
- package/js/components/SaleTunnel/index.spec.tsx +76 -63
- package/js/components/SaleTunnel/index.tsx +2 -2
- package/js/components/TeacherDashboardCourseList/index.spec.tsx +3 -3
- package/js/components/TeacherDashboardCourseList/index.tsx +2 -2
- package/js/hooks/useContractArchive/index.ts +3 -3
- package/js/hooks/useCourseProductUnion/index.spec.tsx +16 -16
- package/js/hooks/useCourseProductUnion/index.ts +7 -7
- package/js/hooks/useCourseProducts.ts +4 -4
- package/js/hooks/useDefaultOrganizationId/index.tsx +4 -4
- package/js/hooks/useOffering/index.ts +32 -0
- package/js/hooks/useTeacherCoursesSearch/index.tsx +4 -4
- package/js/hooks/useTeacherPendingContractsCount/index.ts +4 -4
- package/js/pages/DashboardCourses/index.spec.tsx +17 -14
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +11 -8
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +6 -3
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +10 -10
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +5 -5
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +8 -8
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.spec.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx +7 -7
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.tsx +5 -5
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.spec.ts +21 -21
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +19 -13
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +6 -3
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.spec.tsx +16 -16
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign.tsx +7 -4
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +21 -21
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts +5 -5
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.spec.tsx +55 -55
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.tsx +1 -1
- package/js/pages/TeacherDashboardCoursesLoader/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardOrganizationCourseLoader/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardTraining/TeacherDashboardTrainingLoader.tsx +7 -7
- package/js/pages/TeacherDashboardTraining/index.spec.tsx +25 -25
- package/js/pages/TeacherDashboardTraining/index.tsx +16 -12
- package/js/types/Joanie.ts +27 -20
- package/js/utils/test/factories/joanie.ts +14 -11
- package/js/utils/test/mockCourseProductWithOrder.ts +4 -4
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.tsx +3 -3
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.useUnionResource.cache.spec.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardItem/Order/Installment/index.tsx +4 -4
- package/js/widgets/Dashboard/components/DashboardItem/stories.mock.ts +1 -1
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.spec.tsx +23 -23
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +20 -17
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.tsx +22 -16
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.tsx +3 -3
- package/js/widgets/Dashboard/utils/teacherDashboardPaths.tsx +4 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +14 -14
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +105 -75
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +6 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +27 -20
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +8 -8
- package/package.json +1 -1
- package/js/hooks/useOffer/index.ts +0 -32
|
@@ -2,13 +2,13 @@ import { renderHook, waitFor } from '@testing-library/react';
|
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import fetchMock from 'fetch-mock';
|
|
4
4
|
import { PropsWithChildren } from 'react';
|
|
5
|
-
import { CourseListItem,
|
|
5
|
+
import { CourseListItem, Offering } from 'types/Joanie';
|
|
6
6
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
7
7
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
8
8
|
import { SessionProvider } from 'contexts/SessionContext';
|
|
9
9
|
import { getRoutes } from 'api/joanie';
|
|
10
10
|
import { mockPaginatedResponse } from 'utils/test/mockPaginatedResponse';
|
|
11
|
-
import { CourseListItemFactory,
|
|
11
|
+
import { CourseListItemFactory, OfferingFactory } from 'utils/test/factories/joanie';
|
|
12
12
|
import { BaseJoanieAppWrapper } from 'utils/test/wrappers/BaseJoanieAppWrapper';
|
|
13
13
|
import { useCourseProductUnion } from '.';
|
|
14
14
|
|
|
@@ -41,12 +41,12 @@ const renderUseCourseProductUnion = ({ organizationId }: { organizationId?: stri
|
|
|
41
41
|
|
|
42
42
|
describe('useCourseProductUnion', () => {
|
|
43
43
|
let courseList: CourseListItem[];
|
|
44
|
-
let
|
|
44
|
+
let offeringList: Offering[];
|
|
45
45
|
let nbApiCalls: number;
|
|
46
46
|
|
|
47
47
|
beforeEach(() => {
|
|
48
48
|
courseList = CourseListItemFactory().many(6);
|
|
49
|
-
|
|
49
|
+
offeringList = OfferingFactory().many(6);
|
|
50
50
|
|
|
51
51
|
fetchMock.get('https://joanie.endpoint/api/v1.0/orders/', [], { overwriteRoutes: true });
|
|
52
52
|
fetchMock.get('https://joanie.endpoint/api/v1.0/credit-cards/', [], { overwriteRoutes: true });
|
|
@@ -59,38 +59,38 @@ describe('useCourseProductUnion', () => {
|
|
|
59
59
|
fetchMock.restore();
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it('should call courses and
|
|
62
|
+
it('should call courses and offering endpoints', async () => {
|
|
63
63
|
const ROUTES = getRoutes();
|
|
64
64
|
const coursesUrl = ROUTES.courses.get.replace(':id/', '');
|
|
65
|
-
const
|
|
65
|
+
const offeringsUrl = ROUTES.offerings.get.replace(':id/', '');
|
|
66
66
|
fetchMock.get(
|
|
67
67
|
`${coursesUrl}?has_listed_course_runs=true&page=1&page_size=${PER_PAGE}`,
|
|
68
68
|
mockPaginatedResponse(courseList.slice(0, PER_PAGE), 0, false),
|
|
69
69
|
);
|
|
70
70
|
fetchMock.get(
|
|
71
|
-
`${
|
|
72
|
-
mockPaginatedResponse(
|
|
71
|
+
`${offeringsUrl}?page=1&page_size=${PER_PAGE}`,
|
|
72
|
+
mockPaginatedResponse(offeringList.slice(0, PER_PAGE), 0, false),
|
|
73
73
|
);
|
|
74
74
|
const { result } = renderUseCourseProductUnion();
|
|
75
75
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
76
76
|
expect(result.current.data.length).toBe(PER_PAGE);
|
|
77
77
|
nbApiCalls += 1; // courses page 1
|
|
78
|
-
nbApiCalls += 1; //
|
|
78
|
+
nbApiCalls += 1; // offerings page 1
|
|
79
79
|
const calledUrls = fetchMock.calls().map((call) => call[0]);
|
|
80
80
|
expect(calledUrls).toHaveLength(nbApiCalls);
|
|
81
81
|
expect(calledUrls).toContain(
|
|
82
82
|
`${coursesUrl}?has_listed_course_runs=true&page=1&page_size=${PER_PAGE}`,
|
|
83
83
|
);
|
|
84
|
-
expect(calledUrls).toContain(`${
|
|
84
|
+
expect(calledUrls).toContain(`${offeringsUrl}?page=1&page_size=${PER_PAGE}`);
|
|
85
85
|
}, 25000);
|
|
86
86
|
|
|
87
|
-
it('should call organization courses and organization
|
|
87
|
+
it('should call organization courses and organization offering endpoints', async () => {
|
|
88
88
|
const organizationId = 'DUMMY_ORGANIZATION_ID';
|
|
89
89
|
const ROUTES = getRoutes();
|
|
90
90
|
const organizationCoursesUrl = ROUTES.organizations.courses.get
|
|
91
91
|
.replace(':organization_id', organizationId)
|
|
92
92
|
.replace(':id/', '');
|
|
93
|
-
const
|
|
93
|
+
const organizationOfferingsUrl = ROUTES.organizations.offerings.get
|
|
94
94
|
.replace(':organization_id', organizationId)
|
|
95
95
|
.replace(':id/', '');
|
|
96
96
|
fetchMock.get(
|
|
@@ -98,19 +98,19 @@ describe('useCourseProductUnion', () => {
|
|
|
98
98
|
mockPaginatedResponse(courseList.slice(0, PER_PAGE), 0, false),
|
|
99
99
|
);
|
|
100
100
|
fetchMock.get(
|
|
101
|
-
`${
|
|
102
|
-
mockPaginatedResponse(
|
|
101
|
+
`${organizationOfferingsUrl}?page=1&page_size=${PER_PAGE}`,
|
|
102
|
+
mockPaginatedResponse(offeringList.slice(0, PER_PAGE), 0, false),
|
|
103
103
|
);
|
|
104
104
|
const { result } = renderUseCourseProductUnion({ organizationId: 'DUMMY_ORGANIZATION_ID' });
|
|
105
105
|
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
|
106
106
|
expect(result.current.data.length).toBe(PER_PAGE);
|
|
107
107
|
nbApiCalls += 1; // courses page 1
|
|
108
|
-
nbApiCalls += 1; //
|
|
108
|
+
nbApiCalls += 1; // offerings page 1
|
|
109
109
|
const calledUrls = fetchMock.calls().map((call) => call[0]);
|
|
110
110
|
expect(calledUrls).toHaveLength(nbApiCalls);
|
|
111
111
|
expect(calledUrls).toContain(
|
|
112
112
|
`${organizationCoursesUrl}?has_listed_course_runs=true&page=1&page_size=${PER_PAGE}`,
|
|
113
113
|
);
|
|
114
|
-
expect(calledUrls).toContain(`${
|
|
114
|
+
expect(calledUrls).toContain(`${organizationOfferingsUrl}?page=1&page_size=${PER_PAGE}`);
|
|
115
115
|
});
|
|
116
116
|
});
|
|
@@ -3,11 +3,11 @@ import { useJoanieApi } from 'contexts/JoanieApiContext';
|
|
|
3
3
|
import {
|
|
4
4
|
CourseListItem,
|
|
5
5
|
Product,
|
|
6
|
-
|
|
6
|
+
Offering,
|
|
7
7
|
CourseQueryFilters,
|
|
8
|
-
|
|
8
|
+
OfferingQueryFilters,
|
|
9
9
|
ProductType,
|
|
10
|
-
|
|
10
|
+
OfferingLight,
|
|
11
11
|
} from 'types/Joanie';
|
|
12
12
|
import useUnionResource, { ResourceUnionPaginationProps } from 'hooks/useUnionResource';
|
|
13
13
|
|
|
@@ -41,9 +41,9 @@ export const useCourseProductUnion = ({
|
|
|
41
41
|
const api = useJoanieApi();
|
|
42
42
|
return useUnionResource<
|
|
43
43
|
CourseListItem,
|
|
44
|
-
|
|
44
|
+
Offering | OfferingLight,
|
|
45
45
|
CourseQueryFilters,
|
|
46
|
-
|
|
46
|
+
OfferingQueryFilters
|
|
47
47
|
>({
|
|
48
48
|
queryAConfig: {
|
|
49
49
|
queryKey: ['user', 'courses'],
|
|
@@ -51,8 +51,8 @@ export const useCourseProductUnion = ({
|
|
|
51
51
|
filters: { query, organization_id: organizationId, has_listed_course_runs: true },
|
|
52
52
|
},
|
|
53
53
|
queryBConfig: {
|
|
54
|
-
queryKey: ['user', '
|
|
55
|
-
fn: api.
|
|
54
|
+
queryKey: ['user', 'offerings'],
|
|
55
|
+
fn: api.offerings.get,
|
|
56
56
|
filters: { query, organization_id: organizationId, product_type: productType },
|
|
57
57
|
},
|
|
58
58
|
perPage,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineMessages } from 'react-intl';
|
|
2
|
-
import { API, CourseProductQueryFilters,
|
|
2
|
+
import { API, CourseProductQueryFilters, Offering, Product } from 'types/Joanie';
|
|
3
3
|
import { QueryOptions, useResourcesCustom, UseResourcesProps } from 'hooks/useResources';
|
|
4
4
|
import { useJoanieApi } from 'contexts/JoanieApiContext';
|
|
5
5
|
|
|
@@ -19,7 +19,7 @@ export const messages = defineMessages({
|
|
|
19
19
|
/**
|
|
20
20
|
* Joanie Api hook to retrieve a product through its id and a course code.
|
|
21
21
|
*/
|
|
22
|
-
const props: UseResourcesProps<
|
|
22
|
+
const props: UseResourcesProps<Offering, CourseProductQueryFilters, API['courses']['products']> = {
|
|
23
23
|
queryKey: ['courses-products'],
|
|
24
24
|
apiInterface: () => useJoanieApi().courses.products,
|
|
25
25
|
messages,
|
|
@@ -27,11 +27,11 @@ const props: UseResourcesProps<Offer, CourseProductQueryFilters, API['courses'][
|
|
|
27
27
|
|
|
28
28
|
export const useCourseProduct = (
|
|
29
29
|
filters: Omit<CourseProductQueryFilters, 'id'> & { product_id: Product['id'] },
|
|
30
|
-
queryOptions?: QueryOptions<
|
|
30
|
+
queryOptions?: QueryOptions<Offering>,
|
|
31
31
|
) => {
|
|
32
32
|
const { product_id: productId, ...queryfilters } = filters;
|
|
33
33
|
const enabled = !!productId && !!queryfilters.course_id;
|
|
34
|
-
const resources = useResourcesCustom<
|
|
34
|
+
const resources = useResourcesCustom<Offering, CourseProductQueryFilters>({
|
|
35
35
|
...props,
|
|
36
36
|
filters: { id: productId, ...queryfilters },
|
|
37
37
|
queryOptions: { ...queryOptions, enabled },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useParams, useSearchParams } from 'react-router';
|
|
2
2
|
import { useOrganizations } from 'hooks/useOrganizations';
|
|
3
|
-
import {
|
|
3
|
+
import { Offering, Organization } from 'types/Joanie';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* return organization id with this priority:
|
|
@@ -9,14 +9,14 @@ import { Offer, Organization } from 'types/Joanie';
|
|
|
9
9
|
* * first organization of user's organizations
|
|
10
10
|
*/
|
|
11
11
|
const useDefaultOrganizationId = () => {
|
|
12
|
-
const { organizationId: routeOrganizationId,
|
|
12
|
+
const { organizationId: routeOrganizationId, offeringId: routeOfferingId } = useParams<{
|
|
13
13
|
organizationId?: Organization['id'];
|
|
14
|
-
|
|
14
|
+
offeringId: Offering['id'];
|
|
15
15
|
}>();
|
|
16
16
|
const [searchParams] = useSearchParams();
|
|
17
17
|
const queryOrganizationId = searchParams.get('organization_id') || undefined;
|
|
18
18
|
const { items: organizations } = useOrganizations(
|
|
19
|
-
{
|
|
19
|
+
{ offering_id: routeOfferingId },
|
|
20
20
|
{
|
|
21
21
|
enabled: !routeOrganizationId && !queryOrganizationId,
|
|
22
22
|
},
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl';
|
|
2
|
+
import { useJoanieApi } from 'contexts/JoanieApiContext';
|
|
3
|
+
import { API, Offering, OfferingQueryFilters } from 'types/Joanie';
|
|
4
|
+
import { useResource, useResources, UseResourcesProps } from 'hooks/useResources';
|
|
5
|
+
|
|
6
|
+
const messages = defineMessages({
|
|
7
|
+
errorGet: {
|
|
8
|
+
id: 'hooks.useOfferings.errorGet',
|
|
9
|
+
description: 'Error message shown to the user when offering fetch request fails.',
|
|
10
|
+
defaultMessage: 'An error occurred while fetching trainings. Please retry later.',
|
|
11
|
+
},
|
|
12
|
+
errorNotFound: {
|
|
13
|
+
id: 'hooks.useOfferings.errorNotFound',
|
|
14
|
+
description: 'Error message shown to the user when no offering matches.',
|
|
15
|
+
defaultMessage: 'Cannot find the training.',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Joanie Api hook to retrieve/create/update/delete course
|
|
21
|
+
* owned by the authenticated user.
|
|
22
|
+
*/
|
|
23
|
+
const props: UseResourcesProps<Offering, OfferingQueryFilters, API['offerings']> = {
|
|
24
|
+
queryKey: ['offerings'],
|
|
25
|
+
apiInterface: () => useJoanieApi().offerings,
|
|
26
|
+
session: true,
|
|
27
|
+
messages,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const useOfferings = useResources<Offering, OfferingQueryFilters, API['offerings']>(props);
|
|
31
|
+
|
|
32
|
+
export const useOffering = useResource<Offering, OfferingQueryFilters>(props);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { useParams, useSearchParams } from 'react-router';
|
|
3
3
|
import { useCourseProductUnion } from 'hooks/useCourseProductUnion';
|
|
4
|
-
import { CourseListItem,
|
|
4
|
+
import { CourseListItem, OfferingLight, ProductType } from 'types/Joanie';
|
|
5
5
|
import { Maybe, Nullable } from 'types/utils';
|
|
6
6
|
|
|
7
7
|
const useTeacherCoursesSearch = () => {
|
|
8
8
|
const { organizationId } = useParams<{ organizationId: string }>();
|
|
9
9
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
10
10
|
const [count, setCount] = useState<Maybe<number>>(0);
|
|
11
|
-
const [courseAndProductList, setCourseAndProductList] = useState<
|
|
12
|
-
[]
|
|
13
|
-
);
|
|
11
|
+
const [courseAndProductList, setCourseAndProductList] = useState<
|
|
12
|
+
(CourseListItem | OfferingLight)[]
|
|
13
|
+
>([]);
|
|
14
14
|
const [isNewSearchLoading, setIsNewSearchLoading] = useState(false);
|
|
15
15
|
const query = searchParams.get('query') || undefined;
|
|
16
16
|
const {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { useOrganizationContracts } from 'hooks/useContracts';
|
|
2
2
|
import { PER_PAGE } from 'settings';
|
|
3
|
-
import { ContractState,
|
|
3
|
+
import { ContractState, Offering, Organization } from 'types/Joanie';
|
|
4
4
|
|
|
5
5
|
interface UseTeacherPendingContractsCountProps {
|
|
6
6
|
organizationId?: Organization['id'];
|
|
7
|
-
|
|
7
|
+
offeringId?: Offering['id'];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const useTeacherPendingContractsCount = ({
|
|
11
11
|
organizationId,
|
|
12
|
-
|
|
12
|
+
offeringId,
|
|
13
13
|
}: UseTeacherPendingContractsCountProps) => {
|
|
14
14
|
const { items: contracts, meta } = useOrganizationContracts({
|
|
15
15
|
organization_id: organizationId,
|
|
16
|
-
|
|
16
|
+
offering_id: offeringId,
|
|
17
17
|
signature_state: ContractState.LEARNER_SIGNED,
|
|
18
18
|
page: 1,
|
|
19
19
|
page_size: PER_PAGE.teacherContractList,
|
|
@@ -5,12 +5,12 @@ import userEvent from '@testing-library/user-event';
|
|
|
5
5
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
6
6
|
import { DashboardTest } from 'widgets/Dashboard/components/DashboardTest';
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
OfferingFactory,
|
|
9
9
|
EnrollmentFactory,
|
|
10
10
|
CredentialOrderFactory,
|
|
11
11
|
} from 'utils/test/factories/joanie';
|
|
12
12
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
13
|
-
import { CourseLight,
|
|
13
|
+
import { CourseLight, Offering, Enrollment, CredentialOrder } from 'types/Joanie';
|
|
14
14
|
import { expectNoSpinner, expectSpinner } from 'utils/test/expectSpinner';
|
|
15
15
|
import { expectBannerError, expectBannerInfo, expectNoBannerInfo } from 'utils/test/expectBanner';
|
|
16
16
|
import { Deferred } from 'utils/test/deferred';
|
|
@@ -54,15 +54,15 @@ describe('<DashboardCourses/>', () => {
|
|
|
54
54
|
const perPage = PER_PAGE.useOrdersEnrollments;
|
|
55
55
|
|
|
56
56
|
const mockOrders = (orders: CredentialOrder[], client?: QueryClient) => {
|
|
57
|
-
const
|
|
57
|
+
const offerings: Record<string, Offering> = {};
|
|
58
58
|
orders.forEach((order) => {
|
|
59
59
|
const productId = order.product_id;
|
|
60
60
|
const courseCode = (order.course as CourseLight).code;
|
|
61
|
-
const
|
|
61
|
+
const offering = OfferingFactory().one();
|
|
62
62
|
|
|
63
63
|
fetchMock.get(
|
|
64
64
|
`https://joanie.endpoint/api/v1.0/courses/${courseCode}/products/${productId}/`,
|
|
65
|
-
|
|
65
|
+
offering,
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
// Allowing this option boosts the test performances. Without it, the tests case with 200+
|
|
@@ -70,28 +70,28 @@ describe('<DashboardCourses/>', () => {
|
|
|
70
70
|
if (client) {
|
|
71
71
|
client.setQueryData(
|
|
72
72
|
['courses-products', JSON.stringify({ id: courseCode, productId })],
|
|
73
|
-
|
|
73
|
+
offering,
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
offerings[order.id] = offering;
|
|
77
77
|
});
|
|
78
78
|
orders.sort((a, b) => {
|
|
79
79
|
const aDate = new Date(a.created_on);
|
|
80
80
|
const bDate = new Date(b.created_on);
|
|
81
81
|
return bDate.getTime() - aDate.getTime();
|
|
82
82
|
});
|
|
83
|
-
return { orders,
|
|
83
|
+
return { orders, offerings };
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
const expectList = (
|
|
87
87
|
entities: (CredentialOrder | Enrollment)[],
|
|
88
|
-
|
|
88
|
+
offerings: Record<string, Offering>,
|
|
89
89
|
) => {
|
|
90
90
|
const itemElements = document.querySelectorAll<HTMLElement>('.dashboard__courses__list__item');
|
|
91
91
|
expect(itemElements.length).toBe(entities.length);
|
|
92
92
|
entities.forEach((entity, i) => {
|
|
93
93
|
const title = isOrder(entity)
|
|
94
|
-
?
|
|
94
|
+
? offerings[entity.id].product.title
|
|
95
95
|
: entity.course_run.course?.title;
|
|
96
96
|
getByRole(itemElements[i], 'heading', {
|
|
97
97
|
name: title,
|
|
@@ -146,7 +146,10 @@ describe('<DashboardCourses/>', () => {
|
|
|
146
146
|
|
|
147
147
|
it('should render the list of entities', async () => {
|
|
148
148
|
const client = createTestQueryClient({ user: true });
|
|
149
|
-
const { orders,
|
|
149
|
+
const { orders, offerings } = mockOrders(
|
|
150
|
+
CredentialOrderFactory().many(perPage * 2 + 1),
|
|
151
|
+
client,
|
|
152
|
+
);
|
|
150
153
|
fetchMock.get(
|
|
151
154
|
'https://joanie.endpoint/api/v1.0/orders/' +
|
|
152
155
|
'?product_type=credential' +
|
|
@@ -252,18 +255,18 @@ describe('<DashboardCourses/>', () => {
|
|
|
252
255
|
await expectNoBannerInfo('You have no enrollments nor orders yet');
|
|
253
256
|
let loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
254
257
|
expect(loadMoreButton).toBeEnabled();
|
|
255
|
-
await waitFor(() => expectList(entities.slice(0, perPage),
|
|
258
|
+
await waitFor(() => expectList(entities.slice(0, perPage), offerings), { interval: 200 });
|
|
256
259
|
|
|
257
260
|
// Click on load more button to load slice 2.
|
|
258
261
|
await act(async () => userEvent.click(loadMoreButton));
|
|
259
|
-
await waitFor(() => expectList(entities.slice(0, perPage * 2),
|
|
262
|
+
await waitFor(() => expectList(entities.slice(0, perPage * 2), offerings));
|
|
260
263
|
loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
261
264
|
expect(loadMoreButton).toBeEnabled();
|
|
262
265
|
|
|
263
266
|
// Activate intersection observe to load slice 3.
|
|
264
267
|
const { onIntersect } = (globalThis as any).__intersection_observer_props__;
|
|
265
268
|
await waitFor(async () => onIntersect());
|
|
266
|
-
await waitFor(() => expectList(entities.slice(0, perPage * 3),
|
|
269
|
+
await waitFor(() => expectList(entities.slice(0, perPage * 3), offerings), { timeout: 30000 });
|
|
267
270
|
loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
268
271
|
expect(loadMoreButton).toBeEnabled();
|
|
269
272
|
}, 15000);
|
|
@@ -3,7 +3,7 @@ import { screen } from '@testing-library/react';
|
|
|
3
3
|
import { getAllByRole } from '@testing-library/dom';
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
5
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
6
|
-
import { ContractFactory,
|
|
6
|
+
import { ContractFactory, OfferingFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
7
7
|
import { expectNoSpinner } from 'utils/test/expectSpinner';
|
|
8
8
|
import { expectBannerError } from 'utils/test/expectBanner';
|
|
9
9
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
@@ -33,8 +33,8 @@ jest.mock('components/ContractFrame', () => ({
|
|
|
33
33
|
describe('pages/TeacherDashboardContracts', () => {
|
|
34
34
|
setupJoanieSession();
|
|
35
35
|
|
|
36
|
-
it('should render a list of contracts for
|
|
37
|
-
const
|
|
36
|
+
it('should render a list of contracts for an offering', async () => {
|
|
37
|
+
const offering = OfferingFactory().one();
|
|
38
38
|
const contracts = ContractFactory({
|
|
39
39
|
student_signed_on: Date.toString(),
|
|
40
40
|
organization_signed_on: Date.toString(),
|
|
@@ -44,29 +44,32 @@ describe('pages/TeacherDashboardContracts', () => {
|
|
|
44
44
|
|
|
45
45
|
// OrganizationContractFilter request all organizations forwho the user have access
|
|
46
46
|
fetchMock.get(
|
|
47
|
-
`https://joanie.endpoint/api/v1.0/organizations/?
|
|
47
|
+
`https://joanie.endpoint/api/v1.0/organizations/?offering_id=${offering.id}`,
|
|
48
48
|
organizations,
|
|
49
49
|
);
|
|
50
50
|
// TeacherDashboardContracts request a paginated list of contracts to display
|
|
51
51
|
fetchMock.get(
|
|
52
|
-
`https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}
|
|
52
|
+
`https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/` +
|
|
53
|
+
`contracts/?offering_id=${offering.id}&signature_state=signed&page=1&page_size=25`,
|
|
53
54
|
{ results: contracts, count: 0, previous: null, next: null },
|
|
54
55
|
);
|
|
55
56
|
// useTeacherContractsToSign request all contract to sign, without pagination
|
|
56
57
|
fetchMock.get(
|
|
57
|
-
`https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}
|
|
58
|
+
`https://joanie.endpoint/api/v1.0/organizations/${defaultOrganization.id}/` +
|
|
59
|
+
`contracts/?signature_state=half_signed&offering_id=${offering.id}`,
|
|
58
60
|
{ results: [], count: 0, previous: null, next: null },
|
|
59
61
|
);
|
|
60
62
|
|
|
61
63
|
render(<TeacherDashboardContracts />, {
|
|
62
64
|
routerOptions: {
|
|
63
|
-
path: '/courses/:courseId/products/:
|
|
64
|
-
initialEntries: [`/courses/${
|
|
65
|
+
path: '/courses/:courseId/products/:offeringId/contracts',
|
|
66
|
+
initialEntries: [`/courses/${offering.course.id}/products/${offering.id}/contracts`],
|
|
65
67
|
},
|
|
66
68
|
});
|
|
67
69
|
|
|
68
70
|
await expectNoSpinner();
|
|
69
71
|
|
|
72
|
+
// screen.logTestingPlaygroundURL();
|
|
70
73
|
// Organization filter should have been rendered
|
|
71
74
|
const organizationFilter: HTMLInputElement = await screen.findByRole('combobox', {
|
|
72
75
|
name: 'Organization',
|
|
@@ -42,7 +42,7 @@ const TeacherDashboardContracts = () => {
|
|
|
42
42
|
defaultPage: page ? parseInt(page, 10) : 1,
|
|
43
43
|
pageSize: PER_PAGE.teacherContractList,
|
|
44
44
|
});
|
|
45
|
-
const { organizationId: routeOrganizationId,
|
|
45
|
+
const { organizationId: routeOrganizationId, offeringId: routeOfferingId } =
|
|
46
46
|
useParams<TeacherDashboardContractsParams>();
|
|
47
47
|
// organization list is used to show/hide organization filter.
|
|
48
48
|
// when organizationId is in route's params this filter is always hidden.
|
|
@@ -50,7 +50,7 @@ const TeacherDashboardContracts = () => {
|
|
|
50
50
|
const {
|
|
51
51
|
items: organizationList,
|
|
52
52
|
states: { isFetched: isOrganizationListFetched },
|
|
53
|
-
} = useOrganizations({
|
|
53
|
+
} = useOrganizations({ offering_id: routeOfferingId }, { enabled: !routeOrganizationId });
|
|
54
54
|
const hasMultipleOrganizations = isOrganizationListFetched && organizationList.length > 1;
|
|
55
55
|
const { initialFilters, filters, setFilters } = useTeacherContractFilters();
|
|
56
56
|
const {
|
|
@@ -91,7 +91,10 @@ const TeacherDashboardContracts = () => {
|
|
|
91
91
|
return (
|
|
92
92
|
<div className="teacher-contract-page">
|
|
93
93
|
<div className="dashboard__page__actions">
|
|
94
|
-
<ContractActionsBar
|
|
94
|
+
<ContractActionsBar
|
|
95
|
+
organizationId={filters.organization_id!}
|
|
96
|
+
offeringId={filters.offering_id}
|
|
97
|
+
/>
|
|
95
98
|
<ContractFiltersBar
|
|
96
99
|
defaultValues={initialFilters}
|
|
97
100
|
onFiltersChange={handleFiltersChange}
|
|
@@ -9,7 +9,7 @@ import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
|
9
9
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
10
10
|
import { ContractDownloadStatus } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { OfferingFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
13
13
|
import { unstoreContractArchiveId } from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage';
|
|
14
14
|
import BulkDownloadContractButton from '.';
|
|
15
15
|
|
|
@@ -44,26 +44,26 @@ describe.each([
|
|
|
44
44
|
{
|
|
45
45
|
testLabel: 'for all organization and all trainings',
|
|
46
46
|
organization: undefined,
|
|
47
|
-
|
|
47
|
+
offering: undefined,
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
testLabel: 'for a training in an organization',
|
|
51
51
|
organization: OrganizationFactory().one(),
|
|
52
|
-
|
|
52
|
+
offering: OfferingFactory().one(),
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
testLabel: 'for an organization',
|
|
56
56
|
organization: OrganizationFactory().one(),
|
|
57
|
-
|
|
57
|
+
offering: undefined,
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
testLabel: 'for a training',
|
|
61
61
|
organization: undefined,
|
|
62
|
-
|
|
62
|
+
offering: OfferingFactory().one(),
|
|
63
63
|
},
|
|
64
64
|
])(
|
|
65
65
|
'TeacherDashboardContractsLayout/BulkDownloadContractButton $testLabel',
|
|
66
|
-
({ organization,
|
|
66
|
+
({ organization, offering }) => {
|
|
67
67
|
const Wrapper = ({ children }: PropsWithChildren) => {
|
|
68
68
|
return (
|
|
69
69
|
<IntlProvider locale="en">
|
|
@@ -86,7 +86,7 @@ describe.each([
|
|
|
86
86
|
jest.resetAllMocks();
|
|
87
87
|
unstoreContractArchiveId({
|
|
88
88
|
organizationId: organization ? organization.id : undefined,
|
|
89
|
-
|
|
89
|
+
offeringId: offering ? offering.id : undefined,
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
@@ -97,7 +97,7 @@ describe.each([
|
|
|
97
97
|
<Wrapper>
|
|
98
98
|
<BulkDownloadContractButton
|
|
99
99
|
organizationId={organization?.id ?? undefined}
|
|
100
|
-
|
|
100
|
+
offeringId={offering?.id ?? undefined}
|
|
101
101
|
/>
|
|
102
102
|
</Wrapper>,
|
|
103
103
|
);
|
|
@@ -118,7 +118,7 @@ describe.each([
|
|
|
118
118
|
<Wrapper>
|
|
119
119
|
<BulkDownloadContractButton
|
|
120
120
|
organizationId={organization?.id ?? undefined}
|
|
121
|
-
|
|
121
|
+
offeringId={offering?.id ?? undefined}
|
|
122
122
|
/>
|
|
123
123
|
</Wrapper>,
|
|
124
124
|
);
|
|
@@ -139,7 +139,7 @@ describe.each([
|
|
|
139
139
|
<Wrapper>
|
|
140
140
|
<BulkDownloadContractButton
|
|
141
141
|
organizationId={organization?.id ?? undefined}
|
|
142
|
-
|
|
142
|
+
offeringId={offering?.id ?? undefined}
|
|
143
143
|
/>
|
|
144
144
|
</Wrapper>,
|
|
145
145
|
);
|
|
@@ -160,7 +160,7 @@ describe.each([
|
|
|
160
160
|
<Wrapper>
|
|
161
161
|
<BulkDownloadContractButton
|
|
162
162
|
organizationId={organization?.id ?? undefined}
|
|
163
|
-
|
|
163
|
+
offeringId={offering?.id ?? undefined}
|
|
164
164
|
/>
|
|
165
165
|
</Wrapper>,
|
|
166
166
|
);
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
unstoreContractArchiveId,
|
|
15
15
|
} from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage';
|
|
16
16
|
import { CONTRACT_DOWNLOAD_SETTINGS } from 'settings';
|
|
17
|
-
import {
|
|
17
|
+
import { OfferingFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
18
18
|
import BulkDownloadContractButton from '.';
|
|
19
19
|
|
|
20
20
|
jest.mock('utils/context', () => ({
|
|
@@ -45,26 +45,26 @@ describe.each([
|
|
|
45
45
|
{
|
|
46
46
|
testLabel: 'for all organization and all trainings',
|
|
47
47
|
organization: undefined,
|
|
48
|
-
|
|
48
|
+
offering: undefined,
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
testLabel: 'for a training in an organization',
|
|
52
52
|
organization: OrganizationFactory().one(),
|
|
53
|
-
|
|
53
|
+
offering: OfferingFactory().one(),
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
testLabel: 'for an organization',
|
|
57
57
|
organization: OrganizationFactory().one(),
|
|
58
|
-
|
|
58
|
+
offering: undefined,
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
testLabel: 'for a training',
|
|
62
62
|
organization: undefined,
|
|
63
|
-
|
|
63
|
+
offering: OfferingFactory().one(),
|
|
64
64
|
},
|
|
65
65
|
])(
|
|
66
66
|
'TeacherDashboardContractsLayout/BulkDownloadContractButton with fake timer, $testLabel',
|
|
67
|
-
({ organization,
|
|
67
|
+
({ organization, offering }) => {
|
|
68
68
|
let localStorageArchiveFilters: LocalStorageArchiveFilters;
|
|
69
69
|
|
|
70
70
|
const Wrapper = ({ children }: PropsWithChildren) => {
|
|
@@ -81,7 +81,7 @@ describe.each([
|
|
|
81
81
|
beforeEach(() => {
|
|
82
82
|
localStorageArchiveFilters = {
|
|
83
83
|
organizationId: organization ? organization.id : undefined,
|
|
84
|
-
|
|
84
|
+
offeringId: offering ? offering.id : undefined,
|
|
85
85
|
};
|
|
86
86
|
mockHasContractToDownload = true;
|
|
87
87
|
|
|
@@ -102,7 +102,7 @@ describe.each([
|
|
|
102
102
|
jest.clearAllMocks();
|
|
103
103
|
unstoreContractArchiveId({
|
|
104
104
|
organizationId: organization ? organization.id : undefined,
|
|
105
|
-
|
|
105
|
+
offeringId: offering ? offering.id : undefined,
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
|
|
@@ -114,7 +114,7 @@ describe.each([
|
|
|
114
114
|
<Wrapper>
|
|
115
115
|
<BulkDownloadContractButton
|
|
116
116
|
organizationId={organization?.id ?? undefined}
|
|
117
|
-
|
|
117
|
+
offeringId={offering?.id ?? undefined}
|
|
118
118
|
/>
|
|
119
119
|
</Wrapper>,
|
|
120
120
|
);
|
|
@@ -151,7 +151,7 @@ describe.each([
|
|
|
151
151
|
|
|
152
152
|
render(
|
|
153
153
|
<Wrapper>
|
|
154
|
-
<BulkDownloadContractButton organizationId={organization?.id}
|
|
154
|
+
<BulkDownloadContractButton organizationId={organization?.id} offeringId={offering?.id} />
|
|
155
155
|
</Wrapper>,
|
|
156
156
|
);
|
|
157
157
|
|
package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
|
|
|
4
4
|
import useDownloadContractArchive, {
|
|
5
5
|
ContractDownloadStatus,
|
|
6
6
|
} from 'pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive';
|
|
7
|
-
import {
|
|
7
|
+
import { Offering, Organization } from 'types/Joanie';
|
|
8
8
|
|
|
9
9
|
const messages = defineMessages({
|
|
10
10
|
bulkDownloadButtonDownloadLabel: {
|
|
@@ -26,16 +26,16 @@ const messages = defineMessages({
|
|
|
26
26
|
|
|
27
27
|
interface BulkDownloadContractButtonProps {
|
|
28
28
|
organizationId?: Organization['id'];
|
|
29
|
-
|
|
29
|
+
offeringId?: Offering['id'];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const BulkDownloadContractButton = ({
|
|
33
33
|
organizationId,
|
|
34
|
-
|
|
34
|
+
offeringId,
|
|
35
35
|
}: BulkDownloadContractButtonProps) => {
|
|
36
36
|
const { downloadContractArchive, createContractArchive, status } = useDownloadContractArchive({
|
|
37
37
|
organizationId,
|
|
38
|
-
|
|
38
|
+
offeringId,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
useEffect(() => {
|