From c8fbadb24a139a87b69c4ae92981409008abe532 Mon Sep 17 00:00:00 2001 From: Peter Fogg Date: Fri, 13 Nov 2015 14:53:24 -0500 Subject: [PATCH] Show a message when logging in with no internet connection. ECOM-2890 --- lms/static/js/spec/student_account/login_spec.js | 15 +++++++++++++++ lms/static/js/student_account/views/LoginView.js | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lms/static/js/spec/student_account/login_spec.js b/lms/static/js/spec/student_account/login_spec.js index f66a4d60e1..f95e1a9d00 100644 --- a/lms/static/js/spec/student_account/login_spec.js +++ b/lms/static/js/spec/student_account/login_spec.js @@ -265,6 +265,21 @@ expect(view.$errors).toHaveClass('hidden'); expect(authComplete).toBe(true); }); + + it('displays an error if there is no internet connection', function () { + createLoginView(this); + + // Submit the form, with successful validation + submitForm(true); + + // Simulate an error from the LMS servers + AjaxHelpers.respondWithError(requests, 0); + + // Expect that an error is displayed and that auth complete is not triggered + expect(view.$errors).not.toHaveClass('hidden'); + expect(authComplete).toBe(false); + expect(view.$errors.text()).toContain('Please check your internet connection and try again.'); + }); }); }); }).call(this, define || RequireJS.define); diff --git a/lms/static/js/student_account/views/LoginView.js b/lms/static/js/student_account/views/LoginView.js index e4509b20eb..68ff04fa1b 100644 --- a/lms/static/js/student_account/views/LoginView.js +++ b/lms/static/js/student_account/views/LoginView.js @@ -3,9 +3,10 @@ define([ 'jquery', 'underscore', + 'gettext', 'js/student_account/views/FormView' ], - function($, _, FormView) { + function($, _, gettext, FormView) { return FormView.extend({ el: '#login-form', @@ -102,7 +103,12 @@ }, saveError: function( error ) { - this.errors = ['
  • ' + error.responseText + '
  • ']; + if (error.status === 0) { + this.errors = ['
  • ' + gettext('Please check your internet connection and try again.') + '
  • ']; + } + else { + this.errors = ['
  • ' + error.responseText + '
  • ']; + } this.setErrors(); this.element.hide( this.$resetSuccess );