Skip to content

Commit

Permalink
fix: variant based assignment bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Sep 18, 2024
1 parent b2a91d6 commit 28ed3b5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/components/course/course-header/CourseImportantDates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/components/course/data/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 64 in src/components/course/data/utils.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/course/data/utils.jsx#L64

Added line #L64 was not covered by tests
}
return courseRun.weeksToComplete <= weeksRemainingUntilEnd(courseRun);
}

Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <span className="font-weight-light">Starts {formattedStartDate}</span>;
}
Expand All @@ -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 <span className="font-weight-light">Ends {formattedEndDate}</span>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -129,14 +130,24 @@ describe('<BaseCourseCard />', () => {

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(
<BaseCourseCardWrapper
type={COURSE_STATUSES.inProgress}
Expand All @@ -148,14 +159,15 @@ describe('<BaseCourseCard />', () => {
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();
}
});

Expand Down Expand Up @@ -204,9 +216,15 @@ describe('<BaseCourseCard />', () => {
});

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');
Expand All @@ -221,10 +239,10 @@ describe('<BaseCourseCard />', () => {
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 {
Expand Down

0 comments on commit 28ed3b5

Please sign in to comment.