From aca292de359280b324e38c26fa4c3c9273c292a1 Mon Sep 17 00:00:00 2001 From: asadiqbal Date: Tue, 8 Dec 2015 16:38:38 +0500 Subject: [PATCH] SOL-1490 --- lms/djangoapps/instructor/views/api.py | 2 +- .../certificates_bulk_exception_spec.js | 145 ++++++++++++++++++ lms/static/js/spec/main.js | 1 + 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 53035e8e69..bab6c47f89 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -2949,7 +2949,7 @@ def generate_bulk_certificate_exceptions(request, course_id): # pylint: disable """ inner method to build dict of csv data as row errors. """ - row_errors[key].append(_('user "{user}" in row# {row}').format(user=_user, row=row_count)) + row_errors[key].append(_('user "{user}" in row# {row}').format(user=_user, row=row_count)) if 'students_list' in request.FILES: try: diff --git a/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js b/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js new file mode 100644 index 0000000000..ce9d81658c --- /dev/null +++ b/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js @@ -0,0 +1,145 @@ +define([ + 'jquery', + 'js/certificates/views/certificate_bulk_whitelist' + ], + function($, CertificateBulkWhiteListView) { + 'use strict'; + describe("certificate bulk exceptions generation", function() { + + var certificate_bulk_exception_url = 'test/url/'; + var SELECTORS = { + upload_csv_button: ".upload-csv-button", + bulk_white_list_exception_form: "form#bulk-white-list-exception-form", + bulk_exception_results: ".bulk-exception-results" + }; + beforeEach(function() { + setFixtures(); + var fixture = readFixtures( + "templates/instructor/instructor_dashboard_2/certificate-bulk-white-list.underscore" + ); + + setFixtures( + "" + + "
" + ); + + this.view = new CertificateBulkWhiteListView({ + bulk_exception_url: certificate_bulk_exception_url + }); + this.view.render(); + }); + + it('bind the ajax call and the result will be success', function() { + var submitCallback; + spyOn($, "ajax").andCallFake(function(params) { + params.success({ + row_errors: {}, + general_errors: [], + success: ["user test in row# 1"] + }); + return { + always: function() {} + }; + }); + submitCallback = jasmine.createSpy().andReturn(); + this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); + this.view.$el.find(SELECTORS.upload_csv_button).click(); + expect($(SELECTORS.bulk_exception_results).text()).toContain('1 learner is successfully added to the ' + + 'exception list'); + }); + + it('bind the ajax call and the result will be general error', function() { + var submitCallback; + spyOn($, "ajax").andCallFake(function(params) { + params.success({ + row_errors: {}, + general_errors: ["File is not attached."], + success: [] + }); + return { + always: function() {} + }; + }); + submitCallback = jasmine.createSpy().andReturn(); + this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); + this.view.$el.find(SELECTORS.upload_csv_button).click(); + expect($(SELECTORS.bulk_exception_results).text()).toContain('File is not attached.'); + }); + + it('bind the ajax call and the result will be singular form of row errors', function() { + var submitCallback; + spyOn($, "ajax").andCallFake(function(params) { + params.success({ + general_errors: [], + row_errors: { + data_format_error: ['user 1 in row# 1'], + user_not_exist: ['user 2 in row# 2'], + user_already_white_listed: ['user 3 in row# 3'], + user_not_enrolled: ['user 4 in row# 4'] + }, + success: [] + }); + return { + always: function() {} + }; + }); + submitCallback = jasmine.createSpy().andReturn(); + this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); + this.view.$el.find(SELECTORS.upload_csv_button).click(); + expect($(SELECTORS.bulk_exception_results).text()).toContain('1 record is not in correct format'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('1 learner does not exist in LMS'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('1 learner is already white listed'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('1 learner is not enrolled in course'); + + }); + + it('bind the ajax call and the result will be plural form of row errors', function() { + var submitCallback; + spyOn($, "ajax").andCallFake(function(params) { + params.success({ + general_errors: [], + row_errors: { + data_format_error: ['user 1 in row# 1', 'user 1 in row# 1'], + user_not_exist: ['user 2 in row# 2', 'user 2 in row# 2'], + user_already_white_listed: ['user 3 in row# 3', 'user 3 in row# 3'], + user_not_enrolled: ['user 4 in row# 4', 'user 4 in row# 4'] + }, + success: [] + }); + return { + always: function() {} + }; + }); + submitCallback = jasmine.createSpy().andReturn(); + this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); + this.view.$el.find(SELECTORS.upload_csv_button).click(); + expect($(SELECTORS.bulk_exception_results).text()).toContain('2 records are not in correct format'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('2 learners do not exist in LMS'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('2 learners are already white listed'); + expect($(SELECTORS.bulk_exception_results).text()).toContain('2 learners are not enrolled in course'); + + }); + + it('toggle message details', function() { + var submitCallback; + spyOn($, "ajax").andCallFake(function(params) { + params.success({ + row_errors: {}, + general_errors: [], + success: ["user test in row# 1"] + }); + return { + always: function() {} + }; + }); + submitCallback = jasmine.createSpy().andReturn(); + this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); + this.view.$el.find(SELECTORS.upload_csv_button).click(); + expect(this.view.$el.find("div.message > .successfully-added")).toBeHidden(); + this.view.$el.find("a.arrow#successfully-added").trigger( "click" ); + expect(this.view.$el.find("div.message > .successfully-added")).toBeVisible(); + + }); + + }); + }); diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index d6fe7bd31f..a94e006ce6 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -648,6 +648,7 @@ 'lms/include/js/spec/instructor_dashboard/ecommerce_spec.js', 'lms/include/js/spec/instructor_dashboard/student_admin_spec.js', 'lms/include/js/spec/instructor_dashboard/certificates_exception_spec.js', + 'lms/include/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js', 'lms/include/js/spec/instructor_dashboard/certificates_spec.js', 'lms/include/js/spec/student_account/account_spec.js', 'lms/include/js/spec/student_account/access_spec.js',