Skip to content

Commit

Permalink
chore: test updates (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored Apr 12, 2024
1 parent 33f06e0 commit 750a30d
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 579 deletions.
11 changes: 3 additions & 8 deletions src/components/course/SubsidyRequestButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions src/components/course/enrollment/tests/EnrollAction.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ToEcomBasketPage />'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,92 +1,75 @@
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', () => ({
...jest.requireActual('../../../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 = () => (
<IntlProvider locale="en">
<UserSubsidyContext.Provider value={initialUserSubsidyState}>
<CourseContext.Provider value={courseContextValue}>
<ExternalCourseEnrollmentConfirmation />
</CourseContext.Provider>
</UserSubsidyContext.Provider>
<ExternalCourseEnrollmentConfirmation />
</IntlProvider>
);

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(<ExternalCourseEnrollmentConfirmationWrapper />);
renderWithRouterProvider({
path: '/:enterpriseSlug',
element: <ExternalCourseEnrollmentConfirmationWrapper />,
}, {
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();
Expand All @@ -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(<ExternalCourseEnrollmentConfirmationWrapper courseContextValue={courseContextValue} />);
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: <ExternalCourseEnrollmentConfirmationWrapper />,
}, {
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(<ExternalCourseEnrollmentConfirmationWrapper courseContextValue={courseContextValue} />);
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();
});
});
Loading

0 comments on commit 750a30d

Please sign in to comment.