Commit 3bf6b9bd by Christina Roberts

Merge pull request #9357 from edx/christina/tnl-3072

The stale flag needs to take into account its previous state.
parents 19604a4a 41f207de
;(function (define) { ;(function (define) {
'use strict'; 'use strict';
define(['teams/js/collections/base', 'teams/js/models/topic', 'gettext', 'underscore'], define(['underscore', 'gettext', 'teams/js/collections/base', 'teams/js/models/topic'],
function(BaseCollection, TopicModel, gettext, _) { function(_, gettext, BaseCollection, TopicModel) {
var TopicCollection = BaseCollection.extend({ var TopicCollection = BaseCollection.extend({
initialize: function(topics, options) { initialize: function(topics, options) {
var self = this; var self = this;
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
onUpdate: function(event) { onUpdate: function(event) {
this.isStale = event.action === 'create'; this.isStale = this.isStale || event.action === 'create';
}, },
model: TopicModel model: TopicModel
......
define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers', 'teams/js/collections/topic'], define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers',
function (Backbone, URI, _, AjaxHelpers, TopicCollection) { 'teams/js/spec_helpers/team_spec_helpers'],
function (Backbone, URI, _, AjaxHelpers, TeamSpecHelpers) {
'use strict'; 'use strict';
describe('TopicCollection', function () { describe('TopicCollection', function () {
var topicCollection; var topicCollection;
beforeEach(function () { beforeEach(function () {
topicCollection = new TopicCollection( topicCollection = TeamSpecHelpers.createMockTopicCollection();
{
"count": 6,
"current_page": 1,
"start": 0,
"results": [
{
"description": "asdf description",
"name": "asdf",
"id": "_asdf"
},
{
"description": "bar description",
"name": "bar",
"id": "_bar"
},
{
"description": "baz description",
"name": "baz",
"id": "_baz"
},
{
"description": "foo description",
"name": "foo",
"id": "_foo"
},
{
"description": "qwerty description",
"name": "qwerty",
"id": "_qwerty"
}
],
"sort_order": "name"
},
{
teamEvents:_.clone(Backbone.Events),
course_id: 'my/course/id',
parse: true
});
}); });
var testRequestParam = function (self, param, value) { var testRequestParam = function (self, param, value) {
......
...@@ -4,17 +4,7 @@ define([ ...@@ -4,17 +4,7 @@ define([
], function (Backbone, _, TopicCollection, TopicsView, TeamSpecHelpers, AjaxHelpers) { ], function (Backbone, _, TopicCollection, TopicsView, TeamSpecHelpers, AjaxHelpers) {
'use strict'; 'use strict';
describe('TopicsView', function () { describe('TopicsView', function () {
var initialTopics, topicCollection, createTopicsView, var initialTopics, topicCollection, createTopicsView, triggerUpdateEvent;
generateTopics = function (startIndex, stopIndex) {
return _.map(_.range(startIndex, stopIndex + 1), function (i) {
return {
"description": "description " + i,
"name": "topic " + i,
"id": "id " + i,
"team_count": 0
};
});
};
createTopicsView = function() { createTopicsView = function() {
return new TopicsView({ return new TopicsView({
...@@ -24,25 +14,18 @@ define([ ...@@ -24,25 +14,18 @@ define([
}).render(); }).render();
}; };
triggerUpdateEvent = function(topicsView, sendJoinAfter) {
topicsView.collection.teamEvents.trigger('teams:update', { action: 'create' });
if (sendJoinAfter) {
topicsView.collection.teamEvents.trigger('teams:update', { action: 'join' });
}
topicsView.render();
};
beforeEach(function () { beforeEach(function () {
setFixtures('<div class="topics-container"></div>'); setFixtures('<div class="topics-container"></div>');
initialTopics = generateTopics(1, 5); initialTopics = TeamSpecHelpers.createMockTopicData(1, 5);
topicCollection = new TopicCollection( topicCollection = TeamSpecHelpers.createMockTopicCollection(initialTopics);
{
"count": 6,
"num_pages": 2,
"current_page": 1,
"start": 0,
"results": initialTopics,
"sort_order": "name"
},
{
teamEvents: TeamSpecHelpers.teamEvents,
course_id: 'my/course/id',
parse: true,
url: 'api/teams/topics'
}
);
}); });
it('can render the first of many pages', function () { it('can render the first of many pages', function () {
...@@ -64,8 +47,25 @@ define([ ...@@ -64,8 +47,25 @@ define([
var requests = AjaxHelpers.requests(this), var requests = AjaxHelpers.requests(this),
topicsView = createTopicsView(); topicsView = createTopicsView();
topicsView.collection.teamEvents.trigger('teams:update', { action: 'create' }); triggerUpdateEvent(topicsView);
topicsView.render(); AjaxHelpers.expectJsonRequestURL(
requests,
'api/teams/topics',
{
course_id : 'my/course/id',
page : '1',
page_size : '5', // currently the page size is determined by the size of the collection
order_by : 'name'
}
);
});
it('refreshes the topics staff creates a team and then joins it', function() {
var requests = AjaxHelpers.requests(this),
topicsView = createTopicsView();
// Staff are not immediately added to the team, but may choose to join after the create event.
triggerUpdateEvent(topicsView, true);
AjaxHelpers.expectJsonRequestURL( AjaxHelpers.expectJsonRequestURL(
requests, requests,
'api/teams/topics', 'api/teams/topics',
......
...@@ -3,9 +3,11 @@ define([ ...@@ -3,9 +3,11 @@ define([
'underscore', 'underscore',
'teams/js/collections/team', 'teams/js/collections/team',
'teams/js/collections/team_membership', 'teams/js/collections/team_membership',
], function (Backbone, _, TeamCollection, TeamMembershipCollection) { 'teams/js/collections/topic'
], function (Backbone, _, TeamCollection, TeamMembershipCollection, TopicCollection) {
'use strict'; 'use strict';
var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse, var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse,
createMockTopicData, createMockTopicCollection,
testCourseID = 'course/1', testCourseID = 'course/1',
testUser = 'testUser', testUser = 'testUser',
testTeamDiscussionID = "12345", testTeamDiscussionID = "12345",
...@@ -228,6 +230,38 @@ define([ ...@@ -228,6 +230,38 @@ define([
); );
}; };
createMockTopicData = function (startIndex, stopIndex) {
return _.map(_.range(startIndex, stopIndex + 1), function (i) {
return {
"description": "description " + i,
"name": "topic " + i,
"id": "id " + i,
"team_count": 0
};
});
};
createMockTopicCollection = function (topicData) {
topicData = topicData !== undefined ? topicData : createMockTopicData(1, 5);
return new TopicCollection(
{
count: topicData.length + 1,
current_page: 1,
num_pages: 2,
start: 0,
results: topicData,
sort_order: "name"
},
{
teamEvents: teamEvents,
course_id: 'my/course/id',
parse: true,
url: 'api/teams/topics'
}
);
};
return { return {
teamEvents: teamEvents, teamEvents: teamEvents,
testCourseID: testCourseID, testCourseID: testCourseID,
...@@ -244,6 +278,8 @@ define([ ...@@ -244,6 +278,8 @@ define([
createMockDiscussionResponse: createMockDiscussionResponse, createMockDiscussionResponse: createMockDiscussionResponse,
createAnnotatedContentInfo: createAnnotatedContentInfo, createAnnotatedContentInfo: createAnnotatedContentInfo,
createMockThreadResponse: createMockThreadResponse, createMockThreadResponse: createMockThreadResponse,
createMockTopicData: createMockTopicData,
createMockTopicCollection: createMockTopicCollection,
verifyCards: verifyCards verifyCards: verifyCards
}; };
}); });
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