diff --git a/src/components/course/SubsidyRequestButton.jsx b/src/components/course/SubsidyRequestButton.jsx index 1ee2fa3709..27e01b5fea 100644 --- a/src/components/course/SubsidyRequestButton.jsx +++ b/src/components/course/SubsidyRequestButton.jsx @@ -38,13 +38,10 @@ const SubsidyRequestButton = () => { const { data: enterpriseCustomer } = useEnterpriseCustomer(); const { data: browseAndRequestConfiguration } = useBrowseAndRequestConfiguration(); const { userSubsidyApplicableToCourse } = useUserSubsidyApplicableToCourse(); - const subsidyRequestCatalogsApplicableToCourse = useBrowseAndRequestCatalogsApplicableToCourse(); const { data: courseMetadata } = useCourseMetadata(); - const { - data: { - enterpriseCourseEnrollments: userEnrollments, - }, - } = useEnterpriseCourseEnrollments(); + const { data: { enterpriseCourseEnrollments: userEnrollments } } = useEnterpriseCourseEnrollments(); + const userHasSubsidyRequest = useUserHasSubsidyRequestForCourse(courseMetadata.key); + const subsidyRequestCatalogsApplicableToCourse = useBrowseAndRequestCatalogsApplicableToCourse(); /** * Check every course run to see if user is enrolled in any of them @@ -62,8 +59,6 @@ const SubsidyRequestButton = () => { [courseMetadata.courseRunKeys, userEnrollments], ); - const userHasSubsidyRequest = useUserHasSubsidyRequestForCourse(courseMetadata.key); - const requestSubsidy = useCallback(async (key) => { switch (browseAndRequestConfiguration.subsidyType) { case SUBSIDY_TYPE.LICENSE: diff --git a/src/components/course/enrollment/tests/EnrollAction.test.jsx b/src/components/course/enrollment/tests/EnrollAction.test.jsx index 8eecaeb853..480f5f422b 100644 --- a/src/components/course/enrollment/tests/EnrollAction.test.jsx +++ b/src/components/course/enrollment/tests/EnrollAction.test.jsx @@ -193,12 +193,7 @@ describe('scenarios user not yet enrolled, but eligible to enroll', () => { courseRunPrice={100} /> ); - // this initialUserSubsidyState is passed as a value to the UserSubsidyContext.provider - // which is then used by a hook to check if the user has a license - renderEnrollAction({ - enrollAction, - }); - + renderEnrollAction({ enrollAction }); expect(screen.getByText('')); }); }); diff --git a/src/components/course/routes/ExternalCourseEnrollmentConfirmation.jsx b/src/components/course/routes/ExternalCourseEnrollmentConfirmation.jsx index 0344d6ecda..6706269e37 100644 --- a/src/components/course/routes/ExternalCourseEnrollmentConfirmation.jsx +++ b/src/components/course/routes/ExternalCourseEnrollmentConfirmation.jsx @@ -4,7 +4,7 @@ import { } from '@openedx/paragon'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; -import { useExternalEnrollmentFailureReason } from '../data/hooks'; +import { useExternalEnrollmentFailureReason } from '../data'; import CourseSummaryCard from '../../executive-education-2u/components/CourseSummaryCard'; import EnrollmentCompletedSummaryCard from '../../executive-education-2u/components/EnrollmentCompletedSummaryCard'; import ErrorPageContent from '../../executive-education-2u/components/ErrorPageContent'; diff --git a/src/components/course/routes/tests/ExternalCourseEnrollmentConfirmation.test.jsx b/src/components/course/routes/tests/ExternalCourseEnrollmentConfirmation.test.jsx index ef1dcec3b3..9eabb8b626 100644 --- a/src/components/course/routes/tests/ExternalCourseEnrollmentConfirmation.test.jsx +++ b/src/components/course/routes/tests/ExternalCourseEnrollmentConfirmation.test.jsx @@ -1,38 +1,18 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import { IntlProvider } from '@edx/frontend-platform/i18n'; +import { getConfig } from '@edx/frontend-platform'; import ExternalCourseEnrollmentConfirmation from '../ExternalCourseEnrollmentConfirmation'; -import { CourseContext } from '../../CourseContextProvider'; -import { DISABLED_ENROLL_REASON_TYPES, LEARNER_CREDIT_SUBSIDY_TYPE } from '../../data/constants'; -import { UserSubsidyContext } from '../../../enterprise-user-subsidy'; -import { emptyRedeemableLearnerCreditPolicies, useEnterpriseCustomer } from '../../../app/data'; +import { DISABLED_ENROLL_REASON_TYPES } from '../../data/constants'; +import { useExternalEnrollmentFailureReason, useMinimalCourseMetadata } from '../../data'; +import { renderWithRouterProvider } from '../../../../utils/tests'; +import { useEnterpriseCustomer } from '../../../app/data'; import { enterpriseCustomerFactory } from '../../../app/data/services/data/__factories__'; -jest.mock('@edx/frontend-platform/config', () => ({ - ...jest.requireActual('@edx/frontend-platform/config'), - getConfig: jest.fn().mockReturnValue({ - GETSMARTER_LEARNER_DASHBOARD_URL: 'https://test.org/dashboard', - GETSMARTER_STUDENT_TC_URL: 'https://test.org/terms', - }), -})); - -jest.mock('../../data/hooks', () => ({ - ...jest.requireActual('../../data/hooks'), - useMinimalCourseMetadata: () => ({ - organization: { - logoImgUrl: 'https://test.org/logo.png', - name: 'Test Org', - marketingUrl: 'https://test.org', - }, - title: 'Test Course Title', - startDate: '2023-03-05', - duration: '3 Weeks', - priceDetails: { - price: 100, - currency: 'USD', - }, - }), +jest.mock('@edx/frontend-platform', () => ({ + ...jest.requireActual('@edx/frontend-platform'), + getConfig: jest.fn(), })); jest.mock('../../../app/data', () => ({ @@ -40,53 +20,56 @@ jest.mock('../../../app/data', () => ({ useEnterpriseCustomer: jest.fn(), })); -const baseCourseContextValue = { - state: { - courseEntitlementProductSku: 'test-sku', - activeCourseRun: { - weeksToComplete: 8, - }, - course: { - organizationShortCodeOverride: 'Test Org', - organizationLogoOverrideUrl: 'https://test.org/logo.png', - }, - }, - userSubsidyApplicableToCourse: { subsidyType: LEARNER_CREDIT_SUBSIDY_TYPE }, - missingUserSubsidyReason: undefined, -}; - -const mockEnterpriseCustomer = enterpriseCustomerFactory(); - -const baseUserSubsidyContextValue = { - subscriptionLicense: null, - couponCodes: { - couponCodes: [{ discountValue: 90 }], - couponCodesCount: 0, - }, - redeemableLearnerCreditPolicies: emptyRedeemableLearnerCreditPolicies, -}; +jest.mock('../../data', () => ({ + ...jest.requireActual('../../data'), + useExternalEnrollmentFailureReason: jest.fn(), + useMinimalCourseMetadata: jest.fn(), +})); -const ExternalCourseEnrollmentConfirmationWrapper = ({ - courseContextValue = baseCourseContextValue, - initialUserSubsidyState = baseUserSubsidyContextValue, -}) => ( +const ExternalCourseEnrollmentConfirmationWrapper = () => ( - - - - - + ); -describe('ExternalCourseEnrollment', () => { +const mockEnterpriseCustomer = enterpriseCustomerFactory(); + +describe('ExternalCourseEnrollmentConfirmation', () => { beforeEach(() => { jest.clearAllMocks(); + getConfig.mockReturnValue({ + GETSMARTER_STUDENT_TC_URL: 'https://example.com/terms', + }); useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer }); + useExternalEnrollmentFailureReason.mockReturnValue({ + failureReason: undefined, + failureMessage: undefined, + }); + useMinimalCourseMetadata.mockReturnValue({ + data: { + title: 'Test Course Title', + organization: { + name: 'Test Org', + marketingUrl: 'https://example.com', + logoImgUrl: 'https://example.com/logo.png', + }, + priceDetails: { + price: 100, + currency: 'USD', + }, + startDate: '2023-03-05T12:00:00Z', + duration: '3 Weeks', + }, + }); }); it('renders', () => { - render(); + renderWithRouterProvider({ + path: '/:enterpriseSlug', + element: , + }, { + initialEntries: ['/test-enterprise'], + }); expect(screen.getByText('Congratulations, you have completed your enrollment for your online course')).toBeInTheDocument(); expect(screen.getByText('Test Course Title')).toBeInTheDocument(); expect(screen.getByText('Test Org')).toBeInTheDocument(); @@ -102,37 +85,20 @@ describe('ExternalCourseEnrollment', () => { }); it('handles failure reason', () => { - const courseContextValue = { - ...baseCourseContextValue, - userSubsidyApplicableToCourse: undefined, - missingUserSubsidyReason: { reason: DISABLED_ENROLL_REASON_TYPES.NO_SUBSIDY_NO_ADMINS }, - }; - render(); + useExternalEnrollmentFailureReason.mockReturnValue({ + failureReason: DISABLED_ENROLL_REASON_TYPES.NO_SUBSIDY_NO_ADMINS, + failureMessage: 'No learner credit is available to cover this course.', + }); + renderWithRouterProvider({ + path: '/:enterpriseSlug', + element: , + }, { + initialEntries: ['/test-enterprise'], + }); expect(screen.queryByText('Congratulations, you have completed your enrollment for your online course')).not.toBeInTheDocument(); expect(screen.queryByText('Test Course Title')).not.toBeInTheDocument(); expect(screen.getByText("We're sorry.")).toBeInTheDocument(); expect(screen.getByText('Something went wrong.')).toBeInTheDocument(); expect(screen.getByText('No learner credit is available to cover this course.')); }); - - it('handles successful prior redemption', () => { - const courseContextValue = { - ...baseCourseContextValue, - userSubsidyApplicableToCourse: undefined, - hasSuccessfulRedemption: true, - missingUserSubsidyReason: { reason: DISABLED_ENROLL_REASON_TYPES.NO_SUBSIDY_NO_ADMINS }, - }; - render(); - expect(screen.getByText('Congratulations, you have completed your enrollment for your online course')).toBeInTheDocument(); - expect(screen.getByText('Test Course Title')).toBeInTheDocument(); - expect(screen.getByText('Test Org')).toBeInTheDocument(); - expect(screen.getByText('Start date:')).toBeInTheDocument(); - expect(screen.getByText('Mar 5, 2023')).toBeInTheDocument(); - expect(screen.getByText('Course duration:')).toBeInTheDocument(); - expect(screen.getByText('3 Weeks')).toBeInTheDocument(); - expect(screen.getByText('Course total:')).toBeInTheDocument(); - expect(screen.getByText('$100.00 USD')).toBeInTheDocument(); - expect(screen.getByText('What happens next?')).toBeInTheDocument(); - expect(screen.getByText('Terms and Conditions')).toBeInTheDocument(); - }); }); diff --git a/src/components/course/tests/SubsidyRequestButton.test.jsx b/src/components/course/tests/SubsidyRequestButton.test.jsx index 796d15e0a2..92a73db2ea 100644 --- a/src/components/course/tests/SubsidyRequestButton.test.jsx +++ b/src/components/course/tests/SubsidyRequestButton.test.jsx @@ -1,20 +1,52 @@ import React from 'react'; -import { - screen, render, waitFor, -} from '@testing-library/react'; +import { screen, render, waitFor } from '@testing-library/react'; +import { useQueryClient } from '@tanstack/react-query'; import '@testing-library/jest-dom/extend-expect'; import userEvent from '@testing-library/user-event'; import { IntlProvider } from '@edx/frontend-platform/i18n'; import { ToastsContext } from '../../Toasts/ToastsProvider'; -import { SubsidyRequestsContext } from '../../enterprise-subsidy-requests'; import SubsidyRequestButton from '../SubsidyRequestButton'; -import { CourseContext } from '../CourseContextProvider'; import * as entepriseAccessService from '../../enterprise-subsidy-requests/data/service'; import { SUBSIDY_REQUEST_STATE, SUBSIDY_TYPE } from '../../../constants'; +import { enterpriseCustomerFactory } from '../../app/data/services/data/__factories__'; +import { + queryRequestsContextQueryKey, + useBrowseAndRequestConfiguration, + useCourseMetadata, + useEnterpriseCourseEnrollments, + useEnterpriseCustomer, +} from '../../app/data'; +import { + useBrowseAndRequestCatalogsApplicableToCourse, + useUserSubsidyApplicableToCourse, + useUserHasSubsidyRequestForCourse, +} from '../data/hooks'; jest.mock('../../enterprise-subsidy-requests/data/service'); -const mockEnterpriseUUID = 'uuid'; +const mockInvalidateQueries = jest.fn(); +jest.mock('@tanstack/react-query', () => ({ + useQueryClient: jest.fn(), +})); +useQueryClient.mockReturnValue({ + invalidateQueries: mockInvalidateQueries, +}); + +jest.mock('../../app/data', () => ({ + ...jest.requireActual('../../app/data'), + useEnterpriseCustomer: jest.fn(), + useBrowseAndRequestConfiguration: jest.fn(), + useCourseMetadata: jest.fn(), + useEnterpriseCourseEnrollments: jest.fn(), +})); +jest.mock('../data/hooks', () => ({ + ...jest.requireActual('../data/hooks'), + useUserSubsidyApplicableToCourse: jest.fn(), + useBrowseAndRequestCatalogsApplicableToCourse: jest.fn(), + useUserHasSubsidyRequestForCourse: jest.fn(), +})); + +const mockEnterpriseCustomer = enterpriseCustomerFactory(); const mockCourseKey = 'edx+101'; const mockCourseRunKey = `${mockCourseKey}+v1`; @@ -26,12 +58,17 @@ const initialToastsState = { removeToast: jest.fn(), }; +const mockSubsidyRequestConfiguration = { + subsidyRequestsEnabled: true, + enterpriseCustomerUuid: mockEnterpriseCustomer.uuid, + subsidyType: SUBSIDY_TYPE.COUPON, +}; +const mockCourseMetadata = { + key: mockCourseKey, + courseRunKeys: [mockCourseRunKey], +}; + const initialSubsidyRequestsState = { - subsidyRequestConfiguration: { - subsidyRequestsEnabled: true, - enterpriseCustomerUuid: mockEnterpriseUUID, - subsidyType: SUBSIDY_TYPE.COUPON, - }, requestsBySubsidyType: { [SUBSIDY_TYPE.LICENSE]: [], [SUBSIDY_TYPE.COUPON]: [], @@ -41,38 +78,26 @@ const initialSubsidyRequestsState = { }; const TEST_CATALOG_UUID = 'test-catalog-uuid'; -const courseState = { - course: { - key: mockCourseKey, - courseRunKeys: [mockCourseRunKey], - }, - catalog: { containsContentItems: true, catalogList: [TEST_CATALOG_UUID] }, - userEnrollments: [], -}; - -const defaultCourseContextValue = { - state: courseState, - userSubsidyApplicableToCourse: undefined, - subsidyRequestCatalogsApplicableToCourse: new Set([TEST_CATALOG_UUID]), -}; -const SubsidyRequestButtonWrapper = ({ - subsidyRequestsState = {}, - courseContextValue = defaultCourseContextValue, -}) => ( +const SubsidyRequestButtonWrapper = () => ( - - - - - + ); describe('', () => { - afterEach(() => jest.clearAllMocks()); + beforeEach(() => { + jest.clearAllMocks(); + useEnterpriseCustomer.mockReturnValue({ data: mockEnterpriseCustomer }); + useBrowseAndRequestConfiguration.mockReturnValue({ data: mockSubsidyRequestConfiguration }); + useUserSubsidyApplicableToCourse.mockReturnValue({ userSubsidyApplicableToCourse: undefined }); + useCourseMetadata.mockReturnValue({ data: mockCourseMetadata }); + useEnterpriseCourseEnrollments.mockReturnValue({ data: { enterpriseCourseEnrollments: [] } }); + useBrowseAndRequestCatalogsApplicableToCourse.mockReturnValue([TEST_CATALOG_UUID]); + useUserHasSubsidyRequestForCourse.mockReturnValue(false); + }); it('should render button', () => { render(); @@ -80,67 +105,45 @@ describe('', () => { }); it('should not render button if subsidy requests is not enabled', () => { - render( - , - ); + useBrowseAndRequestConfiguration.mockReturnValue({ + data: { + ...mockSubsidyRequestConfiguration, + subsidyRequestsEnabled: false, + }, + }); + render(); expect(screen.queryByText('Request enrollment')).not.toBeInTheDocument(); }); it('should not render button if course is not applicable to catalogs for configured subsidy request type', () => { - render( - , - ); + useBrowseAndRequestCatalogsApplicableToCourse.mockReturnValue([]); + render(); expect(screen.queryByText('Request enrollment')).not.toBeInTheDocument(); }); it('should not render button if the user is already enrolled in the course', () => { - render( - , - ); + useEnterpriseCourseEnrollments.mockReturnValue({ + data: { + enterpriseCourseEnrollments: [{ + isEnrollmentActive: true, + isRevoked: false, + courseRunId: mockCourseRunKey, + }], + }, + }); + render(); expect(screen.queryByText('Request enrollment')).not.toBeInTheDocument(); }); it('should not render button if the user has an applicable subsidy', () => { - render( - , - ); + useUserSubsidyApplicableToCourse.mockReturnValue({ userSubsidyApplicableToCourse: { discount: 100 } }); + render(); expect(screen.queryByText('Request enrollment')).not.toBeInTheDocument(); }); it('should render button if the user has an applicable subsidy BUT also a subsidy request for the course', () => { + useUserSubsidyApplicableToCourse.mockReturnValue({ userSubsidyApplicableToCourse: { discount: 100 } }); + useUserHasSubsidyRequestForCourse.mockReturnValue(true); render( ', () => { }], }, }} - contextContextValue={{ - ...defaultCourseContextValue, - userSubsidyApplicableToCourse: { - discount: 100, - }, - }} />, ); expect(screen.queryByText('Request enrollment')).not.toBeInTheDocument(); expect(screen.getByText('Awaiting approval')).toBeInTheDocument(); }); - it.each( - [{ + it.each([ + { subsidyType: SUBSIDY_TYPE.LICENSE, expectedCalledFn: entepriseAccessService.postLicenseRequest, }, @@ -173,32 +170,28 @@ describe('', () => { subsidyType: SUBSIDY_TYPE.COUPON, expectedCalledFn: entepriseAccessService.postCouponCodeRequest, }, - ], - )('should call enterprise access to create a subsidy request when clicked', async ( - { - subsidyType, expectedCalledFn, - }, - ) => { - render( - , - ); + ])('should call enterprise access to create a subsidy request when clicked', async ({ + subsidyType, + expectedCalledFn, + }) => { + useBrowseAndRequestConfiguration.mockReturnValue({ + data: { + ...mockSubsidyRequestConfiguration, + subsidyType, + }, + }); + render(); const requestEnrollmentBtn = screen.getByText('Request enrollment'); userEvent.click(requestEnrollmentBtn); await waitFor(() => { - expect( - expectedCalledFn, - ).toHaveBeenCalledWith(mockEnterpriseUUID, mockCourseKey); + expect(expectedCalledFn).toHaveBeenCalledWith(mockEnterpriseCustomer.uuid, mockCourseKey); expect(mockAddToast).toHaveBeenCalledWith('Request for course submitted'); - expect(mockRefreshSubsidyRequests).toHaveBeenCalled(); + expect(mockInvalidateQueries).toHaveBeenCalledTimes(1); + }); + const expectedQueryKey = queryRequestsContextQueryKey(mockEnterpriseCustomer.uuid); + expect(mockInvalidateQueries).toHaveBeenCalledWith({ + queryKey: expectedQueryKey, }); }); }); diff --git a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/AssignedCourseCard.test.jsx b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/AssignedCourseCard.test.jsx index 46069c0b2a..991b06196c 100644 --- a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/AssignedCourseCard.test.jsx +++ b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/AssignedCourseCard.test.jsx @@ -3,14 +3,8 @@ import { screen } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import AssignedCourseCard from '../AssignedCourseCard'; -import { UserSubsidyContext } from '../../../../../enterprise-user-subsidy'; import { renderWithRouter } from '../../../../../../utils/tests'; -jest.mock('@edx/frontend-enterprise-utils', () => ({ - ...jest.requireActual('@edx/frontend-enterprise-utils'), - sendEnterpriseTrackEvent: jest.fn(), -})); - jest.mock('../../../../../app/data', () => ({ ...jest.requireActual('../../../../../app/data'), useEnterpriseCustomer: jest.fn().mockReturnValue({ data: { uuid: 123 } }), @@ -26,33 +20,9 @@ const basicProps = { mode: 'executive-education', }; -const initialUserSubsidyContextValue = { - couponCodes: { - couponCodes: [], - }, -}; -const AssignedCourseCardWrapper = ({ - userSubsidyContextValue = initialUserSubsidyContextValue, - ...rest -}) => ( - - - -); - describe('', () => { it('should render enroll button and other related content', () => { - renderWithRouter(); - + renderWithRouter(); expect(screen.getByText('Assigned')).toBeInTheDocument(); expect(screen.getByText('Enroll')).toBeInTheDocument(); }); diff --git a/src/components/enterprise-subsidy-requests/SubsidyRequestsContextProvider.jsx b/src/components/enterprise-subsidy-requests/SubsidyRequestsContextProvider.jsx deleted file mode 100644 index 9de28dfd53..0000000000 --- a/src/components/enterprise-subsidy-requests/SubsidyRequestsContextProvider.jsx +++ /dev/null @@ -1,75 +0,0 @@ -import React, { createContext, useMemo } from 'react'; -import PropTypes from 'prop-types'; -import { Container } from '@openedx/paragon'; -import { - useSubsidyRequestConfiguration, - useSubsidyRequests, - useCatalogsForSubsidyRequests, -} from './data'; -import { LoadingSpinner } from '../loading-spinner'; -import { LOADING_SCREEN_READER_TEXT, SUBSIDY_TYPE } from '../../constants'; -import { - useEnterpriseCustomer, -} from '../app/data'; - -export const SubsidyRequestsContext = createContext(); - -const SubsidyRequestsContextProvider = ({ children }) => { - const { data: enterpriseCustomer } = useEnterpriseCustomer(); - - const { - subsidyRequestConfiguration, - isLoading: isLoadingSubsidyRequestConfiguration, - } = useSubsidyRequestConfiguration(enterpriseCustomer.uuid); - - const { - couponCodeRequests, - licenseRequests, - refreshSubsidyRequests, - isLoading: isLoadingSubsidyRequests, - } = useSubsidyRequests(subsidyRequestConfiguration); - - const { - catalogs: catalogsForSubsidyRequests, - } = useCatalogsForSubsidyRequests(); - - const isLoading = isLoadingSubsidyRequestConfiguration - || isLoadingSubsidyRequests; - - const requestsBySubsidyType = useMemo(() => ({ - [SUBSIDY_TYPE.LICENSE]: licenseRequests, - [SUBSIDY_TYPE.COUPON]: couponCodeRequests, - }), [licenseRequests, couponCodeRequests]); - - const context = useMemo(() => ({ - subsidyRequestConfiguration, - requestsBySubsidyType, - refreshSubsidyRequests, - catalogsForSubsidyRequests, - }), [ - subsidyRequestConfiguration, - requestsBySubsidyType, - refreshSubsidyRequests, - catalogsForSubsidyRequests, - ]); - - if (isLoading) { - return ( - - - - ); - } - - return ( - - {children} - - ); -}; - -SubsidyRequestsContextProvider.propTypes = { - children: PropTypes.node.isRequired, -}; - -export default SubsidyRequestsContextProvider; diff --git a/src/components/enterprise-subsidy-requests/index.js b/src/components/enterprise-subsidy-requests/index.js index 67831b3090..c94f80f843 100644 --- a/src/components/enterprise-subsidy-requests/index.js +++ b/src/components/enterprise-subsidy-requests/index.js @@ -1,2 +1 @@ -export { default as SubsidyRequestsContextProvider, SubsidyRequestsContext } from './SubsidyRequestsContextProvider'; export * from './constants'; diff --git a/src/components/enterprise-subsidy-requests/tests/SubsidyRequestsContextProvider.test.jsx b/src/components/enterprise-subsidy-requests/tests/SubsidyRequestsContextProvider.test.jsx deleted file mode 100644 index a36331e0b8..0000000000 --- a/src/components/enterprise-subsidy-requests/tests/SubsidyRequestsContextProvider.test.jsx +++ /dev/null @@ -1,87 +0,0 @@ -import React from 'react'; - -import { screen, render } from '@testing-library/react'; -import SubsidyRequestsContextProvider from '../SubsidyRequestsContextProvider'; -import { UserSubsidyContext } from '../../enterprise-user-subsidy'; -import { LOADING_SCREEN_READER_TEXT } from '../../../constants'; -import { useEnterpriseCustomer } from '../../app/data'; -import { - useCatalogsForSubsidyRequests, - useSubsidyRequestConfiguration, - useSubsidyRequests, -} from '../data'; - -jest.mock('../../../config'); -jest.mock('../data', () => ({ - ...jest.requireActual('../data'), - useSubsidyRequestConfiguration: jest.fn(), - useSubsidyRequests: jest.fn(), - useCatalogsForSubsidyRequests: jest.fn(), -})); - -jest.mock('../../app/data', () => ({ - ...jest.requireActual('../../app/data'), - useEnterpriseCustomer: jest.fn(), -})); - -const SubsidyRequestsContextProviderWrapper = ({ - initialUserSubsidyState = { - couponCodes: { - couponCodes: [], - couponCodesCount: 0, - couponsOverview: { data: undefined }, - }, - customerAgreementConfig: { - subscriptions: [], - }, - }, -}) => ( - - -
children
-
-
-); - -describe('', () => { - beforeEach(() => { - jest.clearAllMocks(); - useEnterpriseCustomer.mockReturnValue({ data: { uuid: 'test-enterprise-uuid' } }); - useSubsidyRequestConfiguration.mockReturnValue({ - subsidyRequestConfiguration: {}, - isLoading: false, - }); - useSubsidyRequests.mockReturnValue({ - couponCodeRequests: [], - licenseRequests: [], - isLoading: false, - }); - useCatalogsForSubsidyRequests.mockReturnValue({ - catalogs: [], - isLoading: false, - }); - }); - - it('should fetch subsidy requests information if feature is enabled', () => { - render(); - - expect(useSubsidyRequestConfiguration).toHaveBeenCalled(); - expect(useSubsidyRequests).toHaveBeenCalled(); - expect(useCatalogsForSubsidyRequests).toHaveBeenCalled(); - }); - - it('should render loading spinner if loading subsidy requests information', () => { - useSubsidyRequestConfiguration.mockReturnValue({ - subsidyRequestConfiguration: {}, - isLoading: true, - }); - useSubsidyRequests.mockReturnValue({ - couponCodeRequests: [], - licenseRequests: [], - isLoading: false, - }); - - render(); - expect(screen.getByText(LOADING_SCREEN_READER_TEXT)); - }); -}); diff --git a/src/components/executive-education-2u/components/CourseSummaryCard.jsx b/src/components/executive-education-2u/components/CourseSummaryCard.jsx index ccf5377e85..075b864a88 100644 --- a/src/components/executive-education-2u/components/CourseSummaryCard.jsx +++ b/src/components/executive-education-2u/components/CourseSummaryCard.jsx @@ -1,14 +1,16 @@ -import React from 'react'; import PropTypes from 'prop-types'; import dayjs from 'dayjs'; import { Card, Image, Row, Col, Hyperlink, } from '@openedx/paragon'; - import { FormattedMessage } from '@edx/frontend-platform/i18n'; -import { numberWithPrecision } from '../../course/data/utils'; -import { DATE_FORMAT, ZERO_PRICE } from '../../course/data/constants'; -import { useMinimalCourseMetadata } from '../../course/data/hooks'; + +import { + useMinimalCourseMetadata, + DATE_FORMAT, + ZERO_PRICE, + numberWithPrecision, +} from '../../course/data'; const CourseSummaryCard = ({ enrollmentCompleted }) => { const { data: minimalCourseMetadata } = useMinimalCourseMetadata(); @@ -54,22 +56,20 @@ const CourseSummaryCard = ({ enrollmentCompleted }) => {
- { - enrollmentCompleted - ? ( - - ) : ( - - ) - } + {enrollmentCompleted + ? ( + + ) : ( + + )} {dayjs(minimalCourseMetadata.startDate).format(DATE_FORMAT)} diff --git a/src/components/skills-quiz-v2/JobCardComponent.jsx b/src/components/skills-quiz-v2/JobCardComponent.jsx index d4be9550ef..5c5f620683 100644 --- a/src/components/skills-quiz-v2/JobCardComponent.jsx +++ b/src/components/skills-quiz-v2/JobCardComponent.jsx @@ -71,7 +71,21 @@ const JobCardComponent = ({ setShowMoreRecommendedCourses(false); }; - return !isLoading ? ( + if (!isLoading) { + return ( + + ); + } + + if (!jobs || jobs.length === 0) { + return null; + } + + return (
))} - {jobs?.length > 0 && ( - <> - - - - - - -
- { !showMoreRecommendedCourses && ( - - ) } -
- { showMoreRecommendedCourses && } - - )} + + + + + + +
+ {!showMoreRecommendedCourses && ( + + )} +
+ {showMoreRecommendedCourses && }
- ) : ( - ); }; diff --git a/src/components/skills-quiz-v2/SkillsQuizForm.jsx b/src/components/skills-quiz-v2/SkillsQuizForm.jsx index 003d7c61c7..f77ed8c006 100644 --- a/src/components/skills-quiz-v2/SkillsQuizForm.jsx +++ b/src/components/skills-quiz-v2/SkillsQuizForm.jsx @@ -47,7 +47,7 @@ const SkillQuizForm = ({ isStyleAutoSuggest }) => {