Commit ca0d048b by Renzo Lucioni Committed by AlasdairSwan

Fix failing JS tests

parent 0b9ed031
...@@ -263,13 +263,20 @@ ...@@ -263,13 +263,20 @@
// Student account registration/login // Student account registration/login
// Loaded explicitly until these are converted to RequireJS // 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': { 'js/student_account/models/LoginModel': {
exports: 'js/student_account/models/LoginModel', exports: 'js/student_account/models/LoginModel',
deps: ['jquery', 'underscore', 'backbone', 'gettext', 'jquery.cookie'] deps: ['jquery', 'underscore', 'backbone', 'gettext', 'jquery.cookie']
}, },
'js/student_account/views/LoginView': { 'js/student_account/views/LoginView': {
exports: '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': { 'js/student_account/models/PasswordResetModel': {
exports: 'js/student_account/models/PasswordResetModel', exports: 'js/student_account/models/PasswordResetModel',
...@@ -277,7 +284,10 @@ ...@@ -277,7 +284,10 @@
}, },
'js/student_account/views/PasswordResetView': { 'js/student_account/views/PasswordResetView': {
exports: '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': { 'js/student_account/models/RegisterModel': {
exports: 'js/student_account/models/RegisterModel', exports: 'js/student_account/models/RegisterModel',
...@@ -285,7 +295,10 @@ ...@@ -285,7 +295,10 @@
}, },
'js/student_account/views/RegisterView': { 'js/student_account/views/RegisterView': {
exports: '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': { 'js/student_account/views/AccessView': {
exports: 'js/student_account/views/AccessView', exports: 'js/student_account/views/AccessView',
......
...@@ -4,11 +4,21 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password ...@@ -4,11 +4,21 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password
'use strict'; 'use strict';
var view = null, 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) { var submitEmail = function(validationSuccess) {
// Simulate manual entry of an email address // 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 // Create a fake click event
var clickEvent = $.Event('click'); var clickEvent = $.Event('click');
...@@ -16,7 +26,10 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password ...@@ -16,7 +26,10 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password
// Used to avoid spying on view.validate twice // Used to avoid spying on view.validate twice
if (typeof validationSuccess !== 'undefined') { if (typeof validationSuccess !== 'undefined') {
// Force validation to return as expected // 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 // Submit the email address
...@@ -43,12 +56,15 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password ...@@ -43,12 +56,15 @@ define(['js/common_helpers/template_helpers', 'js/student_account/views/Password
if (ajaxSuccess) { if (ajaxSuccess) {
defer.resolve(); defer.resolve();
} else { } else {
defer.reject(); defer.rejectWith(this, ["The server could not be contacted."]);
} }
}).promise(); }).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() { 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 ...@@ -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 // If we get an error status on the AJAX request, display an error
ajaxSuccess = false; ajaxSuccess = false;
submitEmail(true); 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 // If we try again and succeed, the error should go away
ajaxSuccess = true; ajaxSuccess = true;
// No argument means we won't spy on view.validate again // No argument means we won't spy on view.validate again
submitEmail(); submitEmail();
expect(view.$resetFail).toHaveClass('hidden'); expect(view.$'#submission-error').toHaveClass('hidden');
}); });
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment