From 7c9f901096442fec3490ce7613842e40f3b0c598 Mon Sep 17 00:00:00 2001 From: Ben Warzeski Date: Wed, 3 Jun 2020 11:37:43 -0400 Subject: [PATCH] Update 'create team?' prompt check in topic teams to look in teamset (#24088) * Update check for showing the 'create team?' prompt in topic teams to look in teamset * fix tests and correct which collection we are checking * eslint fixes Co-authored-by: Ben Warzeski --- .../teams/js/spec/views/topic_teams_spec.js | 35 +++++++++---------- .../teams/static/teams/js/views/teams_tab.js | 14 +++++++- .../static/teams/js/views/topic_teams.js | 3 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lms/djangoapps/teams/static/teams/js/spec/views/topic_teams_spec.js b/lms/djangoapps/teams/static/teams/js/spec/views/topic_teams_spec.js index 13b385677a..f58878f345 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/views/topic_teams_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/views/topic_teams_spec.js @@ -8,16 +8,15 @@ define([ 'use strict'; describe('Topic Teams View', function() { var createTopicTeamsView = function(options, isInstructorManagedTopic) { - var myTeamsCollection; options = options || {}; // eslint-disable-line no-param-reassign - myTeamsCollection = options.myTeamsCollection || TeamSpecHelpers.createMockTeams({results: []}); return new TopicTeamsView({ el: '.teams-container', model: isInstructorManagedTopic ? TeamSpecHelpers.createMockInstructorManagedTopic() : TeamSpecHelpers.createMockTopic(), - collection: options.teams || TeamSpecHelpers.createMockTeams(), - myTeamsCollection: myTeamsCollection, - showActions: true, + collection: options.teams || TeamSpecHelpers.createMockTeams({results: []}), + myTopicTeamsCollection: ( + options.myTopicTeamsCollection || TeamSpecHelpers.createMockTeams({results: []}) + ), context: _.extend({}, TeamSpecHelpers.testContext, options) }).render(); }; @@ -28,10 +27,7 @@ define([ 'If you still can\'t find a team to join, create a new team in this topic.', title = teamsView.$('.title').text().trim(), message = teamsView.$('.copy').text().trim(); - if (!options) { - options = {showActions: true}; // eslint-disable-line no-param-reassign - } - + options = options || {showActions: true}; // eslint-disable-line no-param-reassign if (options.showActions) { expect(title).toBe(expectedTitle); expect(message).toBe(expectedMessage); @@ -47,12 +43,13 @@ define([ }); it('can render itself', function() { - var testTeamData = TeamSpecHelpers.createMockTeamData(1, 5), - teamsView = createTopicTeamsView({ - teams: TeamSpecHelpers.createMockTeams({ - results: testTeamData - }) - }); + var testTeamData = TeamSpecHelpers.createMockTeamData(1, 5); + var options = { + teams: TeamSpecHelpers.createMockTeams({ + results: testTeamData + }) + }; + var teamsView = createTopicTeamsView(options); var footerEl = teamsView.$('.teams-paging-footer'); expect(teamsView.$('.teams-paging-header').text()).toMatch('Showing 1-5 out of 6 total'); expect(footerEl.text()).toMatch('1\\s+out of\\s+\/\\s+2'); // eslint-disable-line no-useless-escape @@ -85,8 +82,8 @@ define([ ); }); - it('does not show actions for a user already in a team', function() { - var options = {myTeamsCollection: TeamSpecHelpers.createMockTeams()}; + it('does not show actions for a user already in a team in the teamset', function() { + var options = {myTopicTeamsCollection: TeamSpecHelpers.createMockTeams()}; var teamsView = createTopicTeamsView(options); verifyActions(teamsView, {showActions: false}); }); @@ -102,7 +99,7 @@ define([ privileged: true, staff: false }, - myTeamsCollection: TeamSpecHelpers.createMockTeams() + myTopicTeamsCollection: TeamSpecHelpers.createMockTeams() }; var teamsView = createTopicTeamsView(options); verifyActions(teamsView, {showActions: true}); @@ -114,7 +111,7 @@ define([ privileged: false, staff: true }, - myTeamsCollection: TeamSpecHelpers.createMockTeams() + myTopicTeamsCollection: TeamSpecHelpers.createMockTeams() }; var teamsView = createTopicTeamsView(options); verifyActions(teamsView, {showActions: true}); diff --git a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js index a199c976f0..e80f2265ec 100644 --- a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js +++ b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js @@ -380,12 +380,24 @@ createTeamsListView: function(options) { var topic = options.topic, collection = options.collection, + myTopicTeamsCollection = new TeamCollection( + this.context.userInfo.teams, + { + teamEvents: this.teamEvents, + course_id: this.context.courseID, + username: this.context.userInfo.username, + topic_id: topic.get('id'), + perPage: 5, + parse: true, + url: this.context.myTeamsUrl + } + ), teamsView = new TopicTeamsView({ router: this.router, context: this.context, model: topic, collection: collection, - myTeamsCollection: this.myTeamsCollection, + myTopicTeamsCollection: myTopicTeamsCollection, showSortControls: options.showSortControls }), searchFieldView = new SearchFieldView({ diff --git a/lms/djangoapps/teams/static/teams/js/views/topic_teams.js b/lms/djangoapps/teams/static/teams/js/views/topic_teams.js index b512c17a66..0bfefaf79c 100644 --- a/lms/djangoapps/teams/static/teams/js/views/topic_teams.js +++ b/lms/djangoapps/teams/static/teams/js/views/topic_teams.js @@ -21,7 +21,6 @@ this.options = _.extend({}, options); this.showSortControls = options.showSortControls; this.context = options.context; - this.myTeamsCollection = options.myTeamsCollection; TeamsView.prototype.initialize.call(this, options); }, @@ -33,7 +32,7 @@ return this.context.userInfo.staff || this.context.userInfo.privileged || (!TeamUtils.isInstructorManagedTopic(this.model.attributes.type) - && this.myTeamsCollection.length === 0); + && this.options.myTopicTeamsCollection.length === 0); }, render: function() {