From 419a8bf1c8b07aa53eb1ea58c0c853d9ecd81d2c Mon Sep 17 00:00:00 2001 From: mohtamba Date: Mon, 16 Aug 2021 10:08:37 -0400 Subject: [PATCH 1/3] Deleted old allowance code Removed the template files and javascript files for the old allowance template, so the code remaining is for the new bulk allowance only. --- .../proctored_exam_add_allowance_view.js | 220 ---------- .../js/views/proctored_exam_allowance_view.js | 63 +-- .../spec/proctored_exam_add_allowance_spec.js | 396 ------------------ .../proctored_exam_add_bulk_allowance_spec.js | 3 +- .../spec/proctored_exam_allowance_spec.js | 184 -------- .../proctored_exam_bulk_allowance_spec.js | 3 +- .../templates/add-new-allowance.underscore | 76 ---- .../templates/course_allowances.underscore | 58 --- 8 files changed, 14 insertions(+), 989 deletions(-) delete mode 100644 edx_proctoring/static/proctoring/js/views/proctored_exam_add_allowance_view.js delete mode 100644 edx_proctoring/static/proctoring/spec/proctored_exam_add_allowance_spec.js delete mode 100644 edx_proctoring/static/proctoring/spec/proctored_exam_allowance_spec.js delete mode 100644 edx_proctoring/static/proctoring/templates/add-new-allowance.underscore delete mode 100644 edx_proctoring/static/proctoring/templates/course_allowances.underscore diff --git a/edx_proctoring/static/proctoring/js/views/proctored_exam_add_allowance_view.js b/edx_proctoring/static/proctoring/js/views/proctored_exam_add_allowance_view.js deleted file mode 100644 index 0ded3e0d6e7..00000000000 --- a/edx_proctoring/static/proctoring/js/views/proctored_exam_add_allowance_view.js +++ /dev/null @@ -1,220 +0,0 @@ -edx = edx || {}; - -(function(Backbone, $, _, gettext) { - 'use strict'; - - edx.instructor_dashboard = edx.instructor_dashboard || {}; - edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {}; - - edx.instructor_dashboard.proctoring.AddAllowanceView = Backbone.ModalView.extend({ - name: 'AddAllowanceView', - template: null, - template_url: '/static/proctoring/templates/add-new-allowance.underscore', - initialize: function(options) { - this.proctored_exams = options.proctored_exams; - this.proctored_exam_allowance_view = options.proctored_exam_allowance_view; - this.course_id = options.course_id; - this.allowance_types = options.allowance_types; - this.model = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel(); - _.bindAll(this, 'render'); - this.loadTemplateData(); - // Backbone.Validation.bind( this, {valid:this.hideError, invalid:this.showError}); - }, - events: { - 'submit form': 'addAllowance', - 'change #proctored_exam': 'selectExam', - 'change #allowance_type': 'selectAllowance' - }, - loadTemplateData: function() { - var self = this; - $.ajax({url: self.template_url, dataType: 'html'}) - .done(function(templateData) { - self.template = _.template(templateData); - self.render(); - self.showModal(); - self.updateCss(); - self.selectExamAtIndex(0); - }); - }, - updateCss: function() { - var $el = $(this.el); - $el.find('.modal-header').css({ - color: '#1580b0', - 'font-size': '20px', - 'font-weight': '600', - 'line-height': 'normal', - padding: '10px 15px', - 'border-bottom': '1px solid #ccc' - }); - $el.find('form').css({ - padding: '15px' - }); - $el.find('form table.compact td').css({ - 'vertical-align': 'middle', - padding: '4px 8px' - }); - $el.find('form label').css({ - display: 'block', - 'font-size': '14px', - margin: 0, - cursor: 'default' - }); - $el.find('form #minutes_label').css({ - display: 'inline-block' - }); - $el.find('form input[type="text"]').css({ - height: '26px', - padding: '1px 8px 2px', - 'font-size': '14px' - }); - $el.find('form input[type="submit"]').css({ - 'margin-top': '10px', - padding: '2px 32px' - }); - $el.find('.error-message').css({ - color: '#ff0000', - 'line-height': 'normal', - 'font-size': '14px' - }); - $el.find('.error-response').css({ - color: '#ff0000', - 'line-height': 'normal', - 'font-size': '14px', - padding: '0px 10px 5px 7px' - }); - $el.find('form select').css({ - padding: '2px 0px 2px 2px', - 'font-size': '16px' - }); - }, - getCurrentFormValues: function() { - return { - proctored_exam: $('select#proctored_exam').val(), - allowance_type: $('select#allowance_type').val(), - allowance_value: $('#allowance_value').val(), - user_info: $('#user_info').val() - }; - }, - hideError: function(view, attr) { - var $element = view.$form[attr]; - - $element.removeClass('error'); - $element.parent().find('.error-message').empty(); - }, - showError: function(view, attr, errorMessage) { - var $element = view.$form[attr]; - var $errorMessage; - - $element.addClass('error'); - $errorMessage = $element.parent().find('.error-message'); - if ($errorMessage.length === 0) { - $errorMessage = $("
"); - $element.parent().append($errorMessage); - } - - $errorMessage.empty().append(errorMessage); - this.updateCss(); - }, - addAllowance: function(event) { - var $errorResponse, values, formHasErrors; - var self = this; - event.preventDefault(); - $errorResponse = $('.error-response'); - $errorResponse.html(); - values = this.getCurrentFormValues(); - formHasErrors = false; - - $.each(values, function(key, value) { - if (value === '') { - formHasErrors = true; - self.showError(self, key, gettext('Required field')); - } else { - self.hideError(self, key); - } - }); - - if (!formHasErrors) { - self.model.fetch({ - headers: { - 'X-CSRFToken': self.proctored_exam_allowance_view.getCSRFToken() - }, - type: 'PUT', - data: { - exam_id: values.proctored_exam, - user_info: values.user_info, - key: values.allowance_type, - value: values.allowance_value - }, - success: function() { - // fetch the allowances again. - $errorResponse.html(); - self.proctored_exam_allowance_view.collection.url = - self.proctored_exam_allowance_view.initial_url + self.course_id + '/allowance'; - self.proctored_exam_allowance_view.hydrate(); - self.hideModal(); - }, - error: function(unused, response) { - var data = $.parseJSON(response.responseText); - $errorResponse.html(gettext(data.detail)); - } - }); - } - }, - selectExamAtIndex: function(index) { - var selectedExam = this.proctored_exams[index]; - - if (selectedExam.is_proctored) { - // Selected Exam is a Proctored or Practice-Proctored exam. - if (selectedExam.is_practice_exam) { - $('#exam_type_label').text(gettext('Practice Exam')); - } else { - $('#exam_type_label').text(gettext('Proctored Exam')); - } - - // In case of Proctored Exams, we hide the Additional Time label and show the Allowance Types Select - $('#additional_time_label').hide(); - $('select#allowance_type').val('additional_time_granted').show(); - } else { - // Selected Exam is a Timed Exam. - $('#exam_type_label').text(gettext('Timed Exam')); - - // In case of Timed Exams, we show the "Additional Time" label and hide the Allowance Types Select - $('#additional_time_label').show(); - // Even though we have the Select element hidden, the backend will still be using - // the Select's value for the allowance type (key). - $('select#allowance_type').val('additional_time_granted').hide(); - } - this.updateAllowanceLabels('additional_time_granted'); - }, - selectExam: function() { - this.selectExamAtIndex($('#proctored_exam')[0].selectedIndex); - }, - selectAllowance: function() { - this.updateAllowanceLabels($('#allowance_type').val()); - }, - updateAllowanceLabels: function(selectedAllowanceType) { - if (selectedAllowanceType === 'additional_time_granted') { - $('#minutes_label').show(); - $('#allowance_value_label').text(gettext('Additional Time')); - } else { - $('#minutes_label').hide(); - $('#allowance_value_label').text(gettext('Value')); - } - }, - - render: function() { - $(this.el).html(this.template({ - proctored_exams: this.proctored_exams, - allowance_types: this.allowance_types - })); - - this.$form = { - proctored_exam: this.$('select#proctored_exam'), - allowance_type: this.$('select#allowance_type'), - allowance_value: this.$('#allowance_value'), - user_info: this.$('#user_info') - }; - return this; - } - }); -}).call(this, Backbone, $, _, gettext); diff --git a/edx_proctoring/static/proctoring/js/views/proctored_exam_allowance_view.js b/edx_proctoring/static/proctoring/js/views/proctored_exam_allowance_view.js index daa3e1da3f5..3d58ecd7e2a 100644 --- a/edx_proctoring/static/proctoring/js/views/proctored_exam_allowance_view.js +++ b/edx_proctoring/static/proctoring/js/views/proctored_exam_allowance_view.js @@ -19,17 +19,8 @@ edx = edx || {}; /* unfortunately we have to make some assumptions about what is being set up in HTML */ this.setElement($('.special-allowance-container')); this.course_id = this.$el.data('course-id'); - /* we need to check if the bulk allowance waffle flag is enabled */ - this.enableBulkAllowance = - this.$el.data('enable-bulk-allowance'); - this.enableBulkAllowance = this.enableBulkAllowance && - this.enableBulkAllowance.toLowerCase() === 'true'; /* this should be moved to a 'data' attribute in HTML */ - if (this.enableBulkAllowance) { - this.template_url = '/static/proctoring/templates/course_grouped_allowances.underscore'; - } else { - this.template_url = '/static/proctoring/templates/course_allowances.underscore'; - } + this.template_url = '/static/proctoring/templates/course_grouped_allowances.underscore'; this.template = null; this.initial_url = this.collection.url; this.allowance_url = this.initial_url + 'allowance'; @@ -121,11 +112,7 @@ edx = edx || {}; /* we might - at some point - add a visual element to the */ /* loading, like a spinner */ var self = this; - if (self.enableBulkAllowance) { - self.collection.url = self.initial_url + self.course_id + '/grouped/allowance'; - } else { - self.collection.url = self.initial_url + self.course_id + '/allowance'; - } + self.collection.url = self.initial_url + self.course_id + '/grouped/allowance'; self.collection.fetch({ success: function() { self.render(); @@ -137,26 +124,10 @@ edx = edx || {}; }, render: function() { var self = this; - var key, i, html; + var html; if (this.template !== null) { - if (!this.enableBulkAllowance) { - this.collection.each(function(item) { - key = item.get('key'); - for (i = 0; i < self.allowance_types.length; i += 1) { - if (key === self.allowance_types[i][0]) { - item.set('key_display_name', self.allowance_types[i][1]); - break; - } - } - if (!item.has('key_display_name')) { - item.set('key_display_name', key); - } - }); - html = this.template({proctored_exam_allowances: this.collection.toJSON()}); - } else { - html = this.template({proctored_exam_allowances: this.collection.toJSON()[0], - allowance_types: self.allowance_types}); - } + html = this.template({proctored_exam_allowances: this.collection.toJSON()[0], + allowance_types: self.allowance_types}); this.$el.html(html); } }, @@ -164,23 +135,13 @@ edx = edx || {}; var self = this; self.proctoredExamCollection.fetch({ success: function() { - if (!self.enableBulkAllowance) { - // eslint-disable-next-line no-new - new edx.instructor_dashboard.proctoring.AddAllowanceView({ - course_id: self.course_id, - proctored_exams: self.proctoredExamCollection.toJSON(), - proctored_exam_allowance_view: self, - allowance_types: self.allowance_types - }); - } else { - // eslint-disable-next-line no-new - new edx.instructor_dashboard.proctoring.AddBulkAllowanceView({ - course_id: self.course_id, - proctored_exams: self.proctoredExamCollection.toJSON(), - proctored_exam_allowance_view: self, - allowance_types: self.allowance_types - }); - } + // eslint-disable-next-line no-new + new edx.instructor_dashboard.proctoring.AddBulkAllowanceView({ + course_id: self.course_id, + proctored_exams: self.proctoredExamCollection.toJSON(), + proctored_exam_allowance_view: self, + allowance_types: self.allowance_types + }); } }); event.stopPropagation(); diff --git a/edx_proctoring/static/proctoring/spec/proctored_exam_add_allowance_spec.js b/edx_proctoring/static/proctoring/spec/proctored_exam_add_allowance_spec.js deleted file mode 100644 index 52b3bfaab54..00000000000 --- a/edx_proctoring/static/proctoring/spec/proctored_exam_add_allowance_spec.js +++ /dev/null @@ -1,396 +0,0 @@ -describe('ProctoredExamAddAllowanceView', function() { - 'use strict'; - - var html = ''; - var allowancesHtml = ''; - var errorAddingAllowance = { - detail: 'Cannot find user' - }; - var expectedProctoredAllowanceJson = [ - { - created: '2015-08-10T09:15:45Z', - id: 1, - modified: '2015-08-10T09:15:45Z', - key: 'additional_time_granted', - value: '1', - proctored_exam: { - content_id: 'i4x://edX/DemoX/sequential/9f5e9b018a244ea38e5d157e0019e60c', - course_id: 'edX/DemoX/Demo_Course', - exam_name: 'Test Exam', - external_id: null, - id: 6, - is_active: true, - is_practice_exam: false, - is_proctored: true, - time_limit_mins: 1 - }, - user: { - username: 'testuser1', - email: 'testuser1@test.com' - } - } - ]; - - var expectedTimedAllowanceJson = [ - { - created: '2015-08-10T09:15:45Z', - id: 1, - modified: '2015-08-10T09:15:45Z', - key: 'additional_time_granted', - value: '1', - proctored_exam: { - content_id: 'i4x://edX/DemoX/sequential/9f5e9b018a244ea38e5d157e0019e60c', - course_id: 'edX/DemoX/Demo_Course', - exam_name: 'Test Exam', - external_id: null, - id: 6, - is_active: true, - is_practice_exam: false, - is_proctored: false, - time_limit_mins: 1 - }, - user: { - username: 'testuser1', - email: 'testuser1@test.com' - } - } - ]; - - var proctoredExamJson = [ - { - exam_name: 'Midterm Exam', - is_proctored: true, - is_practice: false, - id: 5 - }, - { - exam_name: 'Final Exam', - is_proctored: false, - is_practice: false, - id: 6 - }, - { - exam_name: 'Test Exam', - is_proctored: true, - is_practice: true, - id: 7 - } - ]; - - var allowanceTypes = [ - ['additional_time_granted', gettext('Additional Time (minutes)')], - ['review_policy_exception', gettext('Review Policy Exception')] - ]; - - beforeEach(function() { - // We have converted the edx_proctoring/static/proctoring/templates/add-new-allowance.underscore template - // from http://www.howtocreate.co.uk/tutorials/jsexamples/syntax/prepareInline.html - - // eslint-disable-next-line max-len - html = '
<%- gettext("Add a New Allowance") %>
\n
\n

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n \n \n
\n \n \n \n
\n \n \n \n\n \n
\n \n \n \n \n
\n \n \n \n
\n \n
\n\n'; - - allowancesHtml = '' + - '<%- gettext("Allowances") %>' + - ' +' + - '<%- gettext("Add Allowance") %>' + - ' ' + - '<% var is_allowances = proctored_exam_allowances.length !== 0 %>' + - '<% if (is_allowances) { %>' + - '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '<% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %>' + - '' + - '' + - '<% if (proctored_exam_allowance.user){ %>' + - '' + - '' + - '<% }else{ %>' + - '' + - '<% } %>' + - '' + - '' + - '' + - '<% }); %>' + - '
Exam NameUsernameAllowance TypeAllowance ValueActions
' + - '<%- interpolate(gettext(" %(exam_display_name)s "),' + - '{ exam_display_name: proctored_exam_allowance.proctored_exam.exam_name }, true) %>' + - '' + - '<%- interpolate(gettext(" %(username)s "),' + - '{ username: proctored_exam_allowance.user.username }, true) %>' + - '' + - '<%- interpolate(gettext(" %(email)s "),' + - '{ email: proctored_exam_allowance.user.email }, true) %>' + - 'N/AN/A' + - '<%- interpolate(gettext(" %(allowance_name)s "),' + - '{ allowance_name: proctored_exam_allowance.key_display_name }, true) %>' + - '' + - '<%= proctored_exam_allowance.value %>' + - '' + - '[x]' + - '
' + - '<% } %>'; - this.server = sinon.fakeServer.create(); - this.server.autoRespond = true; - - setFixtures('
'); - // load the underscore template response before calling the proctored exam allowance view. - this.server.respondWith('GET', '/static/proctoring/templates/add-new-allowance.underscore', - [ - 200, - {'Content-Type': 'text/html'}, - html - ] - ); - this.server.respondWith('GET', '/static/proctoring/templates/course_allowances.underscore', - [ - 200, - {'Content-Type': 'text/html'}, - allowancesHtml - ] - ); - }); - - afterEach(function() { - this.server.restore(); - }); - it('should render the proctored exam add allowance view properly', function() { - var addAllowanceView; - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - addAllowanceView = new edx.instructor_dashboard.proctoring.AddAllowanceView({ - course_id: 'test_course_id', - proctored_exams: proctoredExamJson, - proctored_exam_allowance_view: this.proctored_exam_allowance, - allowance_types: allowanceTypes - }); - this.server.respond(); - this.server.respond(); - this.server.respond(); - - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Midterm Exam'); - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Final Exam'); - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Test Exam'); - expect(addAllowanceView.$el.find('#exam_type_label')).toExist(); - $('#proctored_exam').val('5'); - $('#proctored_exam').trigger('change'); - expect(addAllowanceView.$el.find('#exam_type_label').html()).toContain('Proctored Exam'); - }); - - - it('should render the timed exam add allowance view properly', function() { - var addAllowanceView; - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedTimedAllowanceJson) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - addAllowanceView = new edx.instructor_dashboard.proctoring.AddAllowanceView({ - course_id: 'test_course_id', - proctored_exams: proctoredExamJson, - proctored_exam_allowance_view: this.proctored_exam_allowance, - allowance_types: allowanceTypes - }); - this.server.respond(); - this.server.respond(); - this.server.respond(); - - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Midterm Exam'); - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Final Exam'); - expect(addAllowanceView.$el.find('#proctored_exam').html()).toContain('Test Exam'); - expect(addAllowanceView.$el.find('#exam_type_label')).toExist(); - $('#proctored_exam').val('6'); - $('#proctored_exam').trigger('change'); - expect(addAllowanceView.$el.find('#exam_type_label').html()).toContain('Timed Exam'); - }); - - - it('should add the proctored exam allowance', function() { - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify([]) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - // eslint-disable-next-line no-new - new edx.instructor_dashboard.proctoring.AddAllowanceView({ - course_id: 'test_course_id', - proctored_exams: proctoredExamJson, - proctored_exam_allowance_view: this.proctored_exam_allowance, - allowance_types: allowanceTypes - }); - - this.server.respond(); - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Additional Time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Test Exam'); - - // add the proctored exam allowance - this.server.respondWith('PUT', '/api/edx_proctoring/v1/proctored_exam/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify([]) - ] - ); - - // again fetch the results after the proctored exam allowance addition - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - // select the form values - - $('#proctored_exam').val('Test Exam'); - $('#allowance_type').val('additional_time_granted'); - $('#allowance_value').val('1'); - $('#user_info').val('testuser1'); - - // trigger the add allowance event. - spyOnEvent('form', 'submit'); - $('form').trigger('submit'); - - // process the deleted allowance requests. - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Additional Time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Test Exam'); - }); - it('should send error when adding proctored exam allowance', function() { - var addAllowanceView; - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify([]) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - addAllowanceView = new edx.instructor_dashboard.proctoring.AddAllowanceView({ - course_id: 'test_course_id', - proctored_exams: proctoredExamJson, - proctored_exam_allowance_view: this.proctored_exam_allowance, - allowance_types: allowanceTypes - }); - - this.server.respond(); - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Additional Time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Test Exam'); - - // add the proctored exam allowance - this.server.respondWith('PUT', '/api/edx_proctoring/v1/proctored_exam/allowance', - [ - 400, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(errorAddingAllowance) - ] - ); - - // again fetch the results after the proctored exam allowance addition - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - // select the form values - // invalid user_info returns error - $('#proctored_exam').val('Test Exam'); - $('#allowance_type').val('additional_time_granted'); - $('#allowance_value').val('2'); - $('#user_info').val('testuser112321'); - - // trigger the add allowance event. - spyOnEvent('form', 'submit'); - $('form').trigger('submit'); - - // process the deleted allowance requests. - this.server.respond(); - this.server.respond(); - - expect(addAllowanceView.$el.find('.error-response').html()).toContain('Cannot find user'); - - // select the form values - // empty value returns error - $('#proctored_exam').val('Test Exam'); - $('#allowance_type').val('Additional Time (minutes)'); - $('#allowance_value').val(''); - $('#user_info').val('testuser1'); - - // trigger the add allowance event. - spyOnEvent('form', 'submit'); - $('form').trigger('submit'); - - expect(addAllowanceView.$el.find('.error-message').html()).toContain('Required field'); - }); -}); diff --git a/edx_proctoring/static/proctoring/spec/proctored_exam_add_bulk_allowance_spec.js b/edx_proctoring/static/proctoring/spec/proctored_exam_add_bulk_allowance_spec.js index 1e3f500c77d..7ca65175090 100644 --- a/edx_proctoring/static/proctoring/spec/proctored_exam_add_bulk_allowance_spec.js +++ b/edx_proctoring/static/proctoring/spec/proctored_exam_add_bulk_allowance_spec.js @@ -143,8 +143,7 @@ describe('ProctoredExamAAllowanceView', function() { this.server = sinon.fakeServer.create(); this.server.autoRespond = true; - setFixtures('
'); + setFixtures('
' + - ' +' + - '<%- gettext("Add Allowance") %>' + - ' ' + - '<% var is_allowances = proctored_exam_allowances.length !== 0 %>' + - '<% if (is_allowances) { %>' + - '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '<% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %>' + - '' + - '' + - '<% if (proctored_exam_allowance.user){ %>' + - '' + - '' + - '<% }else{ %>' + - '' + - '<% } %>' + - '' + - '' + - '' + - '<% }); %>' + - '
Exam NameUsernameAllowance TypeAllowance ValueActions
' + - '<%- interpolate(gettext(" %(exam_display_name)s "),' + - '{ exam_display_name: proctored_exam_allowance.proctored_exam.exam_name }, true) %>' + - '' + - '<%- interpolate(gettext(" %(username)s "), { username: proctored_exam_allowance.user.username }, true) %>' + - '' + - '<%- interpolate(gettext(" %(email)s "), { email: proctored_exam_allowance.user.email }, true) %>' + - 'N/AN/A' + - '<%- interpolate(gettext(" %(allowance_name)s "),' + - '{ allowance_name: proctored_exam_allowance.key_display_name }, true) %>' + - '' + - '<%= proctored_exam_allowance.value %>' + - '' + - '[x]' + - '
' + - '<% } %>'; - this.server = sinon.fakeServer.create(); - this.server.autoRespond = true; - setFixtures('
'); - - // load the underscore template response before calling the proctored exam allowance view. - this.server.respondWith('GET', '/static/proctoring/templates/course_allowances.underscore', - [ - 200, - {'Content-Type': 'text/html'}, - html - ] - ); - }); - - afterEach(function() { - this.server.restore(); - }); - it('should render the proctored exam allowance view properly', function() { - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - this.server.respond(); - this.server.respond(); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Additional time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Test Exam'); - }); - // - it('should remove the proctored exam allowance', function() { - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Additional time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Test Exam'); - - // delete the proctored exam allowance one by one - this.server.respondWith('DELETE', '/api/edx_proctoring/v1/proctored_exam/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify([]) - ] - ); - - // again fetch the results after the proctored exam allowance deletion - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify([]) - ] - ); - - // trigger the remove allowance event. - spyOnEvent('.remove_allowance', 'click'); - $('.remove_allowance').trigger('click'); - - // process the deleted allowance requests. - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Additional time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .not.toContain('Test Exam'); - }); -}); diff --git a/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js b/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js index f71117d669e..dee46fc7611 100644 --- a/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js +++ b/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js @@ -32,8 +32,7 @@ describe('ProctoredExamAllowanceView', function() { html = ' <%- gettext("Allowances") %>\n \n + <%- gettext("Add Allowance") %>\n \n\n<% var is_allowances = proctored_exam_allowances.length !== 0 %>\n<% if (is_allowances) { %>\n\n
\n
\n <% _.each(proctored_exam_allowances, function(student){ %>\n \n \n \n \n \n \n \n \n \n \n <% _.each(student, function(proctored_exam_allowance){ %>\n <% var key = proctored_exam_allowance.key; %>\n <% for (i = 0; i < allowance_types.length; i += 1) { %>\n <% if (key === allowance_types[i][0]) { %>\n <% proctored_exam_allowance.key_display_name = allowance_types[i][1]; %>\n <% break; %>\n <% }} %>\n <% if (!proctored_exam_allowance.key_display_name) { %>\n <% proctored_exam_allowance.key_display_name = key;} %>\n \n \n \n <% }else{ %>\n \n \n <% } %>\n \n \n \n \n <% }); %>\n \n \n <% }); %>\n
\n
\n<% } %>\n'; this.server = sinon.fakeServer.create(); this.server.autoRespond = true; - setFixtures('
'); + setFixtures('
- select#proctored_exam { - width: 100%; - } - - -
-

- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - - - -
- - - - -
- - - -
- -
- diff --git a/edx_proctoring/static/proctoring/templates/course_allowances.underscore b/edx_proctoring/static/proctoring/templates/course_allowances.underscore deleted file mode 100644 index 495270f75b8..00000000000 --- a/edx_proctoring/static/proctoring/templates/course_allowances.underscore +++ /dev/null @@ -1,58 +0,0 @@ - <%- gettext("Allowances") %> - - + <%- gettext("Add Allowance") %> - - -<% var is_allowances = proctored_exam_allowances.length !== 0 %> -<% if (is_allowances) { %> - -
-
- - - - - - - - - - - - - <% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %> - - - <% if (proctored_exam_allowance.user){ %> - - - <% }else{ %> - - - <% } %> - - - - - <% }); %> - -
<%- gettext("Exam Name") %><%- gettext("Username") %><%- gettext("Allowance Type") %> <%- gettext("Allowance Value") %><%- gettext("Actions") %>
- <%- proctored_exam_allowance.proctored_exam.exam_name %> - - <%= proctored_exam_allowance.user.username %> - - <%= proctored_exam_allowance.user.email %> - N/AN/A - <%= proctored_exam_allowance.key_display_name %> - - <%- proctored_exam_allowance.value %> - [x] -
-
-
-<% } %> - - From afafaf8be231b13105927e46cd3b24e2d9d4c882 Mon Sep 17 00:00:00 2001 From: mohtamba Date: Mon, 16 Aug 2021 15:04:21 -0400 Subject: [PATCH 2/3] Update version and Changelog Update version number and add changes to changelog --- CHANGELOG.rst | 4 ++++ edx_proctoring/__init__.py | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e8fd22fe11..265dca68c41 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ~~~~~~~~~~ +[3.23.3] - 2021-08-16 +~~~~~~~~~~~~~~~~~~~~~ +* Remove the old allowance code entirely, so only the bulk allowance modal is used. + [3.23.2] - 2021-08-06 ~~~~~~~~~~~~~~~~~~~~~ * Change errors on the bulk allowance modal so they appear on their associated field. diff --git a/edx_proctoring/__init__.py b/edx_proctoring/__init__.py index b5c9e703502..4f5c3353a6b 100644 --- a/edx_proctoring/__init__.py +++ b/edx_proctoring/__init__.py @@ -3,6 +3,6 @@ """ # Be sure to update the version number in edx_proctoring/package.json -__version__ = '3.23.2' +__version__ = '3.23.3' default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name diff --git a/package.json b/package.json index 541ec4ef25f..4418ed7ec5f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@edx/edx-proctoring", "//": "Note that the version format is slightly different than that of the Python version when using prereleases.", - "version": "3.23.2", + "version": "3.23.3", "main": "edx_proctoring/static/index.js", "scripts": { "test": "gulp test" From 4909bc8f1bdac6de0dd0d3b9c04392a1b47113c2 Mon Sep 17 00:00:00 2001 From: mohtamba Date: Tue, 17 Aug 2021 08:26:55 -0400 Subject: [PATCH 3/3] Fix bulk allowance JS tests --- .../proctored_exam_bulk_allowance_spec.js | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js b/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js index dee46fc7611..438292bb417 100644 --- a/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js +++ b/edx_proctoring/static/proctoring/spec/proctored_exam_bulk_allowance_spec.js @@ -3,7 +3,7 @@ describe('ProctoredExamAllowanceView', function() { var html = ''; var expectedProctoredAllowanceJson = [{ - student: [{ + testuser1: [{ created: '2015-08-10T09:15:45Z', id: 1, modified: '2015-08-10T09:15:45Z', @@ -32,7 +32,7 @@ describe('ProctoredExamAllowanceView', function() { html = ' <%- gettext("Allowances") %>\n \n + <%- gettext("Add Allowance") %>\n \n\n<% var is_allowances = proctored_exam_allowances.length !== 0 %>\n<% if (is_allowances) { %>\n\n
\n
\n <% _.each(proctored_exam_allowances, function(student){ %>\n \n \n \n \n \n \n \n \n \n \n <% _.each(student, function(proctored_exam_allowance){ %>\n <% var key = proctored_exam_allowance.key; %>\n <% for (i = 0; i < allowance_types.length; i += 1) { %>\n <% if (key === allowance_types[i][0]) { %>\n <% proctored_exam_allowance.key_display_name = allowance_types[i][1]; %>\n <% break; %>\n <% }} %>\n <% if (!proctored_exam_allowance.key_display_name) { %>\n <% proctored_exam_allowance.key_display_name = key;} %>\n \n \n \n <% }else{ %>\n \n \n <% } %>\n \n \n \n \n <% }); %>\n \n \n <% }); %>\n
\n
\n<% } %>\n'; this.server = sinon.fakeServer.create(); this.server.autoRespond = true; - setFixtures('
'); // load the underscore template response before calling the proctored exam allowance view. this.server.respondWith('GET', '/static/proctoring/templates/course_grouped_allowances.underscore', @@ -61,34 +61,6 @@ describe('ProctoredExamAllowanceView', function() { this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); this.server.respond(); this.server.respond(); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1@test.com'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Additional time (minutes)'); - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('Test Exam'); - }); - // - it('should remove the proctored exam allowance', function() { - this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/grouped/allowance', - [ - 200, - { - 'Content-Type': 'application/json' - }, - JSON.stringify(expectedProctoredAllowanceJson) - ] - ); - - this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView(); - - this.server.respond(); - this.server.respond(); - - expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) - .toContain('testuser1'); expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()) .toContain('testuser1@test.com'); expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html())