From 21a418816b29297a425a02b18bc089a013a333ab Mon Sep 17 00:00:00 2001 From: cp-at-mit Date: Wed, 28 Aug 2024 16:26:35 -0400 Subject: [PATCH] mitxonline dashboard crashes when courserun has no upgrade deadline (#2362) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../public/src/components/EnrolledItemCard.js | 14 ++++--- .../src/components/EnrolledItemCard_test.js | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/frontend/public/src/components/EnrolledItemCard.js b/frontend/public/src/components/EnrolledItemCard.js index 59b0b6caa9..b1401129ac 100644 --- a/frontend/public/src/components/EnrolledItemCard.js +++ b/frontend/public/src/components/EnrolledItemCard.js @@ -438,12 +438,14 @@ export class EnrolledItemCard extends React.Component< Upgrade today and, upon passing, receive your certificate signed by MIT faculty to highlight the knowledge and skills you've gained from this MITx course.{" "} - - Upgrade expires:{" "} - {formatPrettyDateTimeAmPmTz( - parseDateString(enrollment.run.upgrade_deadline) - )} - + {enrollment.run.upgrade_deadline ? ( + + Upgrade expires:{" "} + {formatPrettyDateTimeAmPmTz( + parseDateString(enrollment.run.upgrade_deadline) + )} + + ) : null} ) : null diff --git a/frontend/public/src/components/EnrolledItemCard_test.js b/frontend/public/src/components/EnrolledItemCard_test.js index 6328d92b8d..6007db4f1c 100644 --- a/frontend/public/src/components/EnrolledItemCard_test.js +++ b/frontend/public/src/components/EnrolledItemCard_test.js @@ -253,4 +253,46 @@ describe("EnrolledItemCard", () => { const modals = inner.find(`#${modalId}`) assert.lengthOf(modals, 1) }) + ;["audit", "verified", "program"].forEach(mode => { + it(`renders the card for enrollment mode ${mode}`, async () => { + const testEnrollment = + mode === "program" ? + makeProgramEnrollment() : + makeCourseRunEnrollmentWithProduct() + userEnrollment = testEnrollment + enrollmentCardProps.enrollment = testEnrollment + const inner = await renderedCard() + const enrolledItems = inner.find(".enrolled-item") + assert.lengthOf(enrolledItems, 1) + const enrolledItem = enrolledItems.at(0) + if (mode !== "program") { + assert.equal( + enrolledItem.find("h2").text(), + userEnrollment.run.course.title + ) + if (mode === "verified") { + const pricingLinks = inner.find(".pricing-links") + assert.isFalse(pricingLinks.exists()) + } + } else { + assert.equal( + enrolledItem.find("h2").text(), + testEnrollment.program.title + ) + } + }) + }) + it("Test", async () => { + const testEnrollment = makeCourseRunEnrollmentWithProduct() + userEnrollment = testEnrollment + enrollmentCardProps.enrollment = testEnrollment + enrollmentCardProps.enrollment.enrollment_mode = "audit" + const inner = await renderedCard() + const enrollmentExtraLinks = inner + .find(".enrolled-item") + .find(".certificate-upgrade-message") + assert.isTrue(enrollmentExtraLinks.exists()) + const courseDetailsPageLink = enrollmentExtraLinks.find("b").at(0) + assert.isTrue(courseDetailsPageLink.exists()) + }) })