From 28ed3b50afb535b47fea2dc02dc7c5012010d2d8 Mon Sep 17 00:00:00 2001 From: Hamzah Ullah Date: Tue, 17 Sep 2024 18:23:45 -0400 Subject: [PATCH 1/2] fix: variant based assignment bug fixes --- .../course-header/CourseImportantDates.jsx | 5 ++- src/components/course/data/utils.jsx | 6 ++- .../course-cards/BaseCourseCard.jsx | 4 +- .../tests/BaseCourseCard.test.jsx | 42 +++++++++++++------ 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/components/course/course-header/CourseImportantDates.jsx b/src/components/course/course-header/CourseImportantDates.jsx index ebdaa81eea..9eb6d2cfae 100644 --- a/src/components/course/course-header/CourseImportantDates.jsx +++ b/src/components/course/course-header/CourseImportantDates.jsx @@ -92,8 +92,9 @@ const CourseImportantDates = () => { const soonestExpiringAllocatedAssignment = courseMetadata.availableCourseRuns.find( (courseRun) => courseRun.key === soonestExpiringAssignment?.contentKey, ); - soonestExpiringAllocatedAssignmentCourseStartDate = soonestExpiringAllocatedAssignment - && getNormalizedStartDate(soonestExpiringAllocatedAssignment); + if (soonestExpiringAllocatedAssignment) { + soonestExpiringAllocatedAssignmentCourseStartDate = getNormalizedStartDate(soonestExpiringAllocatedAssignment); + } } // Parse logic of date existence and labels const enrollByDate = soonestExpirationDate ?? null; diff --git a/src/components/course/data/utils.jsx b/src/components/course/data/utils.jsx index 5f4873d655..c19d769b6c 100644 --- a/src/components/course/data/utils.jsx +++ b/src/components/course/data/utils.jsx @@ -60,6 +60,9 @@ export function weeksRemainingUntilEnd(courseRun) { } export function hasTimeToComplete(courseRun) { + if ((!courseRun.weeksToComplete || !courseRun.end) && dayjs(courseRun.start).isAfter(dayjs(), 'minute')) { + return true; + } return courseRun.weeksToComplete <= weeksRemainingUntilEnd(courseRun); } @@ -91,12 +94,11 @@ export const getNormalizedStartDate = ({ return todayToIso; } const startDateIso = dayjs(start).toISOString(); - if (isCourseSelfPaced({ pacingType })) { + if (isCourseSelfPaced(pacingType)) { if (hasTimeToComplete({ end, weeksToComplete }) || isWithinMinimumStartDateThreshold({ start })) { // always today's date (incentives enrollment) return todayToIso; } - return startDateIso; } return startDateIso; }; diff --git a/src/components/dashboard/main-content/course-enrollments/course-cards/BaseCourseCard.jsx b/src/components/dashboard/main-content/course-enrollments/course-cards/BaseCourseCard.jsx index b9f96b9246..5996e05502 100644 --- a/src/components/dashboard/main-content/course-enrollments/course-cards/BaseCourseCard.jsx +++ b/src/components/dashboard/main-content/course-enrollments/course-cards/BaseCourseCard.jsx @@ -410,7 +410,7 @@ const BaseCourseCard = ({ weeksToComplete: null, }); const formattedStartDate = dayjs(courseStartDate).format('MMMM Do, YYYY'); - const isCourseStarted = dayjs(courseStartDate).isBefore(dayjs()); + const isCourseStarted = dayjs(startDate).isBefore(dayjs(), 'minute'); if (formattedStartDate && !isCourseStarted) { return Starts {formattedStartDate}; } @@ -419,7 +419,7 @@ const BaseCourseCard = ({ const renderEndDate = () => { const formattedEndDate = endDate ? dayjs(endDate).format('MMMM Do, YYYY') : null; - const isCourseStarted = dayjs(startDate).isBefore(dayjs()); + const isCourseStarted = dayjs(startDate).isBefore(dayjs(), 'minute'); if (formattedEndDate && isCourseStarted && type !== COURSE_STATUSES.completed) { return Ends {formattedEndDate}; } diff --git a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx index 8f94880b00..7e62194caf 100644 --- a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx +++ b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx @@ -20,6 +20,7 @@ import { } from '../../../../../app/data/services/data/__factories__'; import { COURSE_STATUSES } from '../../data'; import { isCourseEnded } from '../../../../../../utils/common'; +import { getNormalizedStartDate } from '../../../../../course/data'; jest.mock('@edx/frontend-enterprise-utils', () => ({ ...jest.requireActual('@edx/frontend-enterprise-utils'), @@ -129,14 +130,24 @@ describe('', () => { it.each([{ startDate: dayjs().toISOString(), + endDate: dayjs().add(5, 'days').toISOString(), + isStarted: false, }, { startDate: dayjs().subtract(1, 'day').toISOString(), + endDate: dayjs().add(5, 'days').toISOString(), + isStarted: true, }, { startDate: dayjs().add(1, 'day').toISOString(), - }])('renders with different startDate values', ({ startDate }) => { - const formattedStartDate = dayjs(startDate).format('MMMM Do, YYYY'); - const isCourseStarted = dayjs(startDate) <= dayjs(); - + endDate: dayjs().add(5, 'days').toISOString(), + isStarted: false, + }])('renders with different startDate values (%s)', ({ startDate, endDate, isStarted }) => { + const courseStartDate = getNormalizedStartDate({ + start: startDate, + end: endDate, + pacingType: 'self', + weeksToComplete: null, + }); + const formatStartDate = (date) => dayjs(date).format('MMMM Do, YYYY'); renderWithRouter( ', () => { productSource="2u" mode="executive-education" startDate={startDate} + endDate={endDate} orgName="some_name" pacing="self" />, ); - if (!isCourseStarted) { - expect(screen.getByText(`Starts ${formattedStartDate}`)).toBeInTheDocument(); + if (isStarted) { + expect(screen.queryByText(`Starts ${formatStartDate(courseStartDate)}`)).not.toBeInTheDocument(); } else { - expect(screen.queryByText(`Starts ${formattedStartDate}`)).not.toBeInTheDocument(); + expect(screen.getByText(`Starts ${formatStartDate(courseStartDate)}`)).toBeInTheDocument(); } }); @@ -204,9 +216,15 @@ describe('', () => { }); it.each([ - { type: COURSE_STATUSES.inProgress }, - { type: COURSE_STATUSES.completed }, - ])('renders endDate based on the course state', ({ type }) => { + { + type: COURSE_STATUSES.inProgress, + shouldRenderEndDate: true, + }, + { + type: COURSE_STATUSES.completed, + shouldRenderEndDate: false, + }, + ])('renders endDate based on the course state', ({ type, shouldRenderEndDate }) => { const startDate = dayjs().subtract(7, 'days').toISOString(); const endDate = dayjs().add(7, 'days').toISOString(); const formattedEndDate = dayjs(endDate).format('MMMM Do, YYYY'); @@ -221,10 +239,10 @@ describe('', () => { endDate={endDate} mode="executive-education" orgName="some_name" - pacing="self" + pacing="instructor" />, ); - const shouldRenderEndDate = dayjs(startDate) <= dayjs() && type !== 'completed'; + // const shouldRenderEndDate = dayjs(startDate).isBefore(dayjs(), 'day') && type !== 'completed'; if (shouldRenderEndDate) { expect(screen.getByText(`Ends ${formattedEndDate}`)).toBeInTheDocument(); } else { From 8881dcc9429fb9c52c8c389ddd30817123ca7f03 Mon Sep 17 00:00:00 2001 From: Hamzah Ullah Date: Wed, 18 Sep 2024 11:03:31 -0400 Subject: [PATCH 2/2] chore: PR feedback --- src/components/course/course-header/CourseImportantDates.jsx | 2 +- .../course-cards/tests/BaseCourseCard.test.jsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/course/course-header/CourseImportantDates.jsx b/src/components/course/course-header/CourseImportantDates.jsx index 9eb6d2cfae..8e16250221 100644 --- a/src/components/course/course-header/CourseImportantDates.jsx +++ b/src/components/course/course-header/CourseImportantDates.jsx @@ -90,7 +90,7 @@ const CourseImportantDates = () => { let soonestExpiringAllocatedAssignmentCourseStartDate = null; if (soonestExpiringAssignment) { const soonestExpiringAllocatedAssignment = courseMetadata.availableCourseRuns.find( - (courseRun) => courseRun.key === soonestExpiringAssignment?.contentKey, + (courseRun) => courseRun.key === soonestExpiringAssignment.contentKey, ); if (soonestExpiringAllocatedAssignment) { soonestExpiringAllocatedAssignmentCourseStartDate = getNormalizedStartDate(soonestExpiringAllocatedAssignment); diff --git a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx index 7e62194caf..a0a1e55e0a 100644 --- a/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx +++ b/src/components/dashboard/main-content/course-enrollments/course-cards/tests/BaseCourseCard.test.jsx @@ -242,7 +242,6 @@ describe('', () => { pacing="instructor" />, ); - // const shouldRenderEndDate = dayjs(startDate).isBefore(dayjs(), 'day') && type !== 'completed'; if (shouldRenderEndDate) { expect(screen.getByText(`Ends ${formattedEndDate}`)).toBeInTheDocument(); } else {