Resolving JS lint errors for account settings & learner profile page.
TNL-1855
This commit is contained in:
committed by
Andy Armstrong
parent
f03841a6bb
commit
bc05cd0ccd
@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'js/student_account/views/account_settings_view'
|
||||
],
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViewsSpecHelpers, Helpers,
|
||||
AccountSettingsFieldViewSpecHelpers, AccountSettingsPage, AccountSettingsView) {
|
||||
AccountSettingsFieldViewSpecHelpers, AccountSettingsPage) {
|
||||
'use strict';
|
||||
|
||||
describe("edx.user.AccountSettingsFactory", function () {
|
||||
@@ -44,7 +44,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'disconnect_url': 'yetanother2.com/auth/disconnect'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
var requests;
|
||||
|
||||
@@ -103,7 +103,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
|
||||
Helpers.expectSettingsSectionsButNotFieldsToBeRendered(accountSettingsView);
|
||||
|
||||
var request = requests[1];
|
||||
request = requests[1];
|
||||
expect(request.method).toBe('GET');
|
||||
expect(request.url).toBe(Helpers.USER_PREFERENCES_API_URL);
|
||||
|
||||
@@ -131,7 +131,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
|
||||
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false);
|
||||
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
|
||||
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView)
|
||||
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView);
|
||||
});
|
||||
|
||||
it("expects all fields to behave correctly", function () {
|
||||
|
||||
@@ -22,7 +22,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
view.$(selector).click();
|
||||
FieldViewsSpecHelpers.expectMessageContains(view, 'Linking');
|
||||
expect(view.redirect_to).toHaveBeenCalledWith(data.connectUrl);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
verifyAuthField: verifyAuthField
|
||||
|
||||
@@ -6,7 +6,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'js/student_account/models/user_account_model',
|
||||
'string_utils'],
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, FieldViews, FieldViewsSpecHelpers,
|
||||
AccountSettingsFieldViewSpecHelpers, AccountSettingsFieldViews, UserAccountModel) {
|
||||
AccountSettingsFieldViewSpecHelpers, AccountSettingsFieldViews) {
|
||||
'use strict';
|
||||
|
||||
describe("edx.AccountSettingsFieldViews", function () {
|
||||
@@ -14,10 +14,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
var requests,
|
||||
timerCallback;
|
||||
|
||||
var USERNAME = 'Legolas',
|
||||
FULLNAME = 'Legolas Thranduil',
|
||||
EMAIL = 'legolas@woodland.middlearth';
|
||||
|
||||
beforeEach(function () {
|
||||
TemplateHelpers.installTemplate('templates/fields/field_readonly');
|
||||
TemplateHelpers.installTemplate('templates/fields/field_dropdown');
|
||||
@@ -39,9 +35,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
var view = new AccountSettingsFieldViews.PasswordFieldView(fieldData).render();
|
||||
view.$('.u-field-value > a').click();
|
||||
AjaxHelpers.expectRequest(requests, 'POST', '/password_reset', "email=legolas%40woodland.middlearth");
|
||||
AjaxHelpers.respondWithJson(requests, {"success": "true"})
|
||||
FieldViewsSpecHelpers.expectMessageContains(view,
|
||||
"We've sent a message to legolas@woodland.middlearth. Click the link in the message to reset your password."
|
||||
AjaxHelpers.respondWithJson(requests, {"success": "true"});
|
||||
FieldViewsSpecHelpers.expectMessageContains(
|
||||
view,
|
||||
"We've sent a message to legolas@woodland.middlearth. " +
|
||||
"Click the link in the message to reset your password."
|
||||
);
|
||||
});
|
||||
|
||||
@@ -61,18 +59,31 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data);
|
||||
AjaxHelpers.respondWithNoContent(requests);
|
||||
|
||||
AjaxHelpers.expectRequest(requests, 'POST', '/i18n/setlang/', 'language=' + data[fieldData.valueAttribute]);
|
||||
AjaxHelpers.expectRequest(
|
||||
requests,
|
||||
'POST',
|
||||
'/i18n/setlang/',
|
||||
'language=' + data[fieldData.valueAttribute]
|
||||
);
|
||||
AjaxHelpers.respondWithNoContent(requests);
|
||||
FieldViewsSpecHelpers.expectMessageContains(view, "Your changes have been saved.");
|
||||
|
||||
var data = {'language': FieldViewsSpecHelpers.SELECT_OPTIONS[1][0]};
|
||||
data = {'language': FieldViewsSpecHelpers.SELECT_OPTIONS[1][0]};
|
||||
view.$(selector).val(data[fieldData.valueAttribute]).change();
|
||||
FieldViewsSpecHelpers.expectAjaxRequestWithData(requests, data);
|
||||
AjaxHelpers.respondWithNoContent(requests);
|
||||
|
||||
AjaxHelpers.expectRequest(requests, 'POST', '/i18n/setlang/', 'language=' + data[fieldData.valueAttribute]);
|
||||
AjaxHelpers.expectRequest(
|
||||
requests,
|
||||
'POST',
|
||||
'/i18n/setlang/',
|
||||
'language=' + data[fieldData.valueAttribute]
|
||||
);
|
||||
AjaxHelpers.respondWithError(requests, 500);
|
||||
FieldViewsSpecHelpers.expectMessageContains(view, "You must sign out of edX and sign back in before your language changes take effect.");
|
||||
FieldViewsSpecHelpers.expectMessageContains(
|
||||
view,
|
||||
"You must sign out of edX and sign back in before your language changes take effect."
|
||||
);
|
||||
});
|
||||
|
||||
it("reads and saves the value correctly for LanguageProficienciesFieldView", function() {
|
||||
|
||||
@@ -4,7 +4,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'js/student_account/models/user_account_model',
|
||||
'js/student_account/views/account_settings_view'
|
||||
],
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, FieldViews, UserAccountModel, AccountSettingsView) {
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, FieldViews, UserAccountModel,
|
||||
AccountSettingsView) {
|
||||
'use strict';
|
||||
|
||||
describe("edx.user.AccountSettingsView", function () {
|
||||
@@ -47,7 +48,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
var accountSettingsView = new AccountSettingsView({
|
||||
el: $('.wrapper-account-settings'),
|
||||
@@ -94,7 +95,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
accountSettingsView.renderFields();
|
||||
Helpers.expectLoadingIndicatorIsVisible(accountSettingsView, false);
|
||||
Helpers.expectLoadingErrorIsVisible(accountSettingsView, false);
|
||||
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView)
|
||||
Helpers.expectSettingsSectionsAndFieldsToBeRendered(accountSettingsView);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -46,7 +46,10 @@ define(['underscore'], function(_) {
|
||||
expect(sectionOneFieldElements.length).toBe(learnerProfileView.options.sectionOneFieldViews.length);
|
||||
|
||||
_.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) {
|
||||
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionOneFieldViews[fieldIndex]);
|
||||
expectProfileElementContainsField(
|
||||
sectionFieldElement,
|
||||
learnerProfileView.options.sectionOneFieldViews[fieldIndex]
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -58,7 +61,10 @@ define(['underscore'], function(_) {
|
||||
expect(sectionTwoFieldElements.length).toBe(learnerProfileView.options.sectionTwoFieldViews.length);
|
||||
|
||||
_.each(sectionTwoFieldElements, function (sectionFieldElement, fieldIndex) {
|
||||
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionTwoFieldViews[fieldIndex]);
|
||||
expectProfileElementContainsField(
|
||||
sectionFieldElement,
|
||||
learnerProfileView.options.sectionTwoFieldViews[fieldIndex]
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -75,13 +81,17 @@ define(['underscore'], function(_) {
|
||||
|
||||
expect(sectionOneFieldElements.length).toBe(1);
|
||||
_.each(sectionOneFieldElements, function (sectionFieldElement, fieldIndex) {
|
||||
expectProfileElementContainsField(sectionFieldElement, learnerProfileView.options.sectionOneFieldViews[fieldIndex]);
|
||||
expectProfileElementContainsField(
|
||||
sectionFieldElement,
|
||||
learnerProfileView.options.sectionOneFieldViews[fieldIndex]
|
||||
);
|
||||
});
|
||||
|
||||
if (othersProfile) {
|
||||
expect($('.profile-private--message').text()).toBe('This edX learner is currently sharing a limited profile.')
|
||||
expect($('.profile-private--message').text())
|
||||
.toBe('This edX learner is currently sharing a limited profile.');
|
||||
} else {
|
||||
expect($('.profile-private--message').text()).toBe('You are currently sharing a limited profile.')
|
||||
expect($('.profile-private--message').text()).toBe('You are currently sharing a limited profile.');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'js/student_profile/views/learner_profile_fields',
|
||||
'js/student_profile/views/learner_profile_factory'
|
||||
],
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews, UserAccountModel, UserPreferencesModel,
|
||||
LearnerProfileView, LearnerProfileFields, LearnerProfilePage) {
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews,
|
||||
UserAccountModel, UserPreferencesModel, LearnerProfileView, LearnerProfileFields, LearnerProfilePage) {
|
||||
'use strict';
|
||||
|
||||
describe("edx.user.LearnerProfileFactory", function () {
|
||||
@@ -33,7 +33,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'country_options': Helpers.FIELD_OPTIONS,
|
||||
'language_options': Helpers.FIELD_OPTIONS,
|
||||
'has_preferences_access': true
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
it("show loading error when UserAccountModel fails to load", function() {
|
||||
@@ -91,7 +91,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
|
||||
|
||||
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView)
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
|
||||
});
|
||||
|
||||
it("renders the full profile after models are successfully fetched", function() {
|
||||
@@ -102,15 +102,15 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
learnerProfileView = context.learnerProfileView;
|
||||
|
||||
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
|
||||
accountSettingsData['year_of_birth'] = 1989;
|
||||
accountSettingsData['requires_parental_consent'] = false;
|
||||
accountSettingsData.year_of_birth = 1989;
|
||||
accountSettingsData.requires_parental_consent = false;
|
||||
|
||||
AjaxHelpers.respondWithJson(requests, accountSettingsData);
|
||||
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
|
||||
|
||||
// sets the profile for full view.
|
||||
context.accountPreferencesModel.set({account_privacy: 'all_users'});
|
||||
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false)
|
||||
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, false);
|
||||
});
|
||||
|
||||
it("renders the limited profile for undefined 'year_of_birth'", function() {
|
||||
@@ -123,7 +123,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
AjaxHelpers.respondWithJson(requests, Helpers.USER_ACCOUNTS_DATA);
|
||||
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
|
||||
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView)
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
|
||||
});
|
||||
|
||||
it("renders the limited profile for under 13 users", function() {
|
||||
@@ -134,12 +134,12 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
learnerProfileView = context.learnerProfileView;
|
||||
|
||||
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
|
||||
accountSettingsData['requires_parental_consent'] = true;
|
||||
accountSettingsData.requires_parental_consent = true;
|
||||
|
||||
AjaxHelpers.respondWithJson(requests, accountSettingsData);
|
||||
AjaxHelpers.respondWithJson(requests, Helpers.USER_PREFERENCES_DATA);
|
||||
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView)
|
||||
LearnerProfileHelpers.expectLimitedProfileSectionsAndFieldsToBeRendered(learnerProfileView);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,8 +8,9 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'js/student_profile/views/learner_profile_view',
|
||||
'js/student_account/views/account_settings_fields'
|
||||
],
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews, UserAccountModel,
|
||||
AccountPreferencesModel, LearnerProfileFields, LearnerProfileView, AccountSettingsFieldViews) {
|
||||
function (Backbone, $, _, AjaxHelpers, TemplateHelpers, Helpers, LearnerProfileHelpers, FieldViews,
|
||||
UserAccountModel, AccountPreferencesModel, LearnerProfileFields, LearnerProfileView,
|
||||
AccountSettingsFieldViews) {
|
||||
'use strict';
|
||||
|
||||
describe("edx.user.LearnerProfileView", function () {
|
||||
@@ -18,8 +19,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
|
||||
var accountSettingsModel = new UserAccountModel();
|
||||
var accountSettingsData = Helpers.USER_ACCOUNTS_DATA;
|
||||
accountSettingsData['year_of_birth'] = 1989;
|
||||
accountSettingsData['requires_parental_consent'] = false;
|
||||
accountSettingsData.year_of_birth = 1989;
|
||||
accountSettingsData.requires_parental_consent = false;
|
||||
accountSettingsModel.set(accountSettingsData);
|
||||
accountSettingsModel.set({'profile_is_public': profileIsPublic});
|
||||
|
||||
@@ -84,7 +85,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
editable: editable,
|
||||
showMessages: false,
|
||||
title: 'About me',
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you're taking courses on edX, or what you hope to learn.",
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
|
||||
"what your interests are, why you're taking courses on edX, or what you hope to learn.",
|
||||
valueAttribute: "bio",
|
||||
helpMessage: ''
|
||||
})
|
||||
@@ -102,7 +104,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
sectionOneFieldViews: sectionOneFieldViews,
|
||||
sectionTwoFieldViews: sectionTwoFieldViews
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -162,7 +163,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
learnerProfileView.render();
|
||||
|
||||
Helpers.expectLoadingErrorIsVisible(learnerProfileView, false);
|
||||
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, true)
|
||||
LearnerProfileHelpers.expectProfileSectionsAndFieldsToBeRendered(learnerProfileView, true);
|
||||
});
|
||||
|
||||
it("renders the fields as expected for others with limited access", function() {
|
||||
|
||||
@@ -50,13 +50,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
};
|
||||
|
||||
var createErrorMessage = function(attribute, user_message) {
|
||||
var field_errors = {}
|
||||
var field_errors = {};
|
||||
field_errors[attribute] = {
|
||||
"user_message": user_message
|
||||
}
|
||||
};
|
||||
return {
|
||||
"field_errors": field_errors
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var expectTitleToBe = function(view, expectedTitle) {
|
||||
@@ -80,7 +80,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
|
||||
var verifyMessageUpdates = function (view, data, timerCallback) {
|
||||
|
||||
var message = 'Here to help!'
|
||||
var message = 'Here to help!';
|
||||
|
||||
view.message(message);
|
||||
expectMessageContains(view, message);
|
||||
@@ -89,11 +89,11 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
expectMessageContains(view, view.helpMessage);
|
||||
|
||||
view.showInProgressMessage();
|
||||
expectMessageContains(view, view.indicators['inProgress']);
|
||||
expectMessageContains(view, view.messages['inProgress']);
|
||||
expectMessageContains(view, view.indicators.inProgress);
|
||||
expectMessageContains(view, view.messages.inProgress);
|
||||
|
||||
view.showSuccessMessage();
|
||||
expectMessageContains(view, view.indicators['success']);
|
||||
expectMessageContains(view, view.indicators.success);
|
||||
expectMessageContains(view, view.getMessage('success'));
|
||||
|
||||
expect(timerCallback).not.toHaveBeenCalled();
|
||||
@@ -102,24 +102,24 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
responseText: JSON.stringify(createErrorMessage(data.valueAttribute, 'Ops, try again!.')),
|
||||
status: 400
|
||||
});
|
||||
expectMessageContains(view, view.indicators['validationError']);
|
||||
expectMessageContains(view, view.indicators.validationError);
|
||||
|
||||
view.showErrorMessage({status: 500});
|
||||
expectMessageContains(view, view.indicators['error']);
|
||||
expectMessageContains(view, view.indicators['error']);
|
||||
expectMessageContains(view, view.indicators.error);
|
||||
expectMessageContains(view, view.indicators.error);
|
||||
};
|
||||
|
||||
var verifySuccessMessageReset = function (view, data, timerCallback) {
|
||||
var verifySuccessMessageReset = function (view) {
|
||||
view.showHelpMessage();
|
||||
expectMessageContains(view, view.helpMessage);
|
||||
view.showSuccessMessage();
|
||||
expectMessageContains(view, view.indicators['success']);
|
||||
expectMessageContains(view, view.indicators.success);
|
||||
jasmine.Clock.tick(5000);
|
||||
// Message gets reset
|
||||
expectMessageContains(view, view.helpMessage);
|
||||
|
||||
view.showSuccessMessage();
|
||||
expectMessageContains(view, view.indicators['success']);
|
||||
expectMessageContains(view, view.indicators.success);
|
||||
// But if we change the message, it should not get reset.
|
||||
view.message("Do not reset this!");
|
||||
jasmine.Clock.tick(5000);
|
||||
@@ -133,7 +133,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
if (data.editable === 'toggle') {
|
||||
expect(view.el).toHaveClass('mode-placeholder');
|
||||
expectTitleToBe(view, data.title);
|
||||
expectMessageContains(view, view.indicators['canEdit']);
|
||||
expectMessageContains(view, view.indicators.canEdit);
|
||||
view.$el.click();
|
||||
} else {
|
||||
expectTitleAndMessageToBe(view, data.title, data.helpMessage);
|
||||
@@ -145,8 +145,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
view.$(data.valueInputSelector).val(data.validValue).change();
|
||||
// When the value in the field is changed
|
||||
expect(view.fieldValue()).toBe(data.validValue);
|
||||
expectMessageContains(view, view.indicators['inProgress']);
|
||||
expectMessageContains(view, view.messages['inProgress']);
|
||||
expectMessageContains(view, view.indicators.inProgress);
|
||||
expectMessageContains(view, view.messages.inProgress);
|
||||
request_data[data.valueAttribute] = data.validValue;
|
||||
AjaxHelpers.expectJsonRequest(
|
||||
requests, 'PATCH', url, request_data
|
||||
@@ -158,7 +158,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
expect(view.el).toHaveClass('mode-display');
|
||||
view.$el.click();
|
||||
} else {
|
||||
expectMessageContains(view, view.indicators['success']);
|
||||
expectMessageContains(view, view.indicators.success);
|
||||
}
|
||||
|
||||
view.$(data.valueInputSelector).val(data.invalidValue1).change();
|
||||
@@ -168,8 +168,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
);
|
||||
AjaxHelpers.respondWithError(requests, 500);
|
||||
// When server returns a 500 error
|
||||
expectMessageContains(view, view.indicators['error']);
|
||||
expectMessageContains(view, view.messages['error']);
|
||||
expectMessageContains(view, view.indicators.error);
|
||||
expectMessageContains(view, view.messages.error);
|
||||
expect(view.el).toHaveClass('mode-edit');
|
||||
|
||||
view.$(data.valueInputSelector).val(data.invalidValue2).change();
|
||||
@@ -179,7 +179,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
);
|
||||
AjaxHelpers.respondWithError(requests, 400, createErrorMessage(data.valueAttribute, data.validationError));
|
||||
// When server returns a validation error
|
||||
expectMessageContains(view, view.indicators['validationError']);
|
||||
expectMessageContains(view, view.indicators.validationError);
|
||||
expectMessageContains(view, data.validationError);
|
||||
expect(view.el).toHaveClass('mode-edit');
|
||||
|
||||
@@ -200,22 +200,20 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
};
|
||||
|
||||
var verifyTextField = function (view, data, requests) {
|
||||
var selector = '.u-field-value > input';
|
||||
verifyEditableField(view, _.extend({
|
||||
valueSelector: '.u-field-value',
|
||||
valueInputSelector: '.u-field-value > input'
|
||||
}, data
|
||||
), requests);
|
||||
}
|
||||
};
|
||||
|
||||
var verifyDropDownField = function (view, data, requests) {
|
||||
var selector = '.u-field-value > select';
|
||||
verifyEditableField(view, _.extend({
|
||||
valueSelector: '.u-field-value',
|
||||
valueInputSelector: '.u-field-value > select'
|
||||
}, data
|
||||
), requests);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
SELECT_OPTIONS: SELECT_OPTIONS,
|
||||
|
||||
@@ -6,8 +6,6 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
'use strict';
|
||||
|
||||
var USERNAME = 'Legolas',
|
||||
FULLNAME = 'Legolas Thranduil',
|
||||
EMAIL = 'legolas@woodland.middlearth',
|
||||
BIO = "My Name is Theon Greyjoy. I'm member of House Greyjoy";
|
||||
|
||||
describe("edx.FieldViews", function () {
|
||||
@@ -75,7 +73,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
title: 'Preferred Language',
|
||||
valueAttribute: 'language',
|
||||
helpMessage: 'Your preferred language.'
|
||||
})
|
||||
});
|
||||
|
||||
var view = new fieldViewClass(fieldData);
|
||||
view.saveAttributes(
|
||||
@@ -86,7 +84,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
var request = requests[0];
|
||||
expect(request.method).toBe('PATCH');
|
||||
expect(request.requestHeaders['Content-Type']).toBe('application/merge-patch+json;charset=utf-8');
|
||||
expect(request.requestHeaders['Priority']).toBe('Urgent');
|
||||
expect(request.requestHeaders.Priority).toBe('Urgent');
|
||||
expect(request.requestBody).toBe('{"language":"ur"}');
|
||||
});
|
||||
|
||||
@@ -199,7 +197,8 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
title: 'About me',
|
||||
valueAttribute: 'bio',
|
||||
helpMessage: 'Wicked is good',
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you’re taking courses on edX, or what you hope to learn.",
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
|
||||
"what your interests are, why you’re taking courses on edX, or what you hope to learn.",
|
||||
editable: 'never'
|
||||
});
|
||||
|
||||
@@ -210,7 +209,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
expect(view.el).toHaveClass('mode-hidden');
|
||||
expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue);
|
||||
|
||||
var bio = 'Too much to tell!'
|
||||
var bio = 'Too much to tell!';
|
||||
view.model.set({'bio': bio});
|
||||
expect(view.el).toHaveClass('mode-display');
|
||||
expect(view.$('.u-field-value').text()).toBe(bio);
|
||||
@@ -222,12 +221,13 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
|
||||
requests = AjaxHelpers.requests(this);
|
||||
|
||||
var valueInputSelector = '.u-field-value > textarea'
|
||||
var valueInputSelector = '.u-field-value > textarea';
|
||||
var fieldData = FieldViewsSpecHelpers.createFieldData(FieldViews.TextareaFieldView, {
|
||||
title: 'About me',
|
||||
valueAttribute: 'bio',
|
||||
helpMessage: 'Wicked is good',
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, what your interests are, why you’re taking courses on edX, or what you hope to learn.",
|
||||
placeholderValue: "Tell other edX learners a little about yourself: where you live, " +
|
||||
"what your interests are, why you’re taking courses on edX, or what you hope to learn.",
|
||||
editable: 'toggle'
|
||||
|
||||
});
|
||||
@@ -236,7 +236,7 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
|
||||
var view = new FieldViews.TextareaFieldView(fieldData).render();
|
||||
|
||||
FieldViewsSpecHelpers.expectTitleToBe(view, fieldData.title);
|
||||
FieldViewsSpecHelpers.expectMessageContains(view, view.indicators['canEdit']);
|
||||
FieldViewsSpecHelpers.expectMessageContains(view, view.indicators.canEdit);
|
||||
expect(view.el).toHaveClass('mode-placeholder');
|
||||
expect(view.$('.u-field-value').text()).toBe(fieldData.placeholderValue);
|
||||
|
||||
|
||||
@@ -45,5 +45,5 @@
|
||||
}
|
||||
});
|
||||
return UserAccountModel;
|
||||
})
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
@@ -12,5 +12,5 @@
|
||||
});
|
||||
|
||||
return UserPreferencesModel;
|
||||
})
|
||||
}).call(this, define || RequireJS.define);
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
@@ -37,7 +37,10 @@
|
||||
model: userAccountModel,
|
||||
title: gettext('Full Name'),
|
||||
valueAttribute: 'name',
|
||||
helpMessage: gettext('The name that appears on your edX certificates. Other learners never see your full name.')
|
||||
helpMessage: gettext(
|
||||
'The name that appears on your edX certificates. Other learners never see ' +
|
||||
'your full name.'
|
||||
)
|
||||
})
|
||||
},
|
||||
{
|
||||
@@ -45,7 +48,10 @@
|
||||
model: userAccountModel,
|
||||
title: gettext('Email Address'),
|
||||
valueAttribute: 'email',
|
||||
helpMessage: gettext('The email address you use to sign in to edX. Communications from edX and your courses are sent to this address.')
|
||||
helpMessage: gettext(
|
||||
'The email address you use to sign in to edX. Communications ' +
|
||||
'from edX and your courses are sent to this address.'
|
||||
)
|
||||
})
|
||||
},
|
||||
{
|
||||
@@ -56,7 +62,10 @@
|
||||
emailAttribute: 'email',
|
||||
linkTitle: gettext('Reset Password'),
|
||||
linkHref: fieldsData.password.url,
|
||||
helpMessage: gettext('When you click "Reset Password", a message will be sent to your email address. Click the link in the message to reset your password.')
|
||||
helpMessage: gettext(
|
||||
'When you click "Reset Password", a message will be sent to your email address. ' +
|
||||
'Click the link in the message to reset your password.'
|
||||
)
|
||||
})
|
||||
},
|
||||
{
|
||||
@@ -66,7 +75,10 @@
|
||||
valueAttribute: 'pref-lang',
|
||||
required: true,
|
||||
refreshPageOnSave: true,
|
||||
helpMessage: gettext('The language used for the edX site. The site is currently available in a limited number of languages.'),
|
||||
helpMessage: gettext(
|
||||
'The language used for the edX site. The site is currently available in a ' +
|
||||
'limited number of languages.'
|
||||
),
|
||||
options: fieldsData.language.options
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@
|
||||
AccountSettingsFieldViews.EmailFieldView = FieldViews.TextFieldView.extend({
|
||||
|
||||
successMessage: function() {
|
||||
return this.indicators['success'] + interpolate_text(
|
||||
gettext('We\'ve sent a confirmation message to {new_email_address}. Click the link in the message to update your email address.'),
|
||||
return this.indicators.success + interpolate_text(
|
||||
gettext(
|
||||
'We\'ve sent a confirmation message to {new_email_address}. ' +
|
||||
'Click the link in the message to update your email address.'
|
||||
),
|
||||
{'new_email_address': this.fieldValue()}
|
||||
);
|
||||
}
|
||||
@@ -32,9 +35,13 @@
|
||||
success: function () {
|
||||
view.showSuccessMessage();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
error: function () {
|
||||
view.message(
|
||||
view.indicators['error'] + gettext('You must sign out of edX and sign back in before your language changes take effect.')
|
||||
view.indicators.error +
|
||||
gettext(
|
||||
'You must sign out of edX and sign back in before your language ' +
|
||||
'changes take effect.'
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -51,10 +58,10 @@
|
||||
|
||||
linkClicked: function (event) {
|
||||
event.preventDefault();
|
||||
this.resetPassword(event)
|
||||
this.resetPassword(event);
|
||||
},
|
||||
|
||||
resetPassword: function (event) {
|
||||
resetPassword: function () {
|
||||
var data = {};
|
||||
data[this.options.emailAttribute] = this.model.get(this.options.emailAttribute);
|
||||
|
||||
@@ -64,17 +71,20 @@
|
||||
url: view.options.linkHref,
|
||||
data: data,
|
||||
success: function () {
|
||||
view.showSuccessMessage()
|
||||
view.showSuccessMessage();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
error: function (xhr) {
|
||||
view.showErrorMessage(xhr);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
successMessage: function () {
|
||||
return this.indicators['success'] + interpolate_text(
|
||||
gettext('We\'ve sent a message to {email_address}. Click the link in the message to reset your password.'),
|
||||
return this.indicators.success + interpolate_text(
|
||||
gettext(
|
||||
'We\'ve sent a message to {email_address}. ' +
|
||||
'Click the link in the message to reset your password.'
|
||||
),
|
||||
{'email_address': this.model.get(this.options.emailAttribute)}
|
||||
);
|
||||
}
|
||||
@@ -85,15 +95,15 @@
|
||||
modelValue: function () {
|
||||
var modelValue = this.model.get(this.options.valueAttribute);
|
||||
if (_.isArray(modelValue) && modelValue.length > 0) {
|
||||
return modelValue[0].code
|
||||
return modelValue[0].code;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
|
||||
saveValue: function () {
|
||||
var attributes = {};
|
||||
var value = this.fieldValue() ? [{'code': this.fieldValue()}] : [];
|
||||
var attributes = {},
|
||||
value = this.fieldValue() ? [{'code': this.fieldValue()}] : [];
|
||||
attributes[this.options.valueAttribute] = value;
|
||||
this.saveAttributes(attributes);
|
||||
}
|
||||
@@ -152,21 +162,21 @@
|
||||
view.render();
|
||||
view.showSuccessMessage();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
error: function (xhr) {
|
||||
view.showErrorMessage(xhr);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
inProgressMessage: function() {
|
||||
return this.indicators['inProgress'] + (this.options.connected ? gettext('Unlinking') : gettext('Linking'));
|
||||
return this.indicators.inProgress + (this.options.connected ? gettext('Unlinking') : gettext('Linking'));
|
||||
},
|
||||
|
||||
successMessage: function() {
|
||||
return this.indicators['success'] + gettext('Successfully unlinked.');
|
||||
return this.indicators.success + gettext('Successfully unlinked.');
|
||||
}
|
||||
});
|
||||
|
||||
return AccountSettingsFieldViews;
|
||||
})
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
var AccountSettingsView = Backbone.View.extend({
|
||||
|
||||
initialize: function (options) {
|
||||
initialize: function () {
|
||||
this.template = _.template($('#account_settings-tpl').text());
|
||||
_.bindAll(this, 'render', 'renderFields', 'showLoadingError');
|
||||
},
|
||||
|
||||
@@ -78,7 +78,10 @@
|
||||
editable: editable,
|
||||
showMessages: false,
|
||||
title: gettext('About me'),
|
||||
placeholderValue: gettext("Tell other edX learners a little about yourself: where you live, what your interests are, why you're taking courses on edX, or what you hope to learn."),
|
||||
placeholderValue: gettext(
|
||||
"Tell other edX learners a little about yourself: where you live, what your interests are, " +
|
||||
"why you're taking courses on edX, or what you hope to learn."
|
||||
),
|
||||
valueAttribute: "bio",
|
||||
helpMessage: ''
|
||||
})
|
||||
|
||||
@@ -16,15 +16,22 @@
|
||||
},
|
||||
|
||||
message: function () {
|
||||
var accountSettingsLink = '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>';
|
||||
if (this.profileIsPrivate) {
|
||||
this._super(interpolate_text(
|
||||
gettext("You must specify your birth year before you can share your full profile. To specify your birth year, go to the {account_settings_page_link}"),
|
||||
{'account_settings_page_link': '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>'}
|
||||
gettext(
|
||||
"You must specify your birth year before you can share your full profile. To specify " +
|
||||
"your birth year, go to the {account_settings_page_link}"
|
||||
),
|
||||
{'account_settings_page_link': accountSettingsLink}
|
||||
));
|
||||
} else if (this.requiresParentalConsent) {
|
||||
this._super(interpolate_text(
|
||||
gettext('You must be over 13 to share a full profile. If you are over 13, make sure that you have specified a birth year on the {account_settings_page_link}'),
|
||||
{'account_settings_page_link': '<a href="' + this.options.accountSettingsPageUrl + '">' + gettext('Account Settings page.') + '</a>'}
|
||||
gettext(
|
||||
'You must be over 13 to share a full profile. If you are over 13, make sure that you ' +
|
||||
'have specified a birth year on the {account_settings_page_link}'
|
||||
),
|
||||
{'account_settings_page_link': accountSettingsLink}
|
||||
));
|
||||
}
|
||||
else {
|
||||
@@ -42,5 +49,5 @@
|
||||
});
|
||||
|
||||
return LearnerProfileFieldViews;
|
||||
})
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
var LearnerProfileView = Backbone.View.extend({
|
||||
|
||||
initialize: function (options) {
|
||||
initialize: function () {
|
||||
this.template = _.template($('#learner_profile-tpl').text());
|
||||
_.bindAll(this, 'showFullProfile', 'render', 'renderFields', 'showLoadingError');
|
||||
this.listenTo(this.options.preferencesModel, "change:" + 'account_privacy', this.render);
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
},
|
||||
|
||||
modelValueIsSet: function() {
|
||||
return (this.modelValue() == true);
|
||||
return (this.modelValue() === true);
|
||||
},
|
||||
|
||||
message: function (message) {
|
||||
@@ -102,7 +102,7 @@
|
||||
this.lastSuccessMessageContext = context;
|
||||
|
||||
setTimeout(function () {
|
||||
if ((context === view.lastSuccessMessageContext) && (view.message().html() == successMessage)) {
|
||||
if ((context === view.lastSuccessMessageContext) && (view.message().html() === successMessage)) {
|
||||
view.showHelpMessage();
|
||||
}
|
||||
}, messageRevertDelay);
|
||||
@@ -111,9 +111,11 @@
|
||||
showErrorMessage: function (xhr) {
|
||||
if (xhr.status === 400) {
|
||||
try {
|
||||
var errors = JSON.parse(xhr.responseText);
|
||||
var validationErrorMessage = Mustache.escapeHtml(errors['field_errors'][this.options.valueAttribute]['user_message']);
|
||||
var message = this.indicators['validationError'] + validationErrorMessage;
|
||||
var errors = JSON.parse(xhr.responseText),
|
||||
validationErrorMessage = Mustache.escapeHtml(
|
||||
errors.field_errors[this.options.valueAttribute].user_message
|
||||
),
|
||||
message = this.indicators.validationError + validationErrorMessage;
|
||||
this.message(message);
|
||||
} catch (error) {
|
||||
this.message(this.getMessage('error'));
|
||||
@@ -127,7 +129,9 @@
|
||||
FieldViews.EditableFieldView = FieldViews.FieldView.extend({
|
||||
|
||||
initialize: function (options) {
|
||||
_.bindAll(this, 'saveAttributes', 'saveSucceeded', 'showDisplayMode', 'showEditMode', 'startEditing', 'finishEditing');
|
||||
_.bindAll(this, 'saveAttributes', 'saveSucceeded', 'showDisplayMode', 'showEditMode',
|
||||
'startEditing', 'finishEditing'
|
||||
);
|
||||
this._super(options);
|
||||
|
||||
this.editable = _.isUndefined(this.options.editable) ? 'always': this.options.editable;
|
||||
@@ -183,13 +187,13 @@
|
||||
this.$el.addClass('mode-edit');
|
||||
},
|
||||
|
||||
startEditing: function (event) {
|
||||
startEditing: function () {
|
||||
if (this.editable === 'toggle' && this.mode !== 'edit') {
|
||||
this.showEditMode(true);
|
||||
}
|
||||
},
|
||||
|
||||
finishEditing: function(event) {
|
||||
finishEditing: function() {
|
||||
if (this.fieldValue() !== this.modelValue()) {
|
||||
this.saveValue();
|
||||
} else {
|
||||
@@ -268,7 +272,7 @@
|
||||
this.$('.u-field-value input').val(Mustache.escapeHtml(value));
|
||||
},
|
||||
|
||||
saveValue: function (event) {
|
||||
saveValue: function () {
|
||||
var attributes = {};
|
||||
attributes[this.options.valueAttribute] = this.fieldValue();
|
||||
this.saveAttributes(attributes);
|
||||
@@ -315,15 +319,15 @@
|
||||
|
||||
modelValueIsSet: function() {
|
||||
var value = this.modelValue();
|
||||
if (_.isUndefined(value) || _.isNull(value) || value == '') {
|
||||
if (_.isUndefined(value) || _.isNull(value) || value === '') {
|
||||
return false;
|
||||
} else {
|
||||
return !(_.isUndefined(this.optionForValue(value)))
|
||||
return !(_.isUndefined(this.optionForValue(value)));
|
||||
}
|
||||
},
|
||||
|
||||
optionForValue: function(value) {
|
||||
return _.find(this.options.options, function(option) { return option[0] == value; })
|
||||
return _.find(this.options.options, function(option) { return option[0] === value; });
|
||||
},
|
||||
|
||||
fieldValue: function () {
|
||||
@@ -420,7 +424,7 @@
|
||||
return this;
|
||||
},
|
||||
|
||||
adjustTextareaHeight: function(event) {
|
||||
adjustTextareaHeight: function() {
|
||||
var textarea = this.$('textarea');
|
||||
textarea.css('height', 'auto').css('height', textarea.prop('scrollHeight') + 10);
|
||||
},
|
||||
@@ -490,11 +494,11 @@
|
||||
return this;
|
||||
},
|
||||
|
||||
linkClicked: function () {
|
||||
linkClicked: function (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
return FieldViews;
|
||||
})
|
||||
});
|
||||
}).call(this, define || RequireJS.define);
|
||||
|
||||
Reference in New Issue
Block a user