From 5314784a4d83f8f2b63e877878b21bbb0bb63fce Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Mon, 15 May 2017 17:59:57 -0400 Subject: [PATCH] Handle expired enrollments on the program detail page Learners should be able to enroll in future runs of courses in which they have an expired enrollment. Previously, the course card model populated itself by selecting the first course run in which the user was enrolled. When the user tried to enroll in another run, nothing would happen because they were already enrolled in the run the page was trying to enroll them in. Instead of blindly choosing the first run in which the user is enrolled, we now fall through to the same behavior we use for courses in which the user is not enrolled when the user has expired enrollments. LEARNER-933 --- .../models/course_card_model.js | 14 ++++++------- .../course_card_view_spec.js | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lms/static/js/learner_dashboard/models/course_card_model.js b/lms/static/js/learner_dashboard/models/course_card_model.js index 547d225d7d..207e532f7d 100644 --- a/lms/static/js/learner_dashboard/models/course_card_model.js +++ b/lms/static/js/learner_dashboard/models/course_card_model.js @@ -14,18 +14,18 @@ initialize: function(data) { if (data) { this.context = data; - this.setActiveCourseRun(this.getCourseRun(data.course_runs), data.user_preferences); + this.setActiveCourseRun(this.getCourseRun(data), data.user_preferences); } }, - getCourseRun: function(courseRuns) { - var enrolledCourseRun = _.findWhere(courseRuns, {is_enrolled: true}), + getCourseRun: function(course) { + var enrolledCourseRun = _.findWhere(course.course_runs, {is_enrolled: true}), openEnrollmentCourseRuns = this.getEnrollableCourseRuns(), desiredCourseRun; - // We populate our model by looking at the course runs. - if (enrolledCourseRun) { - // If the learner is already enrolled in a course run, return that one. + // If the learner has an existing, unexpired enrollment, + // use it to populate the model. + if (enrolledCourseRun && !course.expired) { desiredCourseRun = enrolledCourseRun; } else if (openEnrollmentCourseRuns.length > 0) { if (openEnrollmentCourseRuns.length === 1) { @@ -34,7 +34,7 @@ desiredCourseRun = this.getUnselectedCourseRun(openEnrollmentCourseRuns); } } else { - desiredCourseRun = this.getUnselectedCourseRun(courseRuns); + desiredCourseRun = this.getUnselectedCourseRun(course.course_runs); } return desiredCourseRun; diff --git a/lms/static/js/spec/learner_dashboard/course_card_view_spec.js b/lms/static/js/spec/learner_dashboard/course_card_view_spec.js index 4c0acf023c..d7e4b8770d 100644 --- a/lms/static/js/spec/learner_dashboard/course_card_view_spec.js +++ b/lms/static/js/spec/learner_dashboard/course_card_view_spec.js @@ -145,6 +145,26 @@ define([ expect(view.$('.course-certificate .certificate-status').length).toEqual(0); }); + it('should allow enrollment in future runs when the user has an expired enrollment', function() { + var newRun = $.extend({}, course.course_runs[0]), + newRunKey = 'course-v1:foo+bar+baz', + advertisedStart = 'Summer'; + + newRun.key = newRunKey; + newRun.is_enrolled = false; + newRun.advertised_start = advertisedStart; + course.course_runs.push(newRun); + + course.expired = true; + + setupView(course, true); + + expect(courseCardModel.get('course_run_key')).toEqual(newRunKey); + expect(view.$('.course-details .course-text .run-period').html()).toEqual( + advertisedStart + ' - ' + endDate + ); + }); + it('should show a message if an there is an upcoming course run', function() { course.course_runs[0].is_enrollment_open = false;