richie-education 3.1.3-dev3 → 3.1.3-dev31
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/.storybook/__mocks__/utils/context.ts +4 -0
- package/js/api/joanie.ts +8 -8
- package/js/components/ContractFrame/OrganizationContractFrame.spec.tsx +11 -19
- package/js/components/ContractFrame/OrganizationContractFrame.tsx +4 -4
- package/js/components/CourseGlimpse/CourseGlimpseFooter.tsx +30 -5
- package/js/components/CourseGlimpse/index.spec.tsx +18 -0
- package/js/components/CourseGlimpse/index.stories.tsx +75 -4
- package/js/components/CourseGlimpse/index.tsx +4 -0
- package/js/components/CourseGlimpse/utils.ts +35 -30
- package/js/components/CourseGlimpseList/utils.ts +2 -2
- package/js/components/PurchaseButton/index.tsx +3 -3
- package/js/components/SaleTunnel/CredentialSaleTunnel/index.tsx +1 -3
- package/js/components/SaleTunnel/GenericSaleTunnel.tsx +13 -1
- package/js/components/SaleTunnel/SaleTunnelInformation/index.tsx +9 -7
- package/js/components/SaleTunnel/SubscriptionButton/index.tsx +1 -2
- package/js/components/SaleTunnel/index.credential.spec.tsx +5 -19
- package/js/components/SaleTunnel/index.full-process.spec.tsx +3 -3
- package/js/components/SaleTunnel/index.spec.tsx +171 -29
- package/js/components/SaleTunnel/index.stories.tsx +17 -3
- 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 -18
- package/js/hooks/useCourseProductUnion/index.ts +7 -7
- package/js/hooks/useCourseProducts.ts +4 -8
- package/js/hooks/useDefaultOrganizationId/index.tsx +4 -7
- package/js/hooks/useOffering/index.ts +32 -0
- package/js/hooks/useTeacherCoursesSearch/index.tsx +2 -2
- package/js/hooks/useTeacherPendingContractsCount/index.ts +4 -4
- package/js/pages/DashboardCourses/index.spec.tsx +14 -14
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +11 -14
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +4 -9
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +11 -11
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +10 -13
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +4 -4
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +20 -28
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +8 -11
- 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 -28
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +13 -17
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +11 -13
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +6 -6
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +3 -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 +4 -4
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +21 -21
- package/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.ts +5 -10
- package/js/pages/TeacherDashboardCourseLearnersLayout/index.spec.tsx +61 -79
- 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 +21 -29
- package/js/pages/TeacherDashboardTraining/index.tsx +12 -16
- package/js/types/Course.ts +4 -0
- package/js/types/Joanie.ts +36 -29
- package/js/types/index.ts +6 -2
- package/js/utils/ProductHelper/index.ts +1 -5
- package/js/utils/test/factories/joanie.ts +19 -25
- package/js/utils/test/factories/richie.ts +10 -2
- 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 -28
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +4 -8
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +17 -24
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.tsx +18 -21
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +4 -4
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.tsx +3 -7
- package/js/widgets/Dashboard/utils/teacherDashboardPaths.tsx +4 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +19 -34
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/_styles.scss +35 -8
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/CourseRunList.tsx +3 -3
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCourseRuns/_styles.scss +9 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +186 -140
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +11 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +111 -24
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusCourseRun/index.stories.tsx +81 -0
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusCourseRun/index.tsx +14 -0
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusCourseRunCompacted/index.tsx +14 -0
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +54 -8
- package/package.json +1 -1
- package/scss/objects/_course_glimpses.scss +16 -0
- package/js/hooks/useCourseProductRelation/index.ts +0 -44
|
@@ -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,7 @@ 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
150
|
CredentialOrderFactory().many(perPage * 2 + 1),
|
|
151
151
|
client,
|
|
152
152
|
);
|
|
@@ -255,18 +255,18 @@ describe('<DashboardCourses/>', () => {
|
|
|
255
255
|
await expectNoBannerInfo('You have no enrollments nor orders yet');
|
|
256
256
|
let loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
257
257
|
expect(loadMoreButton).toBeEnabled();
|
|
258
|
-
await waitFor(() => expectList(entities.slice(0, perPage),
|
|
258
|
+
await waitFor(() => expectList(entities.slice(0, perPage), offerings), { interval: 200 });
|
|
259
259
|
|
|
260
260
|
// Click on load more button to load slice 2.
|
|
261
261
|
await act(async () => userEvent.click(loadMoreButton));
|
|
262
|
-
await waitFor(() => expectList(entities.slice(0, perPage * 2),
|
|
262
|
+
await waitFor(() => expectList(entities.slice(0, perPage * 2), offerings));
|
|
263
263
|
loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
264
264
|
expect(loadMoreButton).toBeEnabled();
|
|
265
265
|
|
|
266
266
|
// Activate intersection observe to load slice 3.
|
|
267
267
|
const { onIntersect } = (globalThis as any).__intersection_observer_props__;
|
|
268
268
|
await waitFor(async () => onIntersect());
|
|
269
|
-
await waitFor(() => expectList(entities.slice(0, perPage * 3),
|
|
269
|
+
await waitFor(() => expectList(entities.slice(0, perPage * 3), offerings), { timeout: 30000 });
|
|
270
270
|
loadMoreButton = await screen.findByRole('button', { name: 'Load more' });
|
|
271
271
|
expect(loadMoreButton).toBeEnabled();
|
|
272
272
|
}, 15000);
|
|
@@ -3,11 +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 {
|
|
7
|
-
ContractFactory,
|
|
8
|
-
CourseProductRelationFactory,
|
|
9
|
-
OrganizationFactory,
|
|
10
|
-
} from 'utils/test/factories/joanie';
|
|
6
|
+
import { ContractFactory, OfferingFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
11
7
|
import { expectNoSpinner } from 'utils/test/expectSpinner';
|
|
12
8
|
import { expectBannerError } from 'utils/test/expectBanner';
|
|
13
9
|
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
@@ -37,8 +33,8 @@ jest.mock('components/ContractFrame', () => ({
|
|
|
37
33
|
describe('pages/TeacherDashboardContracts', () => {
|
|
38
34
|
setupJoanieSession();
|
|
39
35
|
|
|
40
|
-
it('should render a list of contracts for
|
|
41
|
-
const
|
|
36
|
+
it('should render a list of contracts for an offering', async () => {
|
|
37
|
+
const offering = OfferingFactory().one();
|
|
42
38
|
const contracts = ContractFactory({
|
|
43
39
|
student_signed_on: Date.toString(),
|
|
44
40
|
organization_signed_on: Date.toString(),
|
|
@@ -48,31 +44,32 @@ describe('pages/TeacherDashboardContracts', () => {
|
|
|
48
44
|
|
|
49
45
|
// OrganizationContractFilter request all organizations forwho the user have access
|
|
50
46
|
fetchMock.get(
|
|
51
|
-
`https://joanie.endpoint/api/v1.0/organizations/?
|
|
47
|
+
`https://joanie.endpoint/api/v1.0/organizations/?offering_id=${offering.id}`,
|
|
52
48
|
organizations,
|
|
53
49
|
);
|
|
54
50
|
// TeacherDashboardContracts request a paginated list of contracts to display
|
|
55
51
|
fetchMock.get(
|
|
56
|
-
`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`,
|
|
57
54
|
{ results: contracts, count: 0, previous: null, next: null },
|
|
58
55
|
);
|
|
59
56
|
// useTeacherContractsToSign request all contract to sign, without pagination
|
|
60
57
|
fetchMock.get(
|
|
61
|
-
`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}`,
|
|
62
60
|
{ results: [], count: 0, previous: null, next: null },
|
|
63
61
|
);
|
|
64
62
|
|
|
65
63
|
render(<TeacherDashboardContracts />, {
|
|
66
64
|
routerOptions: {
|
|
67
|
-
path: '/courses/:courseId/products/:
|
|
68
|
-
initialEntries: [
|
|
69
|
-
`/courses/${courseProductRelation.course.id}/products/${courseProductRelation.id}/contracts`,
|
|
70
|
-
],
|
|
65
|
+
path: '/courses/:courseId/products/:offeringId/contracts',
|
|
66
|
+
initialEntries: [`/courses/${offering.course.id}/products/${offering.id}/contracts`],
|
|
71
67
|
},
|
|
72
68
|
});
|
|
73
69
|
|
|
74
70
|
await expectNoSpinner();
|
|
75
71
|
|
|
72
|
+
// screen.logTestingPlaygroundURL();
|
|
76
73
|
// Organization filter should have been rendered
|
|
77
74
|
const organizationFilter: HTMLInputElement = await screen.findByRole('combobox', {
|
|
78
75
|
name: 'Organization',
|
|
@@ -42,20 +42,15 @@ const TeacherDashboardContracts = () => {
|
|
|
42
42
|
defaultPage: page ? parseInt(page, 10) : 1,
|
|
43
43
|
pageSize: PER_PAGE.teacherContractList,
|
|
44
44
|
});
|
|
45
|
-
const {
|
|
46
|
-
|
|
47
|
-
courseProductRelationId: routeCourseProductRelationId,
|
|
48
|
-
} = useParams<TeacherDashboardContractsParams>();
|
|
45
|
+
const { organizationId: routeOrganizationId, offeringId: routeOfferingId } =
|
|
46
|
+
useParams<TeacherDashboardContractsParams>();
|
|
49
47
|
// organization list is used to show/hide organization filter.
|
|
50
48
|
// when organizationId is in route's params this filter is always hidden.
|
|
51
49
|
// therefore we don't need to enable this query.
|
|
52
50
|
const {
|
|
53
51
|
items: organizationList,
|
|
54
52
|
states: { isFetched: isOrganizationListFetched },
|
|
55
|
-
} = useOrganizations(
|
|
56
|
-
{ course_product_relation_id: routeCourseProductRelationId },
|
|
57
|
-
{ enabled: !routeOrganizationId },
|
|
58
|
-
);
|
|
53
|
+
} = useOrganizations({ offering_id: routeOfferingId }, { enabled: !routeOrganizationId });
|
|
59
54
|
const hasMultipleOrganizations = isOrganizationListFetched && organizationList.length > 1;
|
|
60
55
|
const { initialFilters, filters, setFilters } = useTeacherContractFilters();
|
|
61
56
|
const {
|
|
@@ -98,7 +93,7 @@ const TeacherDashboardContracts = () => {
|
|
|
98
93
|
<div className="dashboard__page__actions">
|
|
99
94
|
<ContractActionsBar
|
|
100
95
|
organizationId={filters.organization_id!}
|
|
101
|
-
|
|
96
|
+
offeringId={filters.offering_id}
|
|
102
97
|
/>
|
|
103
98
|
<ContractFiltersBar
|
|
104
99
|
defaultValues={initialFilters}
|
|
@@ -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,10 +151,7 @@ describe.each([
|
|
|
151
151
|
|
|
152
152
|
render(
|
|
153
153
|
<Wrapper>
|
|
154
|
-
<BulkDownloadContractButton
|
|
155
|
-
organizationId={organization?.id}
|
|
156
|
-
courseProductRelationId={courseProductRelation?.id}
|
|
157
|
-
/>
|
|
154
|
+
<BulkDownloadContractButton organizationId={organization?.id} offeringId={offering?.id} />
|
|
158
155
|
</Wrapper>,
|
|
159
156
|
);
|
|
160
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(() => {
|
package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx
CHANGED
|
@@ -97,38 +97,30 @@ describe('TeacherDashboardContractsLayout/ContractActionsBar', () => {
|
|
|
97
97
|
{
|
|
98
98
|
label: "doesn't have contract to download",
|
|
99
99
|
hasContractToDownload: false,
|
|
100
|
-
|
|
100
|
+
offeringId: undefined,
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
|
-
label: "doesn't have contract to download
|
|
103
|
+
label: "doesn't have contract to download and offeringId",
|
|
104
104
|
hasContractToDownload: false,
|
|
105
|
-
|
|
105
|
+
offeringId: faker.string.uuid(),
|
|
106
106
|
},
|
|
107
|
-
])(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
expect(
|
|
125
|
-
screen.getByRole('button', { name: /Sign all pending contracts/ }),
|
|
126
|
-
).toBeInTheDocument();
|
|
127
|
-
expect(
|
|
128
|
-
screen.queryByRole('button', { name: /Request contracts archive/ }),
|
|
129
|
-
).not.toBeInTheDocument();
|
|
130
|
-
},
|
|
131
|
-
);
|
|
107
|
+
])('should only display sign button when $label', ({ hasContractToDownload, offeringId }) => {
|
|
108
|
+
mockHasContractToDownload = hasContractToDownload;
|
|
109
|
+
mockCanSignContracts = true;
|
|
110
|
+
mockContractsToSignCount = 1;
|
|
111
|
+
|
|
112
|
+
render(
|
|
113
|
+
<Wrapper>
|
|
114
|
+
<ContractActionsBar offeringId={offeringId} organizationId={faker.string.uuid()} />
|
|
115
|
+
</Wrapper>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(screen.getByTestId('teacher-contracts-list-actionsBar')).toBeInTheDocument();
|
|
119
|
+
expect(screen.getByRole('button', { name: /Sign all pending contracts/ })).toBeInTheDocument();
|
|
120
|
+
expect(
|
|
121
|
+
screen.queryByRole('button', { name: /Request contracts archive/ }),
|
|
122
|
+
).not.toBeInTheDocument();
|
|
123
|
+
});
|
|
132
124
|
|
|
133
125
|
it("shouldn't only display download button", () => {
|
|
134
126
|
mockHasContractToDownload = true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
|
-
import { Organization,
|
|
2
|
+
import { Organization, Offering } from 'types/Joanie';
|
|
3
3
|
import useTeacherContractsToSign from 'pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign';
|
|
4
4
|
import useHasContractToDownload from 'pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload';
|
|
5
5
|
import SignOrganizationContractButton from '../SignOrganizationContractButton';
|
|
@@ -7,18 +7,18 @@ import BulkDownloadContractButton from '../BulkDownloadContractButton';
|
|
|
7
7
|
|
|
8
8
|
interface ContractActionsProps {
|
|
9
9
|
organizationId: Organization['id'];
|
|
10
|
-
|
|
10
|
+
offeringId?: Offering['id'];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const ContractActionsBar = ({ organizationId,
|
|
13
|
+
const ContractActionsBar = ({ organizationId, offeringId }: ContractActionsProps) => {
|
|
14
14
|
const { canSignContracts, contractsToSignCount } = useTeacherContractsToSign({
|
|
15
15
|
organizationId,
|
|
16
|
-
|
|
16
|
+
offeringId,
|
|
17
17
|
});
|
|
18
|
-
const hasContractToDownload = useHasContractToDownload(organizationId,
|
|
18
|
+
const hasContractToDownload = useHasContractToDownload(organizationId, offeringId);
|
|
19
19
|
|
|
20
20
|
const nbAvailableActions = [canSignContracts, hasContractToDownload].filter((val) => val).length;
|
|
21
|
-
const
|
|
21
|
+
const offeringIds = offeringId ? [offeringId] : undefined;
|
|
22
22
|
return (
|
|
23
23
|
nbAvailableActions > 0 && (
|
|
24
24
|
<div
|
|
@@ -31,17 +31,14 @@ const ContractActionsBar = ({ organizationId, courseProductRelationId }: Contrac
|
|
|
31
31
|
{canSignContracts && (
|
|
32
32
|
<div>
|
|
33
33
|
<SignOrganizationContractButton
|
|
34
|
-
|
|
34
|
+
offeringIds={offeringIds}
|
|
35
35
|
organizationId={organizationId}
|
|
36
36
|
contractToSignCount={contractsToSignCount}
|
|
37
37
|
/>
|
|
38
38
|
</div>
|
|
39
39
|
)}
|
|
40
40
|
{hasContractToDownload && (
|
|
41
|
-
<BulkDownloadContractButton
|
|
42
|
-
organizationId={organizationId}
|
|
43
|
-
courseProductRelationId={courseProductRelationId}
|
|
44
|
-
/>
|
|
41
|
+
<BulkDownloadContractButton organizationId={organizationId} offeringId={offeringId} />
|
|
45
42
|
)}
|
|
46
43
|
</div>
|
|
47
44
|
)
|
|
@@ -70,19 +70,19 @@ describe('TeacherDashboardContractsLayout/SignOrganizationContractButton', () =>
|
|
|
70
70
|
{
|
|
71
71
|
label: "organization's contracts",
|
|
72
72
|
organizationId: faker.string.uuid(),
|
|
73
|
-
|
|
73
|
+
offeringIds: undefined,
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
label: "organization's training contracts",
|
|
77
77
|
organizationId: faker.string.uuid(),
|
|
78
|
-
|
|
78
|
+
offeringIds: [faker.string.uuid()],
|
|
79
79
|
},
|
|
80
|
-
])('should open $label frame on click', async ({ organizationId,
|
|
80
|
+
])('should open $label frame on click', async ({ organizationId, offeringIds }) => {
|
|
81
81
|
render(
|
|
82
82
|
<Wrapper>
|
|
83
83
|
<SignOrganizationContractButton
|
|
84
84
|
organizationId={organizationId}
|
|
85
|
-
|
|
85
|
+
offeringIds={offeringIds}
|
|
86
86
|
contractToSignCount={12}
|
|
87
87
|
/>
|
|
88
88
|
</Wrapper>,
|
|
@@ -92,8 +92,8 @@ describe('TeacherDashboardContractsLayout/SignOrganizationContractButton', () =>
|
|
|
92
92
|
const user = userEvent.setup();
|
|
93
93
|
|
|
94
94
|
let getInvitationLinkUrl = `https://joanie.test/api/v1.0/organizations/${organizationId}/contracts-signature-link/`;
|
|
95
|
-
if (
|
|
96
|
-
getInvitationLinkUrl += `?
|
|
95
|
+
if (offeringIds) {
|
|
96
|
+
getInvitationLinkUrl += `?offering_ids=${offeringIds[0]}`;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
fetchMock.get(getInvitationLinkUrl, {
|
package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { defineMessages, FormattedMessage } from 'react-intl';
|
|
|
3
3
|
import { Button } from '@openfun/cunningham-react';
|
|
4
4
|
import { OrganizationContractFrame } from 'components/ContractFrame';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Offering, Organization } from 'types/Joanie';
|
|
7
7
|
|
|
8
8
|
const messages = defineMessages({
|
|
9
9
|
signAllPendingContracts: {
|
|
@@ -14,7 +14,7 @@ const messages = defineMessages({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
interface Props {
|
|
17
|
-
|
|
17
|
+
offeringIds?: Offering['id'][];
|
|
18
18
|
organizationId: Organization['id'];
|
|
19
19
|
contractToSignCount: number;
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
const SignOrganizationContractButton = ({
|
|
23
23
|
organizationId,
|
|
24
24
|
contractToSignCount,
|
|
25
|
-
|
|
25
|
+
offeringIds = [],
|
|
26
26
|
}: Props) => {
|
|
27
27
|
const [contractFrameOpened, setContractFrameOpened] = useState(false);
|
|
28
28
|
const hasContractToSign = contractToSignCount > 0;
|
|
@@ -48,7 +48,7 @@ const SignOrganizationContractButton = ({
|
|
|
48
48
|
</Button>
|
|
49
49
|
)}
|
|
50
50
|
<OrganizationContractFrame
|
|
51
|
-
|
|
51
|
+
offeringIds={offeringIds}
|
|
52
52
|
organizationId={organizationId}
|
|
53
53
|
isOpen={contractFrameOpened}
|
|
54
54
|
onClose={() => setContractFrameOpened(false)}
|
package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { IntlProvider } from 'react-intl';
|
|
|
5
5
|
import { PropsWithChildren } from 'react';
|
|
6
6
|
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
|
|
7
7
|
import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
8
|
-
import {
|
|
8
|
+
import { OfferingFactory, OrganizationFactory } from 'utils/test/factories/joanie';
|
|
9
9
|
import {
|
|
10
10
|
LocalStorageArchiveFilters,
|
|
11
11
|
storeContractArchiveId,
|
|
@@ -41,24 +41,24 @@ describe.each([
|
|
|
41
41
|
{
|
|
42
42
|
testLabel: 'for all organization and all trainings',
|
|
43
43
|
organization: undefined,
|
|
44
|
-
|
|
44
|
+
offering: undefined,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
testLabel: 'for a training in an organization',
|
|
48
48
|
organization: OrganizationFactory().one(),
|
|
49
|
-
|
|
49
|
+
offering: OfferingFactory().one(),
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
testLabel: 'for an organization',
|
|
53
53
|
organization: OrganizationFactory().one(),
|
|
54
|
-
|
|
54
|
+
offering: undefined,
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
testLabel: 'for a training',
|
|
58
58
|
organization: undefined,
|
|
59
|
-
|
|
59
|
+
offering: OfferingFactory().one(),
|
|
60
60
|
},
|
|
61
|
-
])('useCheckContractArchiveExists $testLabel', ({ organization,
|
|
61
|
+
])('useCheckContractArchiveExists $testLabel', ({ organization, offering }) => {
|
|
62
62
|
const Wrapper = ({ children }: PropsWithChildren) => {
|
|
63
63
|
return (
|
|
64
64
|
<IntlProvider locale="en">
|
|
@@ -71,7 +71,7 @@ describe.each([
|
|
|
71
71
|
beforeEach(() => {
|
|
72
72
|
localStorageArchiveFilters = {
|
|
73
73
|
organizationId: organization ? organization.id : undefined,
|
|
74
|
-
|
|
74
|
+
offeringId: offering ? offering.id : undefined,
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
// Joanie providers calls
|