-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add functionality to create honor course modes through studio
- Loading branch information
1 parent
25577e6
commit 98b1d0c
Showing
11 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
cms/static/js/certificates/factories/course_mode_factory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
define([ | ||
'jquery', | ||
'js/certificates/views/add_course_mode' | ||
], | ||
function($, CourseModeHandler) { | ||
'use strict'; | ||
return function(enableCourseModeCreation, courseModeCreationUrl, courseId) { | ||
// Execute the page object's rendering workflow | ||
new CourseModeHandler({ | ||
enableCourseModeCreation: enableCourseModeCreation, | ||
courseModeCreationUrl: courseModeCreationUrl, | ||
courseId: courseId | ||
}).show(); | ||
}; | ||
}); |
89 changes: 89 additions & 0 deletions
89
cms/static/js/certificates/spec/views/add_course_mode_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Jasmine Test Suite: Course modes creation | ||
|
||
define([ | ||
'underscore', | ||
'jquery', | ||
'js/models/course', | ||
'js/certificates/views/add_course_mode', | ||
'common/js/spec_helpers/template_helpers', | ||
'common/js/spec_helpers/view_helpers', | ||
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers' | ||
], | ||
function(_, $, Course, AddCourseMode, TemplateHelpers, ViewHelpers, AjaxHelpers) { | ||
'use strict'; | ||
|
||
var SELECTORS = { | ||
addCourseMode: '.add-course-mode' | ||
}; | ||
|
||
describe('Add Course Modes Spec:', function() { | ||
beforeEach(function() { | ||
window.course = new Course({ | ||
id: '5', | ||
name: 'Course Name', | ||
url_name: 'course_name', | ||
org: 'course_org', | ||
num: 'course_num', | ||
revision: 'course_rev' | ||
}); | ||
window.CMS.User = {isGlobalStaff: true, isCourseInstructor: true}; | ||
|
||
TemplateHelpers.installTemplate('course-modes', true); | ||
appendSetFixtures('<div class="wrapper-certificates nav-actions"></div>'); | ||
appendSetFixtures('<p class="account-username">test</p>'); | ||
this.view = new AddCourseMode({ | ||
el: $('.wrapper-certificates'), | ||
courseId: window.course.id, | ||
courseModeCreationUrl: '/api/course_modes/v1/courses/' + window.course.id + '/', | ||
enableCourseModeCreation: true | ||
}); | ||
appendSetFixtures(this.view.render().el); | ||
}); | ||
|
||
afterEach(function() { | ||
delete window.course; | ||
delete window.CMS.User; | ||
}); | ||
|
||
describe('Add course modes', function() { | ||
it('course mode creation event works fine', function() { | ||
spyOn(this.view, 'addCourseMode'); | ||
this.view.delegateEvents(); | ||
this.view.$(SELECTORS.addCourseMode).click(); | ||
expect(this.view.addCourseMode).toHaveBeenCalled(); | ||
}); | ||
|
||
it('add course modes button works fine', function() { | ||
var requests = AjaxHelpers.requests(this), | ||
notificationSpy = ViewHelpers.createNotificationSpy(); | ||
this.view.$(SELECTORS.addCourseMode).click(); | ||
AjaxHelpers.expectJsonRequest( | ||
requests, | ||
'POST', '/api/course_modes/v1/courses/' + window.course.id + '/?username=test', | ||
{ | ||
course_id: window.course.id, | ||
mode_slug: 'honor', | ||
mode_display_name: 'Honor', | ||
currency: 'usd' | ||
}); | ||
ViewHelpers.verifyNotificationShowing(notificationSpy, /Enabling honor course mode/); | ||
}); | ||
|
||
it('enable course mode creation should be false when method "remove" called', function() { | ||
this.view.remove(); | ||
expect(this.view.enableCourseModeCreation).toBe(false); | ||
}); | ||
|
||
it('add course mode should be removed when method "remove" called', function() { | ||
this.view.remove(); | ||
expect(this.view.el.innerHTML).toBe(''); | ||
}); | ||
|
||
it('method "show" should call the render function', function() { | ||
spyOn(this.view, 'render'); | ||
this.view.show(); | ||
expect(this.view.render).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
define([ | ||
'underscore', | ||
'gettext', | ||
'js/views/baseview', | ||
'common/js/components/views/feedback_notification', | ||
'text!templates/course-modes.underscore', | ||
'edx-ui-toolkit/js/utils/html-utils' | ||
], | ||
function(_, gettext, BaseView, NotificationView, CourseModes, HtmlUtils) { | ||
'use strict'; | ||
|
||
var AddCourseMode = BaseView.extend({ | ||
el: $('.wrapper-certificates'), | ||
events: { | ||
'click .add-course-mode': 'addCourseMode' | ||
}, | ||
|
||
initialize: function(options) { | ||
this.enableCourseModeCreation = options.enableCourseModeCreation; | ||
this.courseModeCreationUrl = options.courseModeCreationUrl; | ||
this.courseId = options.courseId; | ||
}, | ||
|
||
render: function() { | ||
HtmlUtils.setHtml(this.$el, HtmlUtils.template(CourseModes)({ | ||
enableCourseModeCreation: this.enableCourseModeCreation, | ||
courseModeCreationUrl: this.courseModeCreationUrl, | ||
courseId: this.courseId | ||
})); | ||
return this; | ||
}, | ||
|
||
addCourseMode: function() { | ||
var notification = new NotificationView.Mini({ | ||
title: gettext('Enabling honor course mode') | ||
}); | ||
var username = $('.account-username')[0].innerText; | ||
$.ajax({ | ||
url: this.courseModeCreationUrl + '?username=' + username, | ||
dataType: 'json', | ||
contentType: 'application/json', | ||
data: JSON.stringify({ | ||
course_id: this.courseId, | ||
mode_slug: 'honor', | ||
mode_display_name: 'Honor', | ||
currency: 'usd' | ||
}), | ||
type: 'POST', | ||
beforeSend: function() { | ||
notification.show(); | ||
}, | ||
success: function() { | ||
notification.hide(); | ||
location.reload(); | ||
} | ||
}); | ||
}, | ||
|
||
show: function() { | ||
this.render(); | ||
}, | ||
|
||
remove: function() { | ||
this.enableCourseModeCreation = false; | ||
this.$el.empty(); | ||
return this; | ||
} | ||
}); | ||
return AddCourseMode; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="no-content"> | ||
<label for="add-course-mode"><%- gettext("Enable the honor mode for the course.") %></label> | ||
<a href="#" class="button new-button add-course-mode"> | ||
<% if ( enableCourseModeCreation ) { %> <%- gettext("Enable honor mode") %> <% } %> | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters