Skip to content

Commit

Permalink
Revert "feat: subsidy box points to learner credit (#810)"
Browse files Browse the repository at this point in the history
This reverts commit 3637bed.
  • Loading branch information
adamstankiewicz committed Sep 15, 2023
1 parent eea0ba4 commit 72d4359
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 285 deletions.
72 changes: 72 additions & 0 deletions src/components/dashboard/sidebar/EnterpriseOffersSummaryCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Badge, Row, Col } from '@edx/paragon';
import dayjs from 'dayjs';
import {
ENTERPRISE_OFFER_SUMMARY_CARD_TITLE,
ENTERPRISE_OFFER_ACTIVE_BADGE_LABEL,
ENTERPRISE_OFFER_ACTIVE_BADGE_VARIANT,
} from './data/constants';
import SidebarCard from './SidebarCard';

function getOfferExpiringFirst(offers) {
return offers
.filter(offer => offer.isCurrent)
.sort((a, b) => new Date(a.endDatetime) - new Date(b.endDatetime))[0];

Check warning on line 15 in src/components/dashboard/sidebar/EnterpriseOffersSummaryCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/dashboard/sidebar/EnterpriseOffersSummaryCard.jsx#L15

Added line #L15 was not covered by tests
}

const EnterpriseOffersSummaryCard = ({
className, offers, searchCoursesCta,
}) => {
const offerExpiringFirst = getOfferExpiringFirst(offers);

return (
<SidebarCard
title={
(
<div className="d-flex align-items-center justify-content-between">
<h3 className="m-0">{ENTERPRISE_OFFER_SUMMARY_CARD_TITLE}</h3>
<Badge
variant={ENTERPRISE_OFFER_ACTIVE_BADGE_VARIANT}
className="ml-2"
data-testid="enterprise-offer-status-badge"
>
{ENTERPRISE_OFFER_ACTIVE_BADGE_LABEL}
</Badge>
</div>
)
}
cardClassNames={className}
>
<p data-testid="offer-summary-text">
Apply your organization&apos;s Learner Credit balance to enroll into courses with no out of pocket cost.
</p>
{offerExpiringFirst?.endDatetime && (
<p data-testid="offer-summary-end-date-text">
Available until <b>{dayjs(offerExpiringFirst.endDatetime).format('MMM D, YYYY')}</b>
</p>
)}
{searchCoursesCta && (
<Row className="mt-3 d-flex justify-content-end">
<Col xl={12}>{searchCoursesCta}</Col>
</Row>
)}
</SidebarCard>
);
};

EnterpriseOffersSummaryCard.propTypes = {
offers: PropTypes.arrayOf(PropTypes.shape({
endDatetime: PropTypes.string,
remainingBalanceForUser: PropTypes.number,
})).isRequired,
className: PropTypes.string,
searchCoursesCta: PropTypes.node,
};

EnterpriseOffersSummaryCard.defaultProps = {
className: undefined,
searchCoursesCta: undefined,
};

export default EnterpriseOffersSummaryCard;
62 changes: 0 additions & 62 deletions src/components/dashboard/sidebar/LearnerCreditSummaryCard.jsx

This file was deleted.

28 changes: 5 additions & 23 deletions src/components/dashboard/sidebar/SubsidiesSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ import { Button } from '@edx/paragon';
import classNames from 'classnames';
import CouponCodesSummaryCard from './CouponCodesSummaryCard';
import SubscriptionSummaryCard from './SubscriptionSummaryCard';
import LearnerCreditSummaryCard from './LearnerCreditSummaryCard';
import EnterpriseOffersSummaryCard from './EnterpriseOffersSummaryCard';
import { UserSubsidyContext } from '../../enterprise-user-subsidy';
import { LICENSE_STATUS } from '../../enterprise-user-subsidy/data/constants';
import { CATALOG_ACCESS_CARD_BUTTON_TEXT } from './data/constants';
import SidebarCard from './SidebarCard';
import { CourseEnrollmentsContext } from '../main-content/course-enrollments/CourseEnrollmentsContextProvider';
import { SubsidyRequestsContext, SUBSIDY_TYPE } from '../../enterprise-subsidy-requests';
import { getOfferExpiringFirst, getPolicyExpiringFirst } from './utils';

function getLearnerCreditSummaryCardData({ enterpriseOffers, redeemableLearnerCreditPolicies }) {
const enterpriseOfferExpiringFirst = getOfferExpiringFirst(enterpriseOffers);
const learnerCreditPolicyExpiringFirst = getPolicyExpiringFirst(redeemableLearnerCreditPolicies);
return {
expirationDate: learnerCreditPolicyExpiringFirst?.subsidyExpirationDate
|| enterpriseOfferExpiringFirst?.endDatetime,
};
}

const SubsidiesSummary = ({
className, showSearchCoursesCta, totalCoursesEligibleForCertificate, courseEndDate, programProgressPage,
Expand All @@ -45,14 +35,8 @@ const SubsidiesSummary = ({
couponCodes: { couponCodesCount },
enterpriseOffers,
canEnrollWithEnterpriseOffers,
redeemableLearnerCreditPolicies,
} = useContext(UserSubsidyContext);

const learnerCreditSummaryCardData = getLearnerCreditSummaryCardData({
enterpriseOffers,
redeemableLearnerCreditPolicies,
});

const {
requestsBySubsidyType,
} = useContext(SubsidyRequestsContext);
Expand All @@ -70,10 +54,9 @@ const SubsidiesSummary = ({
&& userSubscriptionLicense?.status === LICENSE_STATUS.ACTIVATED) || licenseRequests.length > 0;

const hasAssignedCodesOrCodeRequests = couponCodesCount > 0 || couponCodeRequests.length > 0;
const hasAvailableLearnerCreditPolicies = redeemableLearnerCreditPolicies?.length > 0;

const hasAvailableSubsidyOrRequests = hasActiveLicenseOrLicenseRequest
|| hasAssignedCodesOrCodeRequests || canEnrollWithEnterpriseOffers || hasAvailableLearnerCreditPolicies;
|| hasAssignedCodesOrCodeRequests || canEnrollWithEnterpriseOffers;

if (!hasAvailableSubsidyOrRequests) {
return null;
Expand Down Expand Up @@ -117,11 +100,10 @@ const SubsidiesSummary = ({
className="border-0 shadow-none"
/>
)}
{(canEnrollWithEnterpriseOffers || hasAvailableLearnerCreditPolicies)
&& learnerCreditSummaryCardData?.expirationDate && (
<LearnerCreditSummaryCard
{canEnrollWithEnterpriseOffers && (
<EnterpriseOffersSummaryCard
className="border-0 shadow-none"
expirationDate={learnerCreditSummaryCardData.expirationDate}
offers={enterpriseOffers}
/>
)}
</div>
Expand Down
6 changes: 0 additions & 6 deletions src/components/dashboard/sidebar/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export const ENTERPRISE_OFFER_ACTIVE_BADGE_LABEL = 'Active';
export const ENTERPRISE_OFFER_ACTIVE_BADGE_VARIANT = 'success';
export const ENTERPRISE_OFFER_SUMMARY_CARD_SUMMARY = 'Apply your organization\'s learner credit balance to enroll into courses with no out of pocket cost.';

// LearnerCreditSummaryCard
export const LEARNER_CREDIT_SUMMARY_CARD_TITLE = 'Learner Credit';
export const LEARNER_CREDIT_ACTIVE_BADGE_LABEL = 'Active';
export const LEARNER_CREDIT_ACTIVE_BADGE_VARIANT = 'success';
export const LEARNER_CREDIT_CARD_SUMMARY = 'Apply your organization\'s learner credit balance to enroll into courses with no out of pocket cost.';

// Dashboard Sidebar texts
export const CATALOG_ACCESS_CARD_BUTTON_TEXT = 'Find a course';
export const NEED_HELP_BLOCK_TITLE = 'Need help?';
Expand Down
47 changes: 1 addition & 46 deletions src/components/dashboard/sidebar/tests/DashboardSidebar.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
LICENSE_REQUESTED_NOTICE,
COUPON_CODES_SUMMARY_NOTICE,
ENTERPRISE_OFFER_SUMMARY_CARD_TITLE,
LEARNER_CREDIT_SUMMARY_CARD_TITLE,
} from '../data/constants';
import { LICENSE_STATUS } from '../../../enterprise-user-subsidy/data/constants';
import CourseEnrollmentsContextProvider from '../../main-content/course-enrollments/CourseEnrollmentsContextProvider';
Expand Down Expand Up @@ -62,7 +61,6 @@ describe('<DashboardSidebar />', () => {
couponCodesCount: 0,
},
enterpriseOffers: [],
redeemableLearnerCreditPolicies: undefined,
};
const initialAppState = {
enterpriseConfig: {
Expand Down Expand Up @@ -175,7 +173,7 @@ describe('<DashboardSidebar />', () => {
);
expect(screen.queryByText(SUBSCRIPTION_SUMMARY_CARD_TITLE)).toBeFalsy();
});
test('Enterprise offers summary card is displayed when enterprise has active offers and no subscriptions or coupons or learner credit', () => {
test('Enterprise offers summary card is displayed when enterprise has active offers and no subscriptions or coupons', () => {
renderWithRouter(
<DashboardSidebarWithContext
initialAppState={initialAppState}
Expand Down Expand Up @@ -221,49 +219,6 @@ describe('<DashboardSidebar />', () => {
expect(screen.queryByText(SUBSCRIPTION_SUMMARY_CARD_TITLE)).not.toBeInTheDocument();
expect(screen.queryByText(COUPON_CODES_SUMMARY_NOTICE)).toBeInTheDocument();
});

test('Learner credit summary card is displayed when enterprise has learner credit', () => {
renderWithRouter(
<DashboardSidebarWithContext
initialAppState={initialAppState}
initialUserSubsidyState={{
...defaultUserSubsidyState,
redeemableLearnerCreditPolicies: [{
remainingBalancePerUser: 5,
subsidyExpirationDate: '2030-01-01 12:00:00Z',
active: true,
}],
}}
/>,
);
expect(screen.queryByText(LEARNER_CREDIT_SUMMARY_CARD_TITLE)).toBeInTheDocument();
});

test('Only learner credit summary card is displayed when enterprise has both; learner credit and offers', () => {
const policyExpirationDate = '2030-01-01 12:00:00Z';
const offerEndDate = '2027-10-25';
renderWithRouter(
<DashboardSidebarWithContext
initialAppState={initialAppState}
initialUserSubsidyState={{
...defaultUserSubsidyState,
redeemableLearnerCreditPolicies: [{
remainingBalancePerUser: 5,
subsidyExpirationDate: policyExpirationDate,
active: true,
}],
enterpriseOffers: [{
uuid: 'enterprise-offer-id',
endDatetime: offerEndDate,
}],
canEnrollWithEnterpriseOffers: true,
}}
/>,
);
expect(screen.getByText('2030', { exact: false })).toBeInTheDocument();
expect(screen.queryByText('2027', { exact: false })).toBeFalsy();
});

test('Find a course button is not rendered when user has no coupon codes or license subsidy', () => {
renderWithRouter(
<DashboardSidebarWithContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { screen, render } from '@testing-library/react';

import EnterpriseOffersSummaryCard from '../EnterpriseOffersSummaryCard';
import { ENTERPRISE_OFFER_SUMMARY_CARD_TITLE } from '../data/constants';

const mockEnterpriseOffer = {
isCurrent: true,
uuid: 'test-enterprise-offer-uuid',
status: 'Open',
enterpriseCatalogUuid: 'test-enterprise-catalog-uuid',
startDatetime: '2022-06-01T00:00:00Z',
endDatetime: '2023-06-01T00:00:00Z',
maxDiscount: 5000,
remainingBalance: 4500,
remainingBalanceForUser: null,
};

describe('<EnterpriseOffersSummaryCard />', () => {
it('should render searchCoursesCta', () => {
const cta = 'Search Courses';
render(
<EnterpriseOffersSummaryCard
offers={[mockEnterpriseOffer]}
searchCoursesCta={
<button type="button">{cta}</button>
}
/>,
);

expect(screen.getByText(ENTERPRISE_OFFER_SUMMARY_CARD_TITLE)).toBeInTheDocument();
expect(screen.getByText(cta)).toBeInTheDocument();
});

it('should render default summary text if remainingBalanceForUser is null', () => {
render(
<EnterpriseOffersSummaryCard
offers={[mockEnterpriseOffer]}
/>,
);

expect(screen.getByTestId('offer-summary-text')).toBeInTheDocument();
});

it('should render earliest, current offer end date, if applicable', () => {
render(
<EnterpriseOffersSummaryCard
offers={[
{
...mockEnterpriseOffer,
isCurrent: false,
endDatetime: '2022-04-01T00:00:00Z', // earliest, non-current start date
},
{
...mockEnterpriseOffer,
endDatetime: '2023-12-01T00:00:00Z', // earliest, current start date
},
]}
/>,
);
expect(screen.getByTestId('offer-summary-end-date-text')).toBeInTheDocument();
expect(screen.getByText('Dec 1, 2023')).toBeInTheDocument();
});
});

This file was deleted.

Loading

0 comments on commit 72d4359

Please sign in to comment.