Skip to content

Commit

Permalink
Convert LMS features to use safe templates
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-armstrong committed Aug 22, 2016
1 parent 719dff6 commit df3b52e
Show file tree
Hide file tree
Showing 36 changed files with 526 additions and 423 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ define([
setFixtures('<div id="page-prompt"></div>');
PageHelpers.preventBackboneChangingUrl();
spyOn(Backbone.history, 'navigate');
spyOn(TeamUtils, 'showMessage');
view = createInstructorTools().render();
spyOn(view.teamEvents, 'trigger');
});
Expand All @@ -66,7 +65,7 @@ define([
team: view.team
}
);
expectSuccessMessage(view.team);
expectSuccessMessage(view);
});

it('can cancel team deletion', function() {
Expand All @@ -80,7 +79,11 @@ define([
var requests = AjaxHelpers.requests(this);
deleteTeam(view, true);
AjaxHelpers.respondWithError(requests, 404);
<<<<<<< 719dff66fb473b380cee40011e38322004514e72
expectSuccessMessage(view.team);
=======
expectSuccessMessage(view);
>>>>>>> Convert LMS features to use safe templates
});

it('can trigger the edit membership view', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ define([
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers',
'common/js/spec_helpers/discussion_spec_helper',
'teams/js/spec_helpers/team_spec_helpers',
'teams/js/views/team_discussion'
], function(_, AjaxHelpers, DiscussionSpecHelper, TeamSpecHelpers, TeamDiscussionView) {
'xmodule_js/common_static/coffee/spec/discussion/discussion_spec_helper',
'edx-ui-toolkit/js/utils/string-utils'
], function(_, AjaxHelpers, TeamDiscussionView, TeamSpecHelpers, DiscussionSpecHelper, StringUtils) {
'use strict';
xdescribe('TeamDiscussionView', function() {
var discussionView, createDiscussionView, createPost, expandReplies, postReply;
Expand All @@ -25,14 +26,12 @@ define([
discussionView.render();
AjaxHelpers.expectRequest(
requests, 'GET',
interpolate(
'/courses/%(courseID)s/discussion/forum/%(discussionID)s/inline?page=1&ajax=1',
StringUtils.interpolate(
'/courses/{courseID}/discussion/forum/{discussionID}/inline?page=1&ajax=1',
{
courseID: TeamSpecHelpers.testCourseID,
discussionID: TeamSpecHelpers.testTeamDiscussionID
},
true

}
)
);
AjaxHelpers.respondWithJson(requests, TeamSpecHelpers.createMockDiscussionResponse(threads));
Expand All @@ -49,16 +48,15 @@ define([
view.$('.submit').click();
AjaxHelpers.expectRequest(
requests, 'POST',
interpolate(
'/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1',
StringUtils.interpolate(
'/courses/{courseID}/discussion/{discussionID}/threads/create?ajax=1',
{
courseID: TeamSpecHelpers.testCourseID,
discussionID: TeamSpecHelpers.testTeamDiscussionID
},
true
}
),
interpolate(
'thread_type=discussion&title=%(title)s&body=%(body)s&anonymous=false&anonymous_to_peers=false&auto_subscribe=true',
StringUtils.interpolate(
'thread_type=discussion&title={title}&body={body}&anonymous=false&anonymous_to_peers=false&auto_subscribe=true', // eslint-disable-line max-len
{
title: title.replace(/ /g, '+'),
body: body.replace(/ /g, '+')
Expand All @@ -80,14 +78,13 @@ define([
view.$('.forum-thread-expand').first().click();
AjaxHelpers.expectRequest(
requests, 'GET',
interpolate(
'/courses/%(courseID)s/discussion/forum/%(discussionID)s/threads/%(threadID)s?ajax=1&resp_skip=0&resp_limit=25',
StringUtils.interpolate(
'/courses/{courseID}/discussion/forum/{discussionID}/threads/{threadID}?ajax=1&resp_skip=0&resp_limit=25', // eslint-disable-line max-len
{
courseID: TeamSpecHelpers.testCourseID,
discussionID: TeamSpecHelpers.testTeamDiscussionID,
threadID: threadID || '999'
},
true
}
)
);
AjaxHelpers.respondWithJson(requests, {
Expand All @@ -102,13 +99,12 @@ define([
replyForm.find('.discussion-submit-post').click();
AjaxHelpers.expectRequest(
requests, 'POST',
interpolate(
'/courses/%(courseID)s/discussion/threads/%(threadID)s/reply?ajax=1',
StringUtils.interpolate(
'/courses/{courseID}/discussion/threads/{threadID}/reply?ajax=1',
{
courseID: TeamSpecHelpers.testCourseID,
threadID: threadID || '999'
},
true
}
),
'body=' + reply.replace(/ /g, '+')
);
Expand Down Expand Up @@ -179,15 +175,14 @@ define([
view.$('.submit').click();
AjaxHelpers.expectRequest(
requests, 'POST',
interpolate(
'/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1',
StringUtils.interpolate(
'/courses/{courseID}/discussion/{discussionID}/threads/create?ajax=1',
{
courseID: TeamSpecHelpers.testCourseID,
discussionID: TeamSpecHelpers.testTeamDiscussionID
},
true
}
),
'thread_type=discussion&title=&body=Updated+body&anonymous=false&anonymous_to_peers=false&auto_subscribe=true'
'thread_type=discussion&title=&body=Updated+body&anonymous=false&anonymous_to_peers=false&auto_subscribe=true' // eslint-disable-line max-len
);
AjaxHelpers.respondWithJson(requests, {
content: TeamSpecHelpers.createMockPostResponse({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
define([
'underscore',
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers',
'common/js/spec_helpers/discussion_spec_helper',
'teams/js/spec_helpers/team_spec_helpers',
'edx-ui-toolkit/js/utils/string-utils',
'teams/js/models/team',
'teams/js/views/team_profile'
], function(_, AjaxHelpers, DiscussionSpecHelper, TeamSpecHelpers, TeamModel, TeamProfileView) {
'teams/js/views/team_profile',
'teams/js/spec_helpers/team_spec_helpers',
'xmodule_js/common_static/coffee/spec/discussion/discussion_spec_helper'
], function(_, AjaxHelpers, StringUtils, TeamModel, TeamProfileView, TeamSpecHelpers, DiscussionSpecHelper) {
'use strict';
describe('TeamProfileView', function() {
var profileView, createTeamProfileView, createTeamModelData, clickLeaveTeam,
Expand Down Expand Up @@ -58,13 +59,12 @@ define([
AjaxHelpers.expectRequest(
requests,
'GET',
interpolate(
'/courses/%(courseID)s/discussion/forum/%(topicID)s/inline?page=1&ajax=1',
StringUtils.interpolate(
'/courses/{courseID}/discussion/forum/{topicID}/inline?page=1&ajax=1',
{
courseID: TeamSpecHelpers.testCourseID,
topicID: TeamSpecHelpers.testTeamDiscussionID
},
true
}
)
);
AjaxHelpers.respondWithJson(requests, TeamSpecHelpers.createMockDiscussionResponse());
Expand Down Expand Up @@ -187,7 +187,7 @@ define([
assertTeamDetails(view, 0, false);
});

it("wouldn't do anything if user click on Cancel button on dialog", function() {
it('should not do anything if user clicks on Cancel button on dialog', function() {
var requests = AjaxHelpers.requests(this);

var view = createTeamProfileView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ define([
userInfo: TeamSpecHelpers.createMockUserInfo({staff: true})
});
teamsTabView.teamsCollection = TeamSpecHelpers.createMockTeams();
if (expectedEvent.page_name === 'search-teams') {
teamsTabView.teamsCollection.searchString = 'test search string';
}
teamsTabView.router.navigate(url, {trigger: true});
if (requests.length > requests.currentIndex) {
AjaxHelpers.respondWithJson(requests, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([
return _.map(_.range(startIndex, stopIndex + 1), function(i) {
var id = 'id' + i;
return {
name: 'team ' + i,
name: 'Team <' + i + '>',
id: id,
language: testLanguages[i % 4][0],
country: testCountries[i % 4][0],
Expand Down Expand Up @@ -151,30 +151,30 @@ define([
];
}
return {
'num_pages': 1,
'page': 1,
'discussion_data': threads,
'user_info': {
'username': testUser,
'follower_ids': [],
'default_sort_key': 'date',
'downvoted_ids': [],
'subscribed_thread_ids': [],
'upvoted_ids': [],
'external_id': '9',
'id': '9',
'subscribed_user_ids': [],
'subscribed_commentable_ids': []
num_pages: 1,
page: 1,
discussion_data: threads,
user_info: {
username: testUser,
follower_ids: [],
default_sort_key: 'date',
downvoted_ids: [],
subscribed_thread_ids: [],
upvoted_ids: [],
external_id: '9',
id: '9',
subscribed_user_ids: [],
subscribed_commentable_ids: []
},
'annotated_content_info': {
annotated_content_info: {
},
'roles': {'Moderator': [], 'Administrator': [], 'Community TA': []},
'course_settings': {
'is_cohorted': false,
'allow_anonymous_to_peers': false,
'allow_anonymous': true,
'category_map': {'subcategories': {}, 'children': [], 'entries': {}},
'cohorts': []
roles: {Moderator: [], Administrator: [], 'Community TA': []},
course_settings: {
is_cohorted: false,
allow_anonymous_to_peers: false,
allow_anonymous: true,
category_map: {subcategories: {}, children: [], entries: {}},
cohorts: []
}
};
};
Expand Down Expand Up @@ -207,7 +207,7 @@ define([
resp_skip: 0,
id: '55c1323c56c02ce921000001',
pinned: false,
votes: {'count': 0, 'down_count': 0, 'point': 0, 'up_count': 0},
votes: {count: 0, down_count: 0, point: 0, up_count: 0},
resp_limit: 25,
abuse_flaggers: [],
closed: false,
Expand All @@ -229,10 +229,10 @@ define([
createMockTopicData = function(startIndex, stopIndex) {
return _.map(_.range(startIndex, stopIndex + 1), function(i) {
return {
'description': 'Test description ' + i,
'name': 'Test Topic ' + i,
'id': 'test-topic-' + i,
'team_count': 0
description: 'Test description ' + i,
name: 'Test Topic ' + i,
id: 'test-topic-' + i,
team_count: 0
};
});
};
Expand Down
20 changes: 12 additions & 8 deletions lms/djangoapps/teams/static/teams/js/views/edit_team.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
define(['backbone',
'underscore',
'gettext',
'edx-ui-toolkit/js/utils/html-utils',
'js/views/fields',
'teams/js/models/team',
'common/js/components/utils/view_utils',
'text!teams/templates/edit-team.underscore'],
function(Backbone, _, gettext, FieldViews, TeamModel, ViewUtils, editTeamTemplate) {
function(Backbone, _, gettext, HtmlUtils, FieldViews, TeamModel, ViewUtils, editTeamTemplate) {
return Backbone.View.extend({

maxTeamNameLength: 255,
Expand Down Expand Up @@ -51,7 +52,7 @@
valueAttribute: 'description',
editable: 'always',
showMessages: false,
helpMessage: gettext('A short description of the team to help other learners understand the goals or direction of the team (maximum 300 characters).')
helpMessage: gettext('A short description of the team to help other learners understand the goals or direction of the team (maximum 300 characters).') // jshint ignore:line
});

this.teamLanguageField = new FieldViews.DropdownFieldView({
Expand All @@ -62,7 +63,7 @@
showMessages: false,
titleIconName: 'fa-comment-o',
options: this.context.languages,
helpMessage: gettext('The language that team members primarily use to communicate with each other.')
helpMessage: gettext('The language that team members primarily use to communicate with each other.') // jshint ignore:line
});

this.teamCountryField = new FieldViews.DropdownFieldView({
Expand All @@ -78,11 +79,14 @@
},

render: function() {
this.$el.html(_.template(editTeamTemplate)({
primaryButtonTitle: this.primaryButtonTitle,
action: this.action,
totalMembers: _.isUndefined(this.teamModel) ? 0 : this.teamModel.get('membership').length
}));
HtmlUtils.setHtml(
this.$el,
HtmlUtils.template(editTeamTemplate)({
primaryButtonTitle: this.primaryButtonTitle,
action: this.action,
totalMembers: _.isUndefined(this.teamModel) ? 0 : this.teamModel.get('membership').length
})
);
this.set(this.teamNameField, '.team-required-fields');
this.set(this.teamDescriptionField, '.team-required-fields');
this.set(this.teamLanguageField, '.team-optional-fields');
Expand Down
Loading

0 comments on commit df3b52e

Please sign in to comment.