-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: add functionality to create honor course modes through studio #28114
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', | ||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to author: here we need a dictionary or list[tuple] of course modes |
||
currency: 'usd' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to author: is there a setting for this? Search. |
||
}), | ||
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; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to author: how can we update the course mode API so we don't necessarily have to send the username