richie-education 2.24.0 → 2.25.0-b2.dev101
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/.eslintignore +2 -0
- package/.nvmrc +1 -1
- package/.prettierignore +2 -0
- package/.storybook/preview-body.html +1 -1
- package/.storybook/preview.tsx +5 -2
- package/cunningham.cjs +52 -43
- package/i18n/locales/ar-SA.json +500 -100
- package/i18n/locales/es-ES.json +500 -100
- package/i18n/locales/fa-IR.json +500 -100
- package/i18n/locales/fr-CA.json +564 -164
- package/i18n/locales/fr-FR.json +517 -117
- package/i18n/locales/ko-KR.json +500 -100
- package/i18n/locales/pt-PT.json +526 -126
- package/i18n/locales/ru-RU.json +500 -100
- package/i18n/locales/vi-VN.json +1734 -0
- package/jest/setup.ts +11 -1
- package/js/api/enrollment.ts +1 -1
- package/js/api/joanie.spec.ts +63 -2
- package/js/api/joanie.ts +218 -141
- package/js/api/lms/dummy.spec.ts +9 -1
- package/js/api/lms/dummy.ts +63 -10
- package/js/api/lms/joanie.spec.ts +49 -31
- package/js/api/lms/joanie.ts +53 -35
- package/js/api/lms/openedx-hawthorn.spec.ts +27 -11
- package/js/api/lms/openedx-hawthorn.ts +7 -6
- package/js/components/AddressesManagement/AddressForm/index.spec.tsx +157 -0
- package/js/components/AddressesManagement/AddressForm/index.stories.tsx +36 -0
- package/js/components/AddressesManagement/AddressForm/index.tsx +163 -0
- package/js/components/AddressesManagement/{validationSchema.ts → AddressForm/validationSchema.ts} +1 -23
- package/js/components/AddressesManagement/_styles.scss +1 -1
- package/js/components/AddressesManagement/index.spec.tsx +171 -202
- package/js/components/AddressesManagement/index.stories.tsx +29 -0
- package/js/components/AddressesManagement/index.tsx +11 -3
- package/js/components/Badge/index.spec.tsx +17 -0
- package/js/components/Badge/index.stories.tsx +22 -0
- package/js/components/Badge/index.tsx +18 -0
- package/js/components/Banner/index.tsx +6 -1
- package/js/components/ContractFrame/AbstractContractFrame.spec.tsx +332 -0
- package/js/components/ContractFrame/AbstractContractFrame.tsx +289 -0
- package/js/components/ContractFrame/LearnerContractFrame.spec.tsx +125 -0
- package/js/components/ContractFrame/LearnerContractFrame.tsx +42 -0
- package/js/components/ContractFrame/OrganizationContractFrame.spec.tsx +167 -0
- package/js/components/ContractFrame/OrganizationContractFrame.tsx +70 -0
- package/js/components/ContractFrame/_styles.scss +62 -0
- package/js/components/ContractFrame/iframe-manager.js +158 -0
- package/js/components/ContractFrame/index.ts +5 -0
- package/js/components/ContractStatus/index.spec.tsx +120 -0
- package/js/components/ContractStatus/index.tsx +67 -0
- package/js/components/CourseGlimpse/CourseGlimpseFooter.tsx +7 -7
- package/js/components/CourseGlimpse/index.tsx +5 -1
- package/js/components/CourseGlimpse/utils.ts +24 -16
- package/js/components/CourseGlimpseList/index.spec.tsx +1 -1
- package/js/components/CourseGlimpseList/index.tsx +1 -1
- package/js/components/CourseGlimpseList/utils.ts +3 -2
- package/js/components/DjangoCMSTemplate/index.spec.tsx +2 -2
- package/js/components/DownloadCertificateButton/index.tsx +58 -0
- package/js/components/DownloadContractButton/index.spec.tsx +155 -0
- package/js/components/DownloadContractButton/index.tsx +48 -0
- package/js/components/Form/CountrySelectField.tsx +28 -16
- package/js/components/Form/Input/index.spec.tsx +76 -0
- package/js/components/Form/Input/index.tsx +47 -0
- package/js/components/Form/Select/index.spec.tsx +99 -0
- package/js/components/Form/Select/index.tsx +43 -0
- package/js/components/{AddressesManagement → Form}/ValidationErrors.ts +10 -5
- package/js/components/Form/index.ts +5 -1
- package/js/components/Form/messages.ts +14 -0
- package/js/components/Form/test-utils.ts +19 -0
- package/js/components/Form/utils.spec.ts +72 -0
- package/js/components/Form/utils.ts +37 -0
- package/js/components/Icon/index.stories.tsx +2 -1
- package/js/components/Modal/_styles.scss +0 -8
- package/js/components/Modal/index.spec.tsx +0 -6
- package/js/components/Modal/index.tsx +23 -17
- package/js/components/PaymentButton/_styles.scss +26 -0
- package/js/{widgets/CourseProductItem → components/PaymentButton}/components/PaymentInterfaces/Dummy.tsx +1 -1
- package/js/{widgets/CourseProductItem → components/PaymentButton}/components/PaymentInterfaces/PayplugLightbox.tsx +30 -7
- package/js/{widgets/CourseProductItem → components/PaymentButton}/components/PaymentInterfaces/__mocks__/index.tsx +1 -1
- package/js/{widgets/CourseProductItem → components/PaymentButton}/components/PaymentInterfaces/index.spec.tsx +5 -3
- package/js/{widgets/CourseProductItem → components/PaymentButton}/components/PaymentInterfaces/index.tsx +7 -5
- package/js/components/PaymentButton/hooks/useTerms.tsx +74 -0
- package/js/components/PaymentButton/index.spec.tsx +1038 -0
- package/js/{widgets/CourseProductItem/components → components}/PaymentButton/index.tsx +94 -41
- package/js/components/PurchaseButton/index.spec.tsx +377 -0
- package/js/components/PurchaseButton/index.stories.tsx +15 -0
- package/js/{widgets/CourseProductItem/components → components}/PurchaseButton/index.tsx +72 -23
- package/js/components/PurchaseButton/styles.scss +7 -0
- package/js/components/RegisteredAddress/_styles.scss +1 -3
- package/js/components/RegisteredAddress/index.spec.tsx +1 -1
- package/js/components/RegisteredAddress/index.stories.tsx +40 -0
- package/js/components/RegisteredAddress/index.tsx +17 -19
- package/js/components/SaleTunnel/_styles.scss +11 -0
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/RegisteredCreditCard/index.tsx +4 -10
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepPayment/_styles.scss +7 -0
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepPayment/index.spec.tsx +85 -61
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepPayment/index.tsx +55 -57
- package/js/components/SaleTunnel/components/SaleTunnelStepResume/_styles.scss +63 -0
- package/js/components/SaleTunnel/components/SaleTunnelStepResume/index.spec.tsx +80 -0
- package/js/components/SaleTunnel/components/SaleTunnelStepResume/index.tsx +88 -0
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepValidation/CourseRunsList.tsx +6 -2
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepValidation/_styles.scss +5 -0
- package/js/components/SaleTunnel/components/SaleTunnelStepValidation/index.spec.tsx +170 -0
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepValidation/index.tsx +41 -10
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/StepBreadcrumb/index.spec.tsx +1 -1
- package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/StepBreadcrumb/index.tsx +1 -1
- package/js/components/SaleTunnel/context.tsx +44 -0
- package/js/{widgets/CourseProductItem/components → components}/SaleTunnel/index.spec.tsx +27 -22
- package/js/{widgets/CourseProductItem/components → components}/SaleTunnel/index.tsx +96 -24
- package/js/components/SignContractButton/index.omniscientOrders.spec.tsx +135 -0
- package/js/components/SignContractButton/index.spec.tsx +213 -0
- package/js/components/SignContractButton/index.tsx +97 -0
- package/js/components/SuccessIcon/_styles.scss +66 -0
- package/js/components/SuccessIcon/index.tsx +10 -0
- package/js/components/TeacherDashboardCourseList/_styles.scss +0 -1
- package/js/components/TeacherDashboardCourseList/index.spec.tsx +9 -9
- package/js/components/TeacherDashboardCourseList/index.tsx +25 -31
- package/js/contexts/JoanieApiContext/index.spec.tsx +1 -1
- package/js/contexts/SessionContext/BaseSessionProvider.tsx +12 -22
- package/js/contexts/SessionContext/JoanieSessionProvider.spec.tsx +14 -0
- package/js/contexts/SessionContext/JoanieSessionProvider.tsx +33 -34
- package/js/contexts/SessionContext/index.spec.tsx +6 -7
- package/js/hooks/useBreadcrumbsPlaceholders.tsx +1 -1
- package/js/hooks/useContractAbilities/index.spec.ts +27 -0
- package/js/hooks/useContractAbilities/index.ts +8 -0
- package/js/hooks/useContractArchive/index.download.spec.tsx +126 -0
- package/js/hooks/useContractArchive/index.spec.tsx +91 -0
- package/js/hooks/useContractArchive/index.ts +64 -0
- package/js/hooks/useContracts/index.tsx +68 -0
- package/js/hooks/useCourseProductRelation/index.ts +8 -5
- package/js/hooks/useCourseProductUnion/index.spec.tsx +14 -10
- package/js/hooks/useCourseProductUnion/index.ts +6 -2
- package/js/hooks/useCourseProducts.ts +45 -0
- package/js/hooks/useCourseSearchParams/computeNewFilterValue.ts +3 -3
- package/js/hooks/useCourses/index.spec.tsx +2 -2
- package/js/hooks/useCourses/index.ts +4 -4
- package/js/hooks/useCreditCards/index.spec.tsx +4 -4
- package/js/hooks/useDashboardAddressForm.tsx +85 -87
- package/js/hooks/useDownloadCertificate/index.spec.tsx +19 -6
- package/js/hooks/useDownloadCertificate/index.tsx +2 -20
- package/js/hooks/useEnrollments.ts +1 -1
- package/js/hooks/useJoanieUserAbilities/index.not.isJoanieEnabled.spec.tsx +17 -0
- package/js/hooks/useJoanieUserAbilities/index.spec.tsx +68 -0
- package/js/hooks/useJoanieUserAbilities/index.tsx +11 -0
- package/js/hooks/useJoanieUserProfile.tsx +34 -0
- package/js/hooks/useOrders.ts +69 -26
- package/js/hooks/useOrganizations/index.ts +1 -1
- package/js/hooks/useProductOrder/index.spec.tsx +113 -0
- package/js/hooks/useProductOrder/index.tsx +33 -0
- package/js/hooks/useQueryKeyInvalidateListener.tsx +16 -0
- package/js/hooks/useResources/index.spec.tsx +30 -29
- package/js/hooks/useResources/index.tsx +11 -4
- package/js/hooks/useResources/useResourcesOmniscient.ts +2 -2
- package/js/hooks/useResources/useResourcesRoot.ts +21 -17
- package/js/hooks/useTeacherPendingContractsCount/index.ts +34 -0
- package/js/hooks/useUnionResource/index.spec.tsx +5 -2
- package/js/hooks/useUnionResource/index.ts +20 -3
- package/js/hooks/useUnionResource/utils/fetchEntity.ts +5 -4
- package/js/index.tsx +2 -2
- package/js/pages/DashboardAddressesManagement/DashboardAddressBox.tsx +1 -1
- package/js/pages/DashboardAddressesManagement/DashboardCreateAddress.spec.tsx +79 -72
- package/js/pages/DashboardAddressesManagement/DashboardCreateAddress.tsx +4 -4
- package/js/pages/DashboardAddressesManagement/DashboardEditAddress.spec.tsx +32 -23
- package/js/pages/DashboardAddressesManagement/DashboardEditAddress.tsx +6 -6
- package/js/pages/DashboardAddressesManagement/DashboardEditAddressLoader.tsx +2 -2
- package/js/pages/DashboardAddressesManagement/index.spec.tsx +4 -3
- package/js/pages/DashboardAddressesManagement/index.tsx +5 -5
- package/js/pages/DashboardCertificates/index.spec.tsx +3 -2
- package/js/pages/DashboardCertificates/index.tsx +2 -1
- package/js/pages/DashboardContracts/_styles.scss +8 -0
- package/js/pages/DashboardContracts/index.spec.tsx +147 -0
- package/js/pages/DashboardContracts/index.tsx +76 -0
- package/js/pages/DashboardCourses/index.spec.tsx +81 -61
- package/js/pages/DashboardCourses/index.tsx +15 -12
- package/js/pages/DashboardCourses/useOrdersEnrollments.tsx +34 -8
- package/js/pages/DashboardCreditCardsManagement/DashboardCreditCardBox.tsx +1 -1
- package/js/pages/DashboardCreditCardsManagement/DashboardEditCreditCard.spec.tsx +7 -6
- package/js/pages/DashboardCreditCardsManagement/DashboardEditCreditCard.tsx +43 -45
- package/js/pages/DashboardCreditCardsManagement/DashboardEditCreditCardLoader.tsx +2 -2
- package/js/pages/DashboardCreditCardsManagement/index.spec.tsx +13 -12
- package/js/pages/DashboardCreditCardsManagement/index.tsx +3 -3
- package/js/pages/DashboardOrderLayout/_styles.scss +5 -0
- package/js/pages/DashboardOrderLayout/index.spec.tsx +8 -8
- package/js/pages/DashboardOrderLayout/index.tsx +11 -6
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.spec.tsx +358 -0
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardContracts/index.tsx +129 -0
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardCourseContractsLayout/index.tsx +26 -0
- package/js/pages/TeacherDashboardContractsLayout/TeacherDashboardOrganizationContractsLayout/index.tsx +26 -0
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.spec.tsx +136 -0
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.timer.spec.tsx +144 -0
- package/js/pages/TeacherDashboardContractsLayout/components/BulkDownloadContractButton/index.tsx +73 -0
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.spec.tsx +185 -0
- package/js/pages/TeacherDashboardContractsLayout/components/ContractActionsBar/index.tsx +47 -0
- package/js/pages/TeacherDashboardContractsLayout/components/ContractFiltersBar/index.spec.tsx +179 -0
- package/js/pages/TeacherDashboardContractsLayout/components/ContractFiltersBar/index.tsx +86 -0
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.spec.tsx +109 -0
- package/js/pages/TeacherDashboardContractsLayout/components/SignOrganizationContractButton/index.tsx +60 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.spec.tsx +124 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useCheckContractArchiveExists/index.tsx +73 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDefaultOrganizationId/index.spec.tsx +134 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDefaultOrganizationId/index.tsx +28 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.spec.ts +85 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/contractArchiveLocalStorage.ts +50 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.spec.tsx +266 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useDownloadContractArchive/index.tsx +153 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.spec.tsx +100 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useHasContractToDownload/index.tsx +27 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.spec.tsx +193 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractFilters/index.tsx +44 -0
- package/js/pages/TeacherDashboardContractsLayout/hooks/useTeacherContractsToSign.tsx +32 -0
- package/js/pages/TeacherDashboardContractsLayout/index.ts +2 -0
- package/js/pages/TeacherDashboardContractsLayout/styles.scss +15 -0
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/CourseRunListCell/index.spec.tsx +1 -1
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/_styles.scss +1 -2
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/index.spec.tsx +2 -2
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/utils.spec.tsx +1 -1
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/utils.tsx +11 -10
- package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/index.tsx +9 -8
- package/js/pages/{TeacherCoursesDashboardLoader → TeacherDashboardCoursesLoader}/index.spec.tsx +17 -17
- package/js/pages/{TeacherCoursesDashboardLoader → TeacherDashboardCoursesLoader}/index.tsx +7 -7
- package/js/pages/{TeacherOrganizationCourseDashboardLoader → TeacherDashboardOrganizationCourseLoader}/index.tsx +5 -5
- package/js/pages/{TeacherTrainingDashboard/TeacherTrainingDashboardLoader.tsx → TeacherDashboardTraining/TeacherDashboardTrainingLoader.tsx} +10 -9
- package/js/pages/{TeacherTrainingDashboard → TeacherDashboardTraining}/index.spec.tsx +76 -6
- package/js/pages/{TeacherTrainingDashboard → TeacherDashboardTraining}/index.tsx +6 -6
- package/js/settings.dev.dist.ts +3 -0
- package/js/settings.ts +29 -1
- package/js/translations/ar-SA.json +1 -1
- package/js/translations/es-ES.json +1 -1
- package/js/translations/fa-IR.json +1 -1
- package/js/translations/fr-CA.json +1 -1
- package/js/translations/fr-FR.json +1 -1
- package/js/translations/ko-KR.json +1 -1
- package/js/translations/pt-PT.json +1 -1
- package/js/translations/ru-RU.json +1 -1
- package/js/translations/vi-VN.json +1 -0
- package/js/types/Joanie.ts +263 -80
- package/js/types/Suggestion.ts +2 -2
- package/js/types/User.ts +19 -1
- package/js/types/commonDataProps.ts +3 -0
- package/js/types/index.ts +1 -1
- package/js/utils/AbilitiesHelper/contractAbilities.spec.ts +35 -0
- package/js/utils/AbilitiesHelper/contractAbilities.ts +14 -0
- package/js/utils/AbilitiesHelper/index.ts +71 -0
- package/js/utils/AbilitiesHelper/joanieUserProfileAbilities.spec.ts +55 -0
- package/js/utils/AbilitiesHelper/joanieUserProfileAbilities.ts +16 -0
- package/js/utils/AbilitiesHelper/types.ts +36 -0
- package/js/utils/ContractHelper/index.spec.ts +73 -0
- package/js/utils/ContractHelper/index.ts +72 -0
- package/js/utils/CourseRuns/index.spec.tsx +20 -1
- package/js/utils/CourseRuns/index.ts +14 -2
- package/js/utils/CoursesHelper/index.spec.ts +45 -55
- package/js/utils/CoursesHelper/index.ts +6 -7
- package/js/utils/CreditCardHelper/index.spec.tsx +26 -22
- package/js/utils/CreditCardHelper/index.tsx +19 -6
- package/js/utils/ObjectHelper/index.spec.ts +18 -10
- package/js/utils/ObjectHelper/index.ts +9 -0
- package/js/utils/OrderHelper/index.ts +32 -0
- package/js/utils/ProductHelper/index.ts +5 -1
- package/js/utils/StringHelper/index.spec.tsx +11 -0
- package/js/utils/StringHelper/index.ts +8 -0
- package/js/utils/UserHelper/index.spec.ts +18 -0
- package/js/utils/UserHelper/index.ts +8 -0
- package/js/utils/download.ts +43 -0
- package/js/utils/errors/HttpError.ts +10 -0
- package/js/utils/indirection/window.ts +1 -1
- package/js/utils/react-query/createQueryClient.ts +12 -21
- package/js/utils/react-query/useLocalizedQueryKey.ts +1 -1
- package/js/utils/react-query/useSessionMutation/index.spec.tsx +8 -8
- package/js/utils/react-query/useSessionMutation/index.ts +6 -11
- package/js/utils/react-query/useSessionQuery/index.spec.tsx +36 -8
- package/js/utils/react-query/useSessionQuery/index.ts +14 -21
- package/js/utils/search/getSuggestionsSection/index.spec.ts +4 -3
- package/js/utils/search/getSuggestionsSection/index.ts +4 -1
- package/js/utils/search/index.tsx +8 -3
- package/js/utils/test/createTestQueryClient.ts +7 -7
- package/js/utils/test/expectBanner.ts +16 -3
- package/js/utils/test/factories/factories.ts +4 -4
- package/js/utils/test/factories/joanie.spec.ts +7 -0
- package/js/utils/test/factories/joanie.ts +214 -63
- package/js/utils/test/factories/reactQuery.ts +1 -1
- package/js/utils/test/factories/richie.ts +4 -2
- package/js/utils/test/mockCourseProductWithOrder.ts +28 -0
- package/js/utils/test/mockPaginatedResponse.ts +1 -1
- package/js/utils/test/render.tsx +72 -0
- package/js/utils/test/wrappers/IntlWrapper.tsx +23 -0
- package/js/utils/test/wrappers/JoanieAppWrapper.tsx +42 -0
- package/js/utils/test/wrappers/PresentationalAppWrapper.tsx +18 -0
- package/js/utils/test/wrappers/ReactQueryWrapper.tsx +16 -0
- package/js/utils/test/wrappers/RouterWrapper.tsx +29 -0
- package/js/utils/test/wrappers/types.ts +26 -0
- package/js/widgets/Dashboard/components/DashboardAvatar/_styles.scss +17 -5
- package/js/widgets/Dashboard/components/DashboardAvatar/index.spec.tsx +9 -2
- package/js/widgets/Dashboard/components/DashboardAvatar/index.tsx +16 -5
- package/js/widgets/Dashboard/components/DashboardBox/index.stories.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardBreadcrumbs/_styles.scss +1 -0
- package/js/widgets/Dashboard/components/DashboardBreadcrumbs/index.tsx +7 -4
- package/js/widgets/Dashboard/components/DashboardCard/index.spec.tsx +1 -1
- package/js/widgets/Dashboard/components/DashboardCard/index.stories.tsx +3 -3
- package/js/widgets/Dashboard/components/DashboardCard/index.tsx +2 -2
- package/js/widgets/Dashboard/components/DashboardItem/Certificate/index.spec.tsx +49 -9
- package/js/widgets/Dashboard/components/DashboardItem/Certificate/index.tsx +27 -73
- package/js/widgets/Dashboard/components/DashboardItem/CertificateStatus/index.spec.tsx +65 -0
- package/js/widgets/Dashboard/components/DashboardItem/CertificateStatus/index.tsx +59 -0
- package/js/widgets/Dashboard/components/DashboardItem/Contract/_styles.scss +29 -0
- package/js/widgets/Dashboard/components/DashboardItem/Contract/index.spec.tsx +197 -0
- package/js/widgets/Dashboard/components/DashboardItem/Contract/index.stories.tsx +34 -0
- package/js/widgets/Dashboard/components/DashboardItem/Contract/index.tsx +53 -0
- package/js/widgets/Dashboard/components/DashboardItem/CourseEnrolling/hooks/useCourseRunPeriodMessage.ts +76 -0
- package/js/widgets/Dashboard/components/DashboardItem/CourseEnrolling/index.spec.tsx +158 -0
- package/js/widgets/Dashboard/components/DashboardItem/{DashboardItemCourseEnrolling.stories.tsx → CourseEnrolling/index.stories.tsx} +6 -6
- package/js/widgets/Dashboard/components/DashboardItem/{DashboardItemCourseEnrolling.tsx → CourseEnrolling/index.tsx} +141 -84
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.spec.tsx +40 -37
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/DashboardItemEnrollment.tsx +29 -11
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.spec.tsx +248 -0
- package/js/widgets/Dashboard/components/DashboardItem/Enrollment/ProductCertificateFooter/index.tsx +89 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.spec.tsx +188 -117
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrder.tsx +124 -78
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.spec.tsx +299 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderContract.useUnionResource.cache.spec.tsx +286 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderReadonly.stories.tsx +9 -5
- package/js/widgets/Dashboard/components/DashboardItem/Order/DashboardItemOrderWritable.stories.tsx +10 -6
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateMessage/index.spec.tsx +121 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/OrderStateMessage/index.tsx +98 -0
- package/js/widgets/Dashboard/components/DashboardItem/Order/_styles.scss +43 -0
- package/js/widgets/Dashboard/components/DashboardItem/_styles.scss +34 -37
- package/js/widgets/Dashboard/components/DashboardItem/index.spec.tsx +74 -4
- package/js/widgets/Dashboard/components/DashboardItem/index.stories.tsx +18 -0
- package/js/widgets/Dashboard/components/DashboardItem/index.tsx +91 -26
- package/js/widgets/Dashboard/components/DashboardItem/stories.mock.ts +4 -8
- package/js/widgets/Dashboard/components/DashboardLayout/_styles.scss +14 -5
- package/js/widgets/Dashboard/components/DashboardLayout/index.tsx +10 -3
- package/js/widgets/Dashboard/components/DashboardListAvatar/_styles.scss +8 -0
- package/js/widgets/Dashboard/components/DashboardListAvatar/index.tsx +11 -0
- package/js/widgets/Dashboard/components/DashboardOrderLoader/_styles.scss +5 -0
- package/js/widgets/Dashboard/components/DashboardOrderLoader/index.tsx +50 -14
- package/js/widgets/Dashboard/components/DashboardSidebar/_styles.scss +37 -24
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.spec.tsx +244 -0
- package/js/widgets/Dashboard/components/DashboardSidebar/components/ContractNavLink/index.tsx +49 -0
- package/js/widgets/Dashboard/components/DashboardSidebar/components/MenuNavLink/index.spec.tsx +40 -0
- package/js/widgets/Dashboard/components/DashboardSidebar/components/MenuNavLink/index.tsx +28 -0
- package/js/widgets/Dashboard/components/DashboardSidebar/components/NavigationSelect.tsx +58 -0
- package/js/widgets/Dashboard/components/DashboardSidebar/index.stories.tsx +11 -1
- package/js/widgets/Dashboard/components/DashboardSidebar/index.tsx +18 -69
- package/js/widgets/Dashboard/components/DashboardSidebar/utils.ts +6 -0
- package/js/widgets/Dashboard/components/FilterOrganization/index.tsx +58 -0
- package/js/widgets/Dashboard/components/FiltersBar/index.tsx +9 -0
- package/js/widgets/Dashboard/components/LearnerDashboardSidebar/index.tsx +4 -2
- package/js/widgets/Dashboard/components/NavigateWithParams/index.spec.tsx +31 -40
- package/js/widgets/Dashboard/components/RouterButton/index.tsx +2 -1
- package/js/widgets/Dashboard/components/Signature/DummyContractPlaceholder.tsx +25 -0
- package/js/widgets/Dashboard/components/Signature/SignatureDummy.tsx +58 -0
- package/js/widgets/Dashboard/components/Signature/SignatureLexPersona.tsx +72 -0
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx +215 -0
- package/js/widgets/Dashboard/components/{TeacherCourseDashboardSidebar → TeacherDashboardCourseSidebar}/index.tsx +75 -31
- package/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/utils.ts +23 -0
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.spec.tsx +154 -0
- package/js/widgets/Dashboard/components/TeacherDashboardOrganizationSidebar/index.stories.tsx +42 -0
- package/js/widgets/Dashboard/components/{TeacherOrganizationDashboardSidebar → TeacherDashboardOrganizationSidebar}/index.tsx +40 -29
- package/js/widgets/Dashboard/components/{TeacherProfileDashboardSidebar → TeacherDashboardProfileSidebar}/components/OrganizationLinks/_styles.scss +27 -10
- package/js/widgets/Dashboard/components/TeacherDashboardProfileSidebar/components/OrganizationLinks/index.spec.tsx +49 -0
- package/js/widgets/Dashboard/components/{TeacherProfileDashboardSidebar → TeacherDashboardProfileSidebar}/components/OrganizationLinks/index.tsx +18 -7
- package/js/widgets/Dashboard/components/{TeacherProfileDashboardSidebar → TeacherDashboardProfileSidebar}/index.spec.tsx +13 -39
- package/js/widgets/Dashboard/components/{TeacherProfileDashboardSidebar → TeacherDashboardProfileSidebar}/index.stories.tsx +5 -5
- package/js/widgets/Dashboard/components/{TeacherProfileDashboardSidebar → TeacherDashboardProfileSidebar}/index.tsx +4 -3
- package/js/widgets/Dashboard/hooks/useEnroll/index.ts +8 -8
- package/js/widgets/Dashboard/index.spec.tsx +22 -12
- package/js/widgets/Dashboard/utils/learnerRouteMessages.tsx +12 -1
- package/js/widgets/Dashboard/utils/learnerRoutes.tsx +6 -0
- package/js/widgets/Dashboard/utils/teacherRouteMessages.tsx +60 -4
- package/js/widgets/Dashboard/utils/teacherRoutes.tsx +87 -13
- package/js/widgets/LtiConsumer/index.spec.tsx +44 -33
- package/js/widgets/LtiConsumer/index.tsx +11 -15
- package/js/widgets/Search/components/SearchFilterGroup/index.spec.tsx +0 -5
- package/js/widgets/Search/components/SearchFilterGroupModal/_styles.scss +0 -9
- package/js/widgets/Search/components/SearchFilterGroupModal/index.spec.tsx +0 -5
- package/js/widgets/Search/components/SearchFilterGroupModal/index.tsx +86 -60
- package/js/widgets/Search/components/SearchFilterValueParent/index.stories.tsx +51 -0
- package/js/widgets/Search/components/SearchFilterValueParent/index.tsx +7 -7
- package/js/widgets/Search/components/SearchFiltersPane/_styles.scss +2 -16
- package/js/widgets/Search/components/SearchFiltersPane/index.tsx +9 -6
- package/js/widgets/Search/hooks/useCourseSearch/index.ts +13 -7
- package/js/widgets/Search/index.spec.tsx +3 -2
- package/js/widgets/Search/utils/getResourceList/index.spec.ts +12 -5
- package/js/widgets/Search/utils/getResourceList/index.ts +6 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/CourseProductItemFooter/index.tsx +74 -0
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/_styles.scss +11 -14
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCertificateItem/_styles.scss +1 -1
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCertificateItem/index.spec.tsx +13 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseProductCertificateItem/index.stories.tsx +33 -0
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCertificateItem/index.tsx +5 -8
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/CourseRunList.tsx +1 -1
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/EnrollableCourseRunList.tsx +16 -8
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/EnrolledCourseRun.tsx +5 -3
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/_styles.scss +1 -0
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/index.spec.tsx +100 -35
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseRunItem/index.spec.tsx +7 -4
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/CourseRunItem/index.stories.tsx +36 -0
- package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseRunItem/index.tsx +5 -3
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/components/ProductSignatureHeader/index.tsx +40 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.spec.tsx +898 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.stories.tsx +83 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseProductItem/index.tsx +253 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/CourseRunUnenrollmentButton/index.tsx +3 -2
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/_styles.scss +0 -25
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.joanie.spec.tsx +73 -30
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.openedx.spec.tsx +10 -5
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunEnrollment/index.tsx +54 -26
- package/js/widgets/SyllabusCourseRunsList/components/CourseRunItemWithEnrollment/index.tsx +1 -0
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/_styles.scss +0 -3
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/hooks/useCourseWish/index.spec.tsx +12 -9
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/index.login.spec.tsx +14 -12
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/index.logout.spec.tsx +4 -6
- package/js/widgets/SyllabusCourseRunsList/components/CourseWishButton/index.tsx +5 -5
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusAsideList/index.tsx +2 -2
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusCourseRun/index.tsx +19 -13
- package/js/widgets/SyllabusCourseRunsList/components/SyllabusSimpleCourseRunsList/index.tsx +1 -0
- package/js/widgets/SyllabusCourseRunsList/hooks/useCourseEnrollment/index.spec.tsx +2 -1
- package/js/widgets/SyllabusCourseRunsList/hooks/useCourseEnrollment/index.ts +14 -19
- package/js/widgets/SyllabusCourseRunsList/index.spec.tsx +54 -14
- package/js/widgets/SyllabusCourseRunsList/index.tsx +5 -8
- package/js/widgets/UserLogin/components/UserMenu/DesktopUserMenu.tsx +2 -1
- package/js/widgets/UserLogin/components/UserMenu/MobileUserMenu.tsx +2 -1
- package/js/widgets/UserLogin/components/UserMenu/index.tsx +6 -5
- package/js/widgets/UserLogin/index.not.isJoanieEnabled.spec.tsx +120 -0
- package/js/widgets/UserLogin/index.spec.tsx +108 -43
- package/js/widgets/UserLogin/index.stories.tsx +29 -0
- package/js/widgets/UserLogin/index.tsx +33 -15
- package/js/widgets/index.tsx +3 -6
- package/mocks/browser.ts +1 -1
- package/mocks/handlers/contracts.ts +16 -0
- package/mocks/handlers.ts +3 -1
- package/package.json +82 -78
- package/scss/_main.scss +2 -0
- package/scss/colors/_palette.scss +2 -2
- package/scss/colors/_theme.scss +6 -16
- package/scss/components/_content.scss +1 -1
- package/scss/components/_index.scss +24 -14
- package/scss/generic/_type.scss +1 -1
- package/scss/objects/_characteristics.scss +7 -14
- package/scss/objects/_course_glimpses.scss +3 -7
- package/scss/objects/_dashboard.scss +28 -0
- package/scss/objects/_form.scss +14 -355
- package/scss/objects/_index.scss +1 -0
- package/scss/objects/_list.scss +8 -0
- package/scss/objects/_organization_glimpses.scss +2 -8
- package/scss/objects/_selector.scss +1 -0
- package/scss/trumps/_bootstrap.scss +4 -0
- package/scss/vendors/css/cunningham-tokens.css +89 -25
- package/scss/vendors/cunningham-tokens.scss +208 -128
- package/js/components/AddressesManagement/AddressForm.spec.tsx +0 -206
- package/js/components/AddressesManagement/AddressForm.tsx +0 -169
- package/js/components/Button/index.spec.tsx +0 -36
- package/js/components/Button/index.stories.tsx +0 -26
- package/js/components/Button/index.tsx +0 -38
- package/js/components/Form/CheckboxField.stories.tsx +0 -12
- package/js/components/Form/Field.stories.config.tsx +0 -24
- package/js/components/Form/Inputs.tsx +0 -295
- package/js/components/Form/RadioField.stories.tsx +0 -18
- package/js/components/Form/SelectField.stories.tsx +0 -27
- package/js/components/Form/TextAreaField.stories.tsx +0 -12
- package/js/components/Form/TextField.stories.tsx +0 -12
- package/js/components/Form/index.spec.tsx +0 -297
- package/js/hooks/useProduct.ts +0 -28
- package/js/utils/test/mockProductWithOrder.ts +0 -17
- package/js/widgets/CourseProductItem/components/PaymentButton/_styles.scss +0 -12
- package/js/widgets/CourseProductItem/components/PaymentButton/index.spec.tsx +0 -473
- package/js/widgets/CourseProductItem/components/PurchaseButton/index.spec.tsx +0 -259
- package/js/widgets/CourseProductItem/components/SaleTunnel/_styles.scss +0 -41
- package/js/widgets/CourseProductItem/components/SaleTunnelStepResume/_styles.scss +0 -130
- package/js/widgets/CourseProductItem/components/SaleTunnelStepResume/index.spec.tsx +0 -29
- package/js/widgets/CourseProductItem/components/SaleTunnelStepResume/index.tsx +0 -59
- package/js/widgets/CourseProductItem/components/SaleTunnelStepValidation/index.spec.tsx +0 -71
- package/js/widgets/CourseProductItem/contexts/CourseProductContext/index.spec.tsx +0 -35
- package/js/widgets/CourseProductItem/contexts/CourseProductContext/index.tsx +0 -45
- package/js/widgets/CourseProductItem/index.spec.tsx +0 -486
- package/js/widgets/CourseProductItem/index.tsx +0 -205
- package/js/widgets/Dashboard/components/DashboardItem/DashboardItemCourseEnrolling.spec.tsx +0 -64
- package/js/widgets/Dashboard/components/TeacherCourseDashboardSidebar/index.spec.tsx +0 -105
- package/js/widgets/Dashboard/components/TeacherOrganizationDashboardSidebar/index.stories.tsx +0 -28
- /package/js/components/AddressesManagement/{validationSchema.spec.ts → AddressForm/validationSchema.spec.ts} +0 -0
- /package/js/{widgets/CourseProductItem/components → components}/EnrollmentDate/index.tsx +0 -0
- /package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/RegisteredCreditCard/_styles.scss +0 -0
- /package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/RegisteredCreditCard/index.spec.tsx +0 -0
- /package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/SaleTunnelStepValidation/TargetCourseDetail.tsx +0 -0
- /package/js/{widgets/CourseProductItem → components/SaleTunnel}/components/StepBreadcrumb/_styles.scss +0 -0
- /package/js/{widgets/CourseProductItem/hooks → hooks}/useStepManager/index.spec.ts +0 -0
- /package/js/{widgets/CourseProductItem/hooks → hooks}/useStepManager/index.ts +0 -0
- /package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/CourseRunListCell/index.tsx +0 -0
- /package/js/pages/{TeacherCourseDashboardLoader → TeacherDashboardCourseLoader}/CourseRunList/index.tsx +0 -0
- /package/js/pages/{TeacherTrainingDashboard → TeacherDashboardTraining}/_styles.scss +0 -0
- /package/js/widgets/Dashboard/components/{TeacherCourseDashboardSidebar → TeacherDashboardCourseSidebar}/_styles.scss +0 -0
- /package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/CourseRunSection.tsx +0 -0
- /package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/components/CourseProductCourseRuns/index.tsx +0 -0
- /package/js/widgets/{CourseProductItem → SyllabusCourseRunsList/components/CourseProductItem}/types/payments/payplug.d.ts +0 -0
|
@@ -16,7 +16,6 @@ import fetchMock from 'fetch-mock';
|
|
|
16
16
|
import userEvent from '@testing-library/user-event';
|
|
17
17
|
import { faker } from '@faker-js/faker';
|
|
18
18
|
import {
|
|
19
|
-
CourseLightFactory,
|
|
20
19
|
CourseRunFactoryFromPriority,
|
|
21
20
|
RichieContextFactory as mockRichieContextFactory,
|
|
22
21
|
UserFactory,
|
|
@@ -25,8 +24,8 @@ import SyllabusCourseRunsList from 'widgets/SyllabusCourseRunsList/index';
|
|
|
25
24
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
26
25
|
import { CourseRun, Priority } from 'types';
|
|
27
26
|
import JoanieApiProvider from 'contexts/JoanieApiContext';
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
27
|
+
import { CourseProductRelation } from 'types/Joanie';
|
|
28
|
+
import { CourseLightFactory, CourseProductRelationFactory } from 'utils/test/factories/joanie';
|
|
30
29
|
import { DEFAULT_DATE_FORMAT } from 'hooks/useDateFormat';
|
|
31
30
|
import { StringHelper } from 'utils/StringHelper';
|
|
32
31
|
import { computeStates } from 'utils/CourseRuns';
|
|
@@ -40,7 +39,7 @@ jest.mock('utils/context', () => {
|
|
|
40
39
|
mock.lms_backends = [
|
|
41
40
|
{
|
|
42
41
|
backend: 'joanie',
|
|
43
|
-
course_regexp: '^.*/api/v1.0
|
|
42
|
+
course_regexp: '^.*/api/v1.0((?:/(?:courses|course-runs|products)/[^/]+)+)/?$',
|
|
44
43
|
endpoint: 'https://joanie.test',
|
|
45
44
|
},
|
|
46
45
|
{
|
|
@@ -143,9 +142,9 @@ describe('<SyllabusCourseRunsList/>', () => {
|
|
|
143
142
|
});
|
|
144
143
|
};
|
|
145
144
|
|
|
146
|
-
const
|
|
145
|
+
const expectCourseProduct = async (container: HTMLElement, relation: CourseProductRelation) => {
|
|
147
146
|
const heading = await findByRole(container, 'heading', {
|
|
148
|
-
name: product.title,
|
|
147
|
+
name: relation.product.title,
|
|
149
148
|
});
|
|
150
149
|
expect(Array.from(heading.classList)).toContain('product-widget__title');
|
|
151
150
|
};
|
|
@@ -232,6 +231,48 @@ describe('<SyllabusCourseRunsList/>', () => {
|
|
|
232
231
|
courseRuns.slice(1).forEach((run) => expectCourseRunInList(portalContainer, run));
|
|
233
232
|
});
|
|
234
233
|
|
|
234
|
+
it('has one forever open course run', async () => {
|
|
235
|
+
const course = CourseLightFactory().one();
|
|
236
|
+
const startDate = faker.date.past();
|
|
237
|
+
const enrollmentStartDate = faker.date.past();
|
|
238
|
+
const courseRun = CourseRunFactoryFromPriority(Priority.ONGOING_OPEN)({
|
|
239
|
+
start: startDate.toISOString(),
|
|
240
|
+
end: undefined,
|
|
241
|
+
enrollment_start: enrollmentStartDate.toISOString(),
|
|
242
|
+
enrollment_end: undefined,
|
|
243
|
+
resource_link: 'https://openedx.endpoint/course-v1:edX+DemoX+Session1/info/',
|
|
244
|
+
}).one();
|
|
245
|
+
|
|
246
|
+
render(
|
|
247
|
+
<SyllabusCourseRunsList
|
|
248
|
+
courseRuns={[courseRun]}
|
|
249
|
+
course={course}
|
|
250
|
+
maxArchivedCourseRuns={MAX_ARCHIVED_COURSE_RUNS}
|
|
251
|
+
/>,
|
|
252
|
+
{
|
|
253
|
+
wrapper: Wrapper,
|
|
254
|
+
},
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
expect(getHeaderContainer().querySelectorAll('.course-detail__run-descriptions').length).toBe(
|
|
258
|
+
1,
|
|
259
|
+
);
|
|
260
|
+
getByRole(getHeaderContainer(), 'heading', {
|
|
261
|
+
name: courseRun.title,
|
|
262
|
+
});
|
|
263
|
+
// Make sure that CourseRunEnrollment is well rendered.
|
|
264
|
+
getByRole(getHeaderContainer(), 'button', { name: 'Log in to enroll' });
|
|
265
|
+
|
|
266
|
+
const intl = createIntl({ locale: 'en' });
|
|
267
|
+
getByText(
|
|
268
|
+
getHeaderContainer(),
|
|
269
|
+
'From ' + intl.formatDate(enrollmentStartDate, DEFAULT_DATE_FORMAT) + ' to ...',
|
|
270
|
+
);
|
|
271
|
+
getByText(
|
|
272
|
+
getHeaderContainer(),
|
|
273
|
+
'From ' + intl.formatDate(startDate, DEFAULT_DATE_FORMAT) + ' to ...',
|
|
274
|
+
);
|
|
275
|
+
});
|
|
235
276
|
it('has multiple opened course run', async () => {
|
|
236
277
|
const course = CourseLightFactory().one();
|
|
237
278
|
const courseRuns = [
|
|
@@ -273,14 +314,13 @@ describe('<SyllabusCourseRunsList/>', () => {
|
|
|
273
314
|
|
|
274
315
|
it('has one opened product', async () => {
|
|
275
316
|
const course = CourseLightFactory().one();
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
product,
|
|
280
|
-
);
|
|
317
|
+
const relation = CourseProductRelationFactory().one();
|
|
318
|
+
const resourceLink = `https://joanie.test/api/v1.0/courses/${course.code}/products/${relation.product.id}/`;
|
|
319
|
+
fetchMock.get(resourceLink, relation);
|
|
281
320
|
|
|
282
|
-
const courseRun = CourseRunFactoryFromPriority(Priority.ONGOING_OPEN)(
|
|
283
|
-
|
|
321
|
+
const courseRun = CourseRunFactoryFromPriority(Priority.ONGOING_OPEN)({
|
|
322
|
+
resource_link: resourceLink,
|
|
323
|
+
}).one();
|
|
284
324
|
|
|
285
325
|
render(
|
|
286
326
|
<SyllabusCourseRunsList
|
|
@@ -297,7 +337,7 @@ describe('<SyllabusCourseRunsList/>', () => {
|
|
|
297
337
|
expect(getHeaderContainer().querySelectorAll('.course-detail__run-descriptions').length).toBe(
|
|
298
338
|
1,
|
|
299
339
|
);
|
|
300
|
-
await
|
|
340
|
+
await expectCourseProduct(getHeaderContainer(), relation);
|
|
301
341
|
|
|
302
342
|
// Portal.
|
|
303
343
|
expectEmptyPortalContainer();
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from 'react';
|
|
2
2
|
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
+
import { Button } from '@openfun/cunningham-react';
|
|
4
5
|
import { CourseRun, Priority } from 'types';
|
|
5
|
-
import { Course } from 'types/Course';
|
|
6
6
|
import { computeStates } from 'utils/CourseRuns';
|
|
7
7
|
import { SyllabusAsideList } from 'widgets/SyllabusCourseRunsList/components/SyllabusAsideList';
|
|
8
8
|
import { SyllabusCourseRun } from 'widgets/SyllabusCourseRunsList/components/SyllabusCourseRun';
|
|
9
9
|
import { DjangoCMSPluginsInit } from 'components/DjangoCMSTemplate';
|
|
10
10
|
import { isJoanieEnabled } from 'api/joanie';
|
|
11
11
|
import context from 'utils/context';
|
|
12
|
+
import { CourseLight } from 'types/Joanie';
|
|
12
13
|
import CourseWishButton from './components/CourseWishButton';
|
|
13
14
|
|
|
14
15
|
const OPENED_COURSES_ELEMENT_ID = 'courseDetailsRunsOpen';
|
|
@@ -40,7 +41,7 @@ const SyllabusCourseRunsList = ({
|
|
|
40
41
|
maxArchivedCourseRuns,
|
|
41
42
|
}: {
|
|
42
43
|
courseRuns: CourseRun[];
|
|
43
|
-
course:
|
|
44
|
+
course: CourseLight;
|
|
44
45
|
maxArchivedCourseRuns: number;
|
|
45
46
|
}) => {
|
|
46
47
|
useEffect(() => {
|
|
@@ -93,13 +94,9 @@ const SyllabusCourseRunsList = ({
|
|
|
93
94
|
values={{ count: openedRuns.length }}
|
|
94
95
|
/>
|
|
95
96
|
</p>
|
|
96
|
-
<
|
|
97
|
-
className="button button--primary"
|
|
98
|
-
href={'#' + OPENED_COURSES_ELEMENT_ID}
|
|
99
|
-
onClick={choose}
|
|
100
|
-
>
|
|
97
|
+
<Button href={'#' + OPENED_COURSES_ELEMENT_ID} onClick={choose} fullWidth={true}>
|
|
101
98
|
<FormattedMessage {...messages.multipleOpenedCourseRunsButton} />
|
|
102
|
-
</
|
|
99
|
+
</Button>
|
|
103
100
|
</div>
|
|
104
101
|
)}
|
|
105
102
|
{createPortal(
|
|
@@ -2,6 +2,7 @@ import { FC } from 'react';
|
|
|
2
2
|
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
3
3
|
import { useSelect } from 'downshift';
|
|
4
4
|
import { location } from 'utils/indirection/window';
|
|
5
|
+
import { UserHelper } from 'utils/UserHelper';
|
|
5
6
|
import { UserMenuProps } from '.';
|
|
6
7
|
|
|
7
8
|
const messages = defineMessages({
|
|
@@ -41,7 +42,7 @@ export const DesktopUserMenu: FC<UserMenuProps> = ({ user }) => {
|
|
|
41
42
|
<FormattedMessage {...messages.menuPurpose} />
|
|
42
43
|
</label>
|
|
43
44
|
<button {...getToggleButtonProps()} className="selector__button">
|
|
44
|
-
{user
|
|
45
|
+
{UserHelper.getName(user)}
|
|
45
46
|
<svg role="img" className="selector__button__icon" aria-hidden="true">
|
|
46
47
|
<use xlinkHref="#icon-chevron-down" />
|
|
47
48
|
</svg>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { Icon, IconTypeEnum } from 'components/Icon';
|
|
3
|
+
import { UserHelper } from 'utils/UserHelper';
|
|
3
4
|
import { UserMenuProps } from '.';
|
|
4
5
|
|
|
5
6
|
export const MobileUserMenu: FC<UserMenuProps> = ({ user }) => (
|
|
6
7
|
<div className="user-menu user-menu--mobile">
|
|
7
8
|
<h6 className="user-menu__username">
|
|
8
9
|
<Icon name={IconTypeEnum.LOGIN} />
|
|
9
|
-
{user
|
|
10
|
+
{UserHelper.getName(user)}
|
|
10
11
|
</h6>
|
|
11
12
|
<ul className="user-menu__list">
|
|
12
13
|
{user.urls.map(({ key, label, action }) => (
|
|
@@ -4,13 +4,14 @@ import useMatchMedia from 'hooks/useMatchMedia';
|
|
|
4
4
|
import { DesktopUserMenu } from './DesktopUserMenu';
|
|
5
5
|
import { MobileUserMenu } from './MobileUserMenu';
|
|
6
6
|
|
|
7
|
+
export interface UserMenuItem {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
action: string | (() => void);
|
|
11
|
+
}
|
|
7
12
|
export interface UserMenuProps {
|
|
8
13
|
user: User & {
|
|
9
|
-
urls:
|
|
10
|
-
key: string;
|
|
11
|
-
label: string;
|
|
12
|
-
action: string | (() => void);
|
|
13
|
-
}[];
|
|
14
|
+
urls: UserMenuItem[];
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import fetchMock from 'fetch-mock';
|
|
5
|
+
import { IntlProvider } from 'react-intl';
|
|
6
|
+
import { act } from 'react-dom/test-utils';
|
|
7
|
+
import { PropsWithChildren } from 'react';
|
|
8
|
+
import {
|
|
9
|
+
RichieContextFactory as mockRichieContextFactory,
|
|
10
|
+
UserFactory,
|
|
11
|
+
} from 'utils/test/factories/richie';
|
|
12
|
+
import { Deferred } from 'utils/test/deferred';
|
|
13
|
+
import context from 'utils/context';
|
|
14
|
+
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
15
|
+
import { User } from 'types/User';
|
|
16
|
+
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
17
|
+
import { Nullable } from 'types/utils';
|
|
18
|
+
import BaseSessionProvider from 'contexts/SessionContext/BaseSessionProvider';
|
|
19
|
+
import UserLogin from '.';
|
|
20
|
+
|
|
21
|
+
jest.mock('utils/errors/handle', () => ({
|
|
22
|
+
handle: jest.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
jest.mock('utils/indirection/window', () => ({
|
|
26
|
+
matchMedia: () => ({
|
|
27
|
+
matches: true,
|
|
28
|
+
addListener: jest.fn(),
|
|
29
|
+
removeListener: jest.fn(),
|
|
30
|
+
}),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock('utils/context', () => ({
|
|
34
|
+
__esModule: true,
|
|
35
|
+
default: mockRichieContextFactory({
|
|
36
|
+
authentication: {
|
|
37
|
+
backend: 'fonzie',
|
|
38
|
+
endpoint: 'https://auth.local.test',
|
|
39
|
+
},
|
|
40
|
+
}).one(),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
describe('<UserLogin />', () => {
|
|
44
|
+
const Wrapper = ({
|
|
45
|
+
children,
|
|
46
|
+
user = false,
|
|
47
|
+
}: PropsWithChildren & { user?: Nullable<User | boolean> }) => (
|
|
48
|
+
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
49
|
+
<IntlProvider locale="en">
|
|
50
|
+
<BaseSessionProvider>{children}</BaseSessionProvider>
|
|
51
|
+
</IntlProvider>
|
|
52
|
+
</QueryClientProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
it('gets and renders the user name and a dropdown containing a logout link', async () => {
|
|
56
|
+
const user: User = UserFactory({ full_name: undefined }).one();
|
|
57
|
+
|
|
58
|
+
render(
|
|
59
|
+
<Wrapper user={user}>
|
|
60
|
+
<UserLogin context={context} />
|
|
61
|
+
</Wrapper>,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const button = await screen.findByLabelText(`Access to your profile settings`, {
|
|
65
|
+
selector: 'button',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await userEvent.click(button);
|
|
69
|
+
|
|
70
|
+
screen.getByText(user.username);
|
|
71
|
+
screen.getByText('Log out');
|
|
72
|
+
expect(screen.queryByText('Loading login status...')).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('renders signup/login buttons when the user is not logged in', async () => {
|
|
76
|
+
const loginDeferred = new Deferred();
|
|
77
|
+
fetchMock.get('https://auth.test/api/user/v1/me', loginDeferred.promise);
|
|
78
|
+
|
|
79
|
+
render(
|
|
80
|
+
<Wrapper user={null}>
|
|
81
|
+
<UserLogin context={context} />
|
|
82
|
+
</Wrapper>,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
await act(async () => {
|
|
86
|
+
loginDeferred.resolve(HttpStatusCode.UNAUTHORIZED);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(await screen.findByRole('button', { name: 'Log in' })).toBeInTheDocument();
|
|
90
|
+
expect(screen.getByRole('button', { name: 'Sign up' })).toBeInTheDocument();
|
|
91
|
+
|
|
92
|
+
expect(screen.queryByText('Loading login status...')).not.toBeInTheDocument();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should renders profile urls and bind user info if needed', async () => {
|
|
96
|
+
const user: User = UserFactory().one();
|
|
97
|
+
const profileUrls = {
|
|
98
|
+
settings: { label: 'Settings', action: 'https://auth.local.test/settings' },
|
|
99
|
+
account: { label: 'Account', action: 'https://auth.local.test/u/(username)' },
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
render(
|
|
103
|
+
<Wrapper user={user}>
|
|
104
|
+
<UserLogin context={context} profileUrls={profileUrls} />
|
|
105
|
+
</Wrapper>,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const button = await screen.findByLabelText(`Access to your profile settings`, {
|
|
109
|
+
selector: 'button',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await userEvent.click(button);
|
|
113
|
+
|
|
114
|
+
screen.getByText(user.full_name!);
|
|
115
|
+
const settingsLink = screen.getByRole('link', { name: 'Settings' });
|
|
116
|
+
const accountLink = screen.getByRole('link', { name: 'Account' });
|
|
117
|
+
expect(settingsLink.getAttribute('href')).toEqual('https://auth.local.test/settings');
|
|
118
|
+
expect(accountLink.getAttribute('href')).toEqual(`https://auth.local.test/u/${user.username}`);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -4,15 +4,19 @@ import userEvent from '@testing-library/user-event';
|
|
|
4
4
|
import fetchMock from 'fetch-mock';
|
|
5
5
|
import { IntlProvider } from 'react-intl';
|
|
6
6
|
import { act } from 'react-dom/test-utils';
|
|
7
|
+
import { PropsWithChildren } from 'react';
|
|
7
8
|
import {
|
|
8
9
|
RichieContextFactory as mockRichieContextFactory,
|
|
9
10
|
UserFactory,
|
|
10
11
|
} from 'utils/test/factories/richie';
|
|
11
12
|
import { Deferred } from 'utils/test/deferred';
|
|
12
13
|
import context from 'utils/context';
|
|
13
|
-
import { SessionProvider } from 'contexts/SessionContext';
|
|
14
14
|
import { createTestQueryClient } from 'utils/test/createTestQueryClient';
|
|
15
|
-
import { User } from 'types/User';
|
|
15
|
+
import { JoanieUserApiAbilityActions, User } from 'types/User';
|
|
16
|
+
import { HttpStatusCode } from 'utils/errors/HttpError';
|
|
17
|
+
import JoanieSessionProvider from 'contexts/SessionContext/JoanieSessionProvider';
|
|
18
|
+
import { JoanieUserProfileFactory } from 'utils/test/factories/joanie';
|
|
19
|
+
import { Nullable } from 'types/utils';
|
|
16
20
|
import UserLogin from '.';
|
|
17
21
|
|
|
18
22
|
jest.mock('utils/errors/handle', () => ({
|
|
@@ -29,10 +33,34 @@ jest.mock('utils/indirection/window', () => ({
|
|
|
29
33
|
|
|
30
34
|
jest.mock('utils/context', () => ({
|
|
31
35
|
__esModule: true,
|
|
32
|
-
default: mockRichieContextFactory(
|
|
36
|
+
default: mockRichieContextFactory({
|
|
37
|
+
authentication: {
|
|
38
|
+
backend: 'fonzie',
|
|
39
|
+
endpoint: 'https://auth.local.test',
|
|
40
|
+
},
|
|
41
|
+
joanie_backend: {
|
|
42
|
+
endpoint: 'https://endpoint.test',
|
|
43
|
+
},
|
|
44
|
+
}).one(),
|
|
33
45
|
}));
|
|
34
46
|
|
|
35
47
|
describe('<UserLogin />', () => {
|
|
48
|
+
const Wrapper = ({
|
|
49
|
+
children,
|
|
50
|
+
user = false,
|
|
51
|
+
}: PropsWithChildren & { user?: Nullable<User | boolean> }) => (
|
|
52
|
+
<QueryClientProvider client={createTestQueryClient({ user })}>
|
|
53
|
+
<IntlProvider locale="en">
|
|
54
|
+
<JoanieSessionProvider>{children}</JoanieSessionProvider>
|
|
55
|
+
</IntlProvider>
|
|
56
|
+
</QueryClientProvider>
|
|
57
|
+
);
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
fetchMock
|
|
60
|
+
.get('https://endpoint.test/api/v1.0/orders/', [])
|
|
61
|
+
.get('https://endpoint.test/api/v1.0/addresses/', [])
|
|
62
|
+
.get('https://endpoint.test/api/v1.0/credit-cards/', []);
|
|
63
|
+
});
|
|
36
64
|
afterEach(() => {
|
|
37
65
|
fetchMock.restore();
|
|
38
66
|
});
|
|
@@ -40,81 +68,118 @@ describe('<UserLogin />', () => {
|
|
|
40
68
|
it('gets and renders the user name and a dropdown containing a logout link', async () => {
|
|
41
69
|
const user: User = UserFactory().one();
|
|
42
70
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</SessionProvider>
|
|
50
|
-
</IntlProvider>
|
|
51
|
-
</QueryClientProvider>,
|
|
52
|
-
);
|
|
53
|
-
});
|
|
71
|
+
fetchMock.get('https://endpoint.test/api/v1.0/users/me/', JoanieUserProfileFactory().one());
|
|
72
|
+
render(
|
|
73
|
+
<Wrapper user={user}>
|
|
74
|
+
<UserLogin context={context} />
|
|
75
|
+
</Wrapper>,
|
|
76
|
+
);
|
|
54
77
|
|
|
55
|
-
const button = screen.
|
|
78
|
+
const button = await screen.findByLabelText(`Access to your profile settings`, {
|
|
56
79
|
selector: 'button',
|
|
57
80
|
});
|
|
58
81
|
|
|
59
82
|
await userEvent.click(button);
|
|
60
83
|
|
|
61
|
-
screen.getByText(user.
|
|
84
|
+
screen.getByText(user.full_name!);
|
|
62
85
|
screen.getByText('Log out');
|
|
63
86
|
expect(screen.queryByText('Loading login status...')).toBeNull();
|
|
64
87
|
});
|
|
65
88
|
|
|
66
89
|
it('renders signup/login buttons when the user is not logged in', async () => {
|
|
67
90
|
const loginDeferred = new Deferred();
|
|
68
|
-
fetchMock.get('https://
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
</SessionProvider>
|
|
76
|
-
</IntlProvider>
|
|
77
|
-
</QueryClientProvider>,
|
|
91
|
+
fetchMock.get('https://auth.test/api/user/v1/me', loginDeferred.promise);
|
|
92
|
+
|
|
93
|
+
fetchMock.get('https://endpoint.test/api/v1.0/users/me/', JoanieUserProfileFactory().one());
|
|
94
|
+
render(
|
|
95
|
+
<Wrapper user={null}>
|
|
96
|
+
<UserLogin context={context} />
|
|
97
|
+
</Wrapper>,
|
|
78
98
|
);
|
|
79
99
|
|
|
80
100
|
await act(async () => {
|
|
81
|
-
loginDeferred.resolve(
|
|
101
|
+
loginDeferred.resolve(HttpStatusCode.UNAUTHORIZED);
|
|
82
102
|
});
|
|
83
103
|
|
|
84
|
-
await
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
expect(await screen.findByRole('button', { name: 'Log in' })).toBeInTheDocument();
|
|
105
|
+
expect(screen.getByRole('button', { name: 'Sign up' })).toBeInTheDocument();
|
|
106
|
+
|
|
107
|
+
expect(screen.queryByText('Loading login status...')).not.toBeInTheDocument();
|
|
87
108
|
});
|
|
88
109
|
|
|
89
|
-
it('should renders profile urls and bind user info if needed', async () => {
|
|
110
|
+
it('should renders profile urls and bind user info if needed, for user without abilities', async () => {
|
|
90
111
|
const user: User = UserFactory().one();
|
|
91
112
|
const profileUrls = {
|
|
92
113
|
settings: { label: 'Settings', action: 'https://auth.local.test/settings' },
|
|
93
114
|
account: { label: 'Account', action: 'https://auth.local.test/u/(username)' },
|
|
115
|
+
dashboard_teacher: { label: 'Teacher dashboard', action: 'https://dashboard.teacher.url' },
|
|
94
116
|
};
|
|
95
117
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
fetchMock.get(
|
|
119
|
+
'https://endpoint.test/api/v1.0/users/me/',
|
|
120
|
+
JoanieUserProfileFactory({
|
|
121
|
+
abilities: {
|
|
122
|
+
[JoanieUserApiAbilityActions.HAS_ORGANIZATION_ACCESS]: false,
|
|
123
|
+
[JoanieUserApiAbilityActions.HAS_COURSE_ACCESS]: false,
|
|
124
|
+
},
|
|
125
|
+
}).one(),
|
|
126
|
+
);
|
|
127
|
+
render(
|
|
128
|
+
<Wrapper user={user}>
|
|
129
|
+
<UserLogin context={context} profileUrls={profileUrls} />
|
|
130
|
+
</Wrapper>,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const button = await screen.findByLabelText(`Access to your profile settings`, {
|
|
134
|
+
selector: 'button',
|
|
106
135
|
});
|
|
107
136
|
|
|
108
|
-
|
|
137
|
+
await userEvent.click(button);
|
|
138
|
+
|
|
139
|
+
screen.getByText(user.full_name!);
|
|
140
|
+
const settingsLink = screen.getByRole('link', { name: 'Settings' });
|
|
141
|
+
const accountLink = screen.getByRole('link', { name: 'Account' });
|
|
142
|
+
expect(settingsLink.getAttribute('href')).toEqual('https://auth.local.test/settings');
|
|
143
|
+
expect(accountLink.getAttribute('href')).toEqual(`https://auth.local.test/u/${user.username}`);
|
|
144
|
+
expect(screen.queryByRole('link', { name: 'Teacher dashboard' })).not.toBeInTheDocument();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should renders teacher dashboard menu item for user with organization access', async () => {
|
|
148
|
+
const user: User = UserFactory().one();
|
|
149
|
+
const profileUrls = {
|
|
150
|
+
settings: { label: 'Settings', action: 'https://auth.local.test/settings' },
|
|
151
|
+
account: { label: 'Account', action: 'https://auth.local.test/u/(username)' },
|
|
152
|
+
dashboard_teacher: { label: 'Teacher dashboard', action: 'https://dashboard.teacher.url' },
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
fetchMock.get(
|
|
156
|
+
'https://endpoint.test/api/v1.0/users/me/',
|
|
157
|
+
JoanieUserProfileFactory({
|
|
158
|
+
abilities: {
|
|
159
|
+
[JoanieUserApiAbilityActions.HAS_ORGANIZATION_ACCESS]: true,
|
|
160
|
+
},
|
|
161
|
+
}).one(),
|
|
162
|
+
);
|
|
163
|
+
render(
|
|
164
|
+
<Wrapper user={user}>
|
|
165
|
+
<UserLogin context={context} profileUrls={profileUrls} />
|
|
166
|
+
</Wrapper>,
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const button = await screen.findByLabelText(`Access to your profile settings`, {
|
|
109
170
|
selector: 'button',
|
|
110
171
|
});
|
|
111
172
|
|
|
112
173
|
await userEvent.click(button);
|
|
113
174
|
|
|
114
|
-
screen.getByText(user.
|
|
175
|
+
screen.getByText(user.full_name!);
|
|
115
176
|
const settingsLink = screen.getByRole('link', { name: 'Settings' });
|
|
116
177
|
const accountLink = screen.getByRole('link', { name: 'Account' });
|
|
117
178
|
expect(settingsLink.getAttribute('href')).toEqual('https://auth.local.test/settings');
|
|
118
179
|
expect(accountLink.getAttribute('href')).toEqual(`https://auth.local.test/u/${user.username}`);
|
|
180
|
+
|
|
181
|
+
const teacherDashboardLink = screen.getByRole('link', { name: 'Teacher dashboard' });
|
|
182
|
+
expect(teacherDashboardLink).toBeInTheDocument();
|
|
183
|
+
expect(teacherDashboardLink.getAttribute('href')).toEqual('https://dashboard.teacher.url');
|
|
119
184
|
});
|
|
120
185
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { StorybookHelper } from 'utils/StorybookHelper';
|
|
3
|
+
import { RichieContextFactory } from 'utils/test/factories/richie';
|
|
4
|
+
import UserLogin from '.';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
component: UserLogin,
|
|
8
|
+
parameters: {
|
|
9
|
+
docs: {
|
|
10
|
+
source: {
|
|
11
|
+
code: 'Disabled for this story, see https://github.com/storybookjs/storybook/issues/11554',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
context: RichieContextFactory().one(),
|
|
17
|
+
profileUrls: {
|
|
18
|
+
first_entry: { action: () => {}, label: 'First entry' },
|
|
19
|
+
second_entry: { action: () => {}, label: 'Second entry' },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
render: (args) => {
|
|
23
|
+
return StorybookHelper.wrapInApp(<UserLogin {...args} />);
|
|
24
|
+
},
|
|
25
|
+
} as Meta<typeof UserLogin>;
|
|
26
|
+
|
|
27
|
+
type Story = StoryObj<typeof UserLogin>;
|
|
28
|
+
|
|
29
|
+
export const Default: Story = {};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-nested-ternary */
|
|
2
|
-
import { Fragment } from 'react';
|
|
2
|
+
import { Fragment, useMemo } from 'react';
|
|
3
3
|
import { defineMessages, FormattedMessage, MessageDescriptor, useIntl } from 'react-intl';
|
|
4
4
|
|
|
5
5
|
import { Spinner } from 'components/Spinner';
|
|
6
6
|
import { Icon, IconTypeEnum } from 'components/Icon';
|
|
7
7
|
import { useSession } from 'contexts/SessionContext';
|
|
8
8
|
import { CommonDataProps } from 'types/commonDataProps';
|
|
9
|
-
import {
|
|
9
|
+
import { abilityActions } from 'utils/AbilitiesHelper';
|
|
10
|
+
import { useJoanieUserAbilities } from 'hooks/useJoanieUserAbilities';
|
|
11
|
+
import { UserMenu, UserMenuItem } from './components/UserMenu';
|
|
10
12
|
|
|
11
13
|
const messages: { [key: string]: MessageDescriptor } = defineMessages({
|
|
12
14
|
logIn: {
|
|
@@ -73,6 +75,34 @@ const UserLogin = ({ profileUrls = {} }: UserLoginProps) => {
|
|
|
73
75
|
*/
|
|
74
76
|
const { user, destroy, login, register } = useSession();
|
|
75
77
|
const intl = useIntl();
|
|
78
|
+
const joanieUserAbilities = useJoanieUserAbilities();
|
|
79
|
+
|
|
80
|
+
const unauthorizedUrlFilter = (urlItem: UserMenuItem) => {
|
|
81
|
+
if (urlItem.key === 'dashboard_teacher') {
|
|
82
|
+
return !!joanieUserAbilities?.can(abilityActions.ACCESS_TEACHER_DASHBOARD);
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const userMenuItems = useMemo(() => {
|
|
88
|
+
if (user) {
|
|
89
|
+
return [
|
|
90
|
+
...Object.entries(profileUrls)
|
|
91
|
+
.map(([key, { label, action }]) => ({
|
|
92
|
+
key,
|
|
93
|
+
label,
|
|
94
|
+
action: typeof action === 'string' ? bindUserDataToUrl(action, user) : action,
|
|
95
|
+
}))
|
|
96
|
+
.filter(unauthorizedUrlFilter),
|
|
97
|
+
{
|
|
98
|
+
key: 'logout',
|
|
99
|
+
label: intl.formatMessage(messages.logOut),
|
|
100
|
+
action: destroy,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
return [];
|
|
105
|
+
}, [user, joanieUserAbilities]);
|
|
76
106
|
|
|
77
107
|
return (
|
|
78
108
|
<div className="user-login">
|
|
@@ -92,21 +122,9 @@ const UserLogin = ({ profileUrls = {} }: UserLoginProps) => {
|
|
|
92
122
|
</Fragment>
|
|
93
123
|
) : (
|
|
94
124
|
<UserMenu
|
|
95
|
-
// If user's fullname is empty, we use its username as a fallback
|
|
96
125
|
user={{
|
|
97
126
|
...user,
|
|
98
|
-
urls:
|
|
99
|
-
...Object.entries(profileUrls).map(([key, { label, action }]) => ({
|
|
100
|
-
key,
|
|
101
|
-
label,
|
|
102
|
-
action: typeof action === 'string' ? bindUserDataToUrl(action, user) : action,
|
|
103
|
-
})),
|
|
104
|
-
{
|
|
105
|
-
key: 'logout',
|
|
106
|
-
label: intl.formatMessage(messages.logOut),
|
|
107
|
-
action: destroy,
|
|
108
|
-
},
|
|
109
|
-
],
|
|
127
|
+
urls: userMenuItems,
|
|
110
128
|
}}
|
|
111
129
|
/>
|
|
112
130
|
)}
|