Commit 41f207de by cahrens

The stale flag needs to take into account its previous state.

Otherwise it can change from false to true without re-rendering. TNL-3072
parent 8b704cc2
;(function (define) {
'use strict';
define(['teams/js/collections/base', 'teams/js/models/topic', 'gettext', 'underscore'],
function(BaseCollection, TopicModel, gettext, _) {
define(['underscore', 'gettext', 'teams/js/collections/base', 'teams/js/models/topic'],
function(_, gettext, BaseCollection, TopicModel) {
var TopicCollection = BaseCollection.extend({
initialize: function(topics, options) {
var self = this;
......@@ -25,7 +25,7 @@
},
onUpdate: function(event) {
this.isStale = event.action === 'create';
this.isStale = this.isStale || event.action === 'create';
},
model: TopicModel
......
define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers', 'teams/js/collections/topic'],
function (Backbone, URI, _, AjaxHelpers, TopicCollection) {
define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers',
'teams/js/spec_helpers/team_spec_helpers'],
function (Backbone, URI, _, AjaxHelpers, TeamSpecHelpers) {
'use strict';
describe('TopicCollection', function () {
var topicCollection;
beforeEach(function () {
topicCollection = new TopicCollection(
{
"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
});
topicCollection = TeamSpecHelpers.createMockTopicCollection();
});
var testRequestParam = function (self, param, value) {
......
......@@ -4,17 +4,7 @@ define([
], function (Backbone, _, TopicCollection, TopicsView, TeamSpecHelpers, AjaxHelpers) {
'use strict';
describe('TopicsView', function () {
var initialTopics, topicCollection, createTopicsView,
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
};
});
};
var initialTopics, topicCollection, createTopicsView, triggerUpdateEvent;
createTopicsView = function() {
return new TopicsView({
......@@ -24,25 +14,18 @@ define([
}).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 () {
setFixtures('<div class="topics-container"></div>');
initialTopics = generateTopics(1, 5);
topicCollection = new TopicCollection(
{
"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'
}
);
initialTopics = TeamSpecHelpers.createMockTopicData(1, 5);
topicCollection = TeamSpecHelpers.createMockTopicCollection(initialTopics);
});
it('can render the first of many pages', function () {
......@@ -64,8 +47,25 @@ define([
var requests = AjaxHelpers.requests(this),
topicsView = createTopicsView();
topicsView.collection.teamEvents.trigger('teams:update', { action: 'create' });
topicsView.render();
triggerUpdateEvent(topicsView);
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(
requests,
'api/teams/topics',
......
......@@ -3,9 +3,11 @@ define([
'underscore',
'teams/js/collections/team',
'teams/js/collections/team_membership',
], function (Backbone, _, TeamCollection, TeamMembershipCollection) {
'teams/js/collections/topic'
], function (Backbone, _, TeamCollection, TeamMembershipCollection, TopicCollection) {
'use strict';
var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse,
createMockTopicData, createMockTopicCollection,
testCourseID = 'course/1',
testUser = 'testUser',
testTeamDiscussionID = "12345",
......@@ -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 {
teamEvents: teamEvents,
testCourseID: testCourseID,
......@@ -244,6 +278,8 @@ define([
createMockDiscussionResponse: createMockDiscussionResponse,
createAnnotatedContentInfo: createAnnotatedContentInfo,
createMockThreadResponse: createMockThreadResponse,
createMockTopicData: createMockTopicData,
createMockTopicCollection: createMockTopicCollection,
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