Fixed Course handouts rejects deletion of all text

This commit is contained in:
Asad Azam
2017-01-10 14:55:01 +05:00
parent 28e3b1cb5a
commit 48bec75b80
2 changed files with 19 additions and 1 deletions

View File

@@ -232,6 +232,20 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
@handoutsEdit.render()
it "saves <ol></ol> when content left empty", ->
requests = AjaxHelpers["requests"](this)
# Enter empty string in the handouts section, verifying that the model
# is saved with '<ol></ol>' instead of the empty string
@handoutsEdit.$el.find('.edit-button').click()
spyOn(@handoutsEdit.$codeMirror, 'getValue').and.returnValue('')
spyOn(@model, "save").and.callThrough()
@handoutsEdit.$el.find('.save-button').click()
expect(@model.save).toHaveBeenCalled()
contentSaved = JSON.parse(requests[requests.length - 1].requestBody).data
expect(contentSaved).toEqual('<ol></ol>')
it "does not rewrite links on save", ->
requests = AjaxHelpers["requests"](this)

View File

@@ -50,10 +50,14 @@ define(['js/views/baseview', 'codemirror', 'common/js/components/views/feedback_
},
onSave: function(event) {
var handoutsContent = this.$codeMirror.getValue();
$('#handout_error').removeClass('is-shown');
$('.save-button').removeClass('is-disabled').attr('aria-disabled', false);
if ($('.CodeMirror-lines').find('.cm-error').length == 0) {
this.model.set('data', this.$codeMirror.getValue());
if (handoutsContent === '') {
handoutsContent = '<ol></ol>';
}
this.model.set('data', handoutsContent);
var saving = new NotificationView.Mini({
title: gettext('Saving')
});