diff --git a/lms/static/js/spec/student_account/login_spec.js b/lms/static/js/spec/student_account/login_spec.js index 45004d07ac..428e09d340 100644 --- a/lms/static/js/spec/student_account/login_spec.js +++ b/lms/static/js/spec/student_account/login_spec.js @@ -134,6 +134,9 @@ define([ // Submit the form, with successful validation submitForm(true); + // Form button should be disabled on success. + expect(view.$submitButton).toHaveAttr('disabled'); + // Verify that the client contacts the server with the expected data AjaxHelpers.expectRequest( requests, 'POST', @@ -213,6 +216,8 @@ define([ // Expect auth complete NOT to have been triggered expect(authComplete).toBe(false); + // Form button should be re-enabled when errors occur + expect(view.$submitButton).not.toHaveAttr('disabled'); }); it('displays an error if the server returns an error while logging in', function() { @@ -227,10 +232,15 @@ define([ // Expect that an error is displayed and that auth complete is not triggered expect(view.$errors).not.toHaveClass('hidden'); expect(authComplete).toBe(false); + // Form button should be re-enabled on server failure. + expect(view.$submitButton).not.toHaveAttr('disabled'); // If we try again and succeed, the error should go away submitForm(); + // Form button should be disabled on success. + expect(view.$submitButton).toHaveAttr('disabled'); + // This time, respond with status code 200 AjaxHelpers.respondWithJson(requests, {}); diff --git a/lms/static/js/spec/student_account/register_spec.js b/lms/static/js/spec/student_account/register_spec.js index 07fada7427..cd6d59ea7b 100644 --- a/lms/static/js/spec/student_account/register_spec.js +++ b/lms/static/js/spec/student_account/register_spec.js @@ -242,6 +242,8 @@ define([ // Verify that auth complete is triggered expect(authComplete).toBe(true); + // Form button should be disabled on success. + expect(view.$submitButton).toHaveAttr('disabled'); }); it('sends analytics info containing the enrolled course ID', function() { @@ -295,6 +297,8 @@ define([ // Verify that no submission errors are visible expect(view.$errors).toHaveClass('hidden'); + // Form button should be disabled on success. + expect(view.$submitButton).toHaveAttr('disabled'); }); it('displays registration form validation errors', function() { @@ -308,6 +312,8 @@ define([ // Expect that auth complete is NOT triggered expect(authComplete).toBe(false); + // Form button should be re-enabled on error. + expect(view.$submitButton).not.toHaveAttr('disabled'); }); it('displays an error if the server returns an error while registering', function() { @@ -332,6 +338,8 @@ define([ // Expect that the error is hidden and that auth complete is triggered expect(view.$errors).toHaveClass('hidden'); expect(authComplete).toBe(true); + // Form button should be disabled on success. + expect(view.$submitButton).toHaveAttr('disabled'); }); }); }); diff --git a/lms/static/js/student_account/views/FormView.js b/lms/static/js/student_account/views/FormView.js index 5c65006128..9142eb9284 100644 --- a/lms/static/js/student_account/views/FormView.js +++ b/lms/static/js/student_account/views/FormView.js @@ -28,6 +28,8 @@ var edx = edx || {}; // String to append to required label fields requiredStr: '*', + submitButton: '', + initialize: function( data ) { this.model = data.model; this.preRender( data ); @@ -65,6 +67,7 @@ var edx = edx || {}; this.$form = $container.find('form'); this.$errors = $container.find('.submission-error'); + this.$submitButton = $container.find(this.submitButton); }, buildForm: function( data ) { @@ -178,6 +181,7 @@ var edx = edx || {}; saveError: function( error ) { this.errors = ['