From ca0d048b4f5b75373ecd1edf7f85a821400fed70 Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Mon, 27 Oct 2014 13:29:30 -0400 Subject: [PATCH] Fix failing JS tests --- lms/static/js/spec/main.js | 19 ++++++++++-- .../student_account/password_reset_spec.js | 30 ++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index f5ecdb181a..acdb4b9565 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -263,13 +263,20 @@ // Student account registration/login // Loaded explicitly until these are converted to RequireJS + 'js/student_account/views/FormView': { + exports: 'js/student_account/views/FormView', + deps: ['jquery', 'underscore', 'backbone', 'gettext'] + }, 'js/student_account/models/LoginModel': { exports: 'js/student_account/models/LoginModel', deps: ['jquery', 'underscore', 'backbone', 'gettext', 'jquery.cookie'] }, 'js/student_account/views/LoginView': { exports: 'js/student_account/views/LoginView', - deps: ['js/student_account/models/LoginModel'] + deps: [ + 'js/student_account/models/LoginModel', + 'js/student_account/views/FormView' + ] }, 'js/student_account/models/PasswordResetModel': { exports: 'js/student_account/models/PasswordResetModel', @@ -277,7 +284,10 @@ }, 'js/student_account/views/PasswordResetView': { exports: 'js/student_account/views/PasswordResetView', - deps: ['js/student_account/models/PasswordResetModel'] + deps: [ + 'js/student_account/models/PasswordResetModel', + 'js/student_account/views/FormView' + ] }, 'js/student_account/models/RegisterModel': { exports: 'js/student_account/models/RegisterModel', @@ -285,7 +295,10 @@ }, 'js/student_account/views/RegisterView': { exports: 'js/student_account/views/RegisterView', - deps: ['js/student_account/models/RegisterModel'] + deps: [ + 'js/student_account/models/RegisterModel', + 'js/student_account/views/FormView' + ] }, 'js/student_account/views/AccessView': { exports: 'js/student_account/views/AccessView', diff --git a/lms/static/js/spec/student_account/password_reset_spec.js b/lms/static/js/spec/student_account/password_reset_spec.js index 9b2662a58d..ce8dbe69b5 100644 --- a/lms/static/js/spec/student_account/password_reset_spec.js +++ b/lms/static/js/spec/student_account/password_reset_spec.js @@ -4,11 +4,21 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password 'use strict'; var view = null, - ajaxSuccess = true; + ajaxSuccess = true, + model = new edx.student.account.PasswordResetModel(), + data = [{ + label: 'E-mail', + instructions: 'This is the e-mail address you used to register with edX', + name: 'email', + required: true, + type: 'email', + restrictions: [], + defaultValue: '' + }]; var submitEmail = function(validationSuccess) { // Simulate manual entry of an email address - $('#reset-password-email').val('foo@bar.baz'); + $('#password-reset-email').val('foo@bar.baz'); // Create a fake click event var clickEvent = $.Event('click'); @@ -16,7 +26,10 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password // Used to avoid spying on view.validate twice if (typeof validationSuccess !== 'undefined') { // Force validation to return as expected - spyOn(view, 'validate').andReturn(validationSuccess); + spyOn(view, 'validate').andReturn({ + isValid: validationSuccess, + message: "We're all good." + }); } // Submit the email address @@ -43,12 +56,15 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password if (ajaxSuccess) { defer.resolve(); } else { - defer.reject(); + defer.rejectWith(this, ["The server could not be contacted."]); } }).promise(); }); - view = new edx.student.account.PasswordResetView(); + view = new edx.student.account.PasswordResetView({ + fields: data, + model: model + }); }); it("allows the user to request a new password", function() { @@ -72,13 +88,13 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password // If we get an error status on the AJAX request, display an error ajaxSuccess = false; submitEmail(true); - expect(view.$resetFail).not.toHaveClass('hidden'); + expect(view.$'#submission-error').not.toHaveClass('hidden'); // If we try again and succeed, the error should go away ajaxSuccess = true; // No argument means we won't spy on view.validate again submitEmail(); - expect(view.$resetFail).toHaveClass('hidden'); + expect(view.$'#submission-error').toHaveClass('hidden'); }); }); }