Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: variant based assignment bug fixes #1194

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/course/course-header/CourseImportantDates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ const CourseImportantDates = () => {
let soonestExpiringAllocatedAssignmentCourseStartDate = null;
if (soonestExpiringAssignment) {
const soonestExpiringAllocatedAssignment = courseMetadata.availableCourseRuns.find(
(courseRun) => courseRun.key === soonestExpiringAssignment?.contentKey,
(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 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 @@
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,9 @@ describe('<BaseCourseCard />', () => {
endDate={endDate}
mode="executive-education"
orgName="some_name"
pacing="self"
pacing="instructor"
/>,
);
const shouldRenderEndDate = dayjs(startDate) <= dayjs() && type !== 'completed';
if (shouldRenderEndDate) {
expect(screen.getByText(`Ends ${formattedEndDate}`)).toBeInTheDocument();
} else {
Expand Down
Loading