Commit 2d29751d by Ehtesham

fixing paging footer in topics tab

parent 9cb660a7
......@@ -521,6 +521,23 @@ class BrowseTopicsTest(TeamsTabBase):
self.assertEqual(len(self.topics_page.topic_cards), TOPICS_PER_PAGE)
self.assertTrue(self.topics_page.get_pagination_header_text().startswith('Showing 1-12 out of 13 total'))
def test_topic_pagination_one_page(self):
"""
Scenario: Browsing topics when there are fewer topics than the page size i.e. 12
all topics should show on one page
Given I am enrolled in a course with team configuration and topics
When I visit the Teams page
And I browse topics
And I should see corrected number of topic cards
And I should see the correct page header
And I should not see a pagination footer
"""
self.set_team_configuration({u"max_team_size": 10, u"topics": self.create_topics(10)})
self.topics_page.visit()
self.assertEqual(len(self.topics_page.topic_cards), 10)
self.assertTrue(self.topics_page.get_pagination_header_text().startswith('Showing 1-10 out of 10 total'))
self.assertFalse(self.topics_page.pagination_controls_visible())
def test_topic_description_truncation(self):
"""
Scenario: excessively long topic descriptions should be truncated so
......
......@@ -6,7 +6,9 @@
constructor: function (models, options) {
this.options = options;
this.url = options.url;
this.state.perPage = options.per_page;
if (options.perPage) {
this.state.pageSize = options.perPage;
}
this.course_id = options.course_id;
this.teamEvents = options.teamEvents;
......@@ -33,6 +35,8 @@
this.isStale = true;
},
// TODO: These changes has been added to backbone.paginator
// remove when backbone.paginator gets a new release
sync: function (method, model, options) {
// do not send total pages and total records in request
if (method === 'read') {
......
......@@ -8,9 +8,7 @@
},
text_search: function () {
return this.searchString || '';
},
totalPages: null,
totalRecords: null
}
},
constructor: function (teams, options) {
......
;(function (define) {
'use strict';
define(['teams/js/collections/base', 'teams/js/models/team_membership'],
function(BaseCollection, TeamMembershipModel) {
var TeamMembershipCollection = BaseCollection.extend({
initialize: function(team_memberships, options) {
this.url = options.url;
var self = this;
BaseCollection.prototype.initialize.call(this, options);
this.perPage = options.per_page || 10;
this.username = options.username;
this.server_api = _.extend(
{
expand: 'team,user',
username: this.username,
course_id: function () { return encodeURIComponent(self.course_id); }
},
BaseCollection.prototype.server_api
);
delete this.server_api['sort_order']; // Sort order is not specified for the TeamMembership API
delete this.server_api['order_by']; // Order by is not specified for the TeamMembership API
},
model: TeamMembershipModel
});
return TeamMembershipCollection;
});
}).call(this, define || RequireJS.define);
......@@ -6,7 +6,6 @@
model: TopicModel,
state: {
perPage: null,
sortKey: 'name'
},
......@@ -16,12 +15,13 @@
},
constructor: function(topics, options) {
BaseCollection.prototype.constructor.call(this, topics, options);
this.state.pageSize = topics.results.length;
if (topics.sort_order) {
this.state.sortKey = topics.sort_order;
}
options.perPage = topics.results.length;
BaseCollection.prototype.constructor.call(this, topics, options);
this.registerSortableField('name', gettext('name'));
// Translators: This refers to the number of teams (a count of how many teams there are)
this.registerSortableField('team_count', gettext('team count'));
......
......@@ -20,8 +20,9 @@ define(['backbone', 'URI', 'underscore', 'common/js/spec_helpers/ajax_helpers',
expect(params[param]).toBe(value);
};
it('sets its perPage based on initial page size', function () {
it('sets its page size based on initial page size', function () {
expect(topicCollection.getPageSize()).toBe(5);
expect(topicCollection.getTotalPages()).toBe(2);
});
it('sorts by name', function () {
......
......@@ -2,10 +2,9 @@ define([
'backbone',
'underscore',
'teams/js/collections/team',
'teams/js/collections/team_membership',
'teams/js/collections/topic',
'teams/js/models/topic'
], function (Backbone, _, TeamCollection, TeamMembershipCollection, TopicCollection, TopicModel) {
], function (Backbone, _, TeamCollection, TopicCollection, TopicModel) {
'use strict';
var createMockPostResponse, createMockDiscussionResponse, createAnnotatedContentInfo, createMockThreadResponse,
createMockTopicData, createMockTopicCollection, createMockTopic,
......@@ -63,9 +62,7 @@ define([
return new collectionType(
createMockTeamsResponse(responseOptions),
_.extend({
state: {
pageSize: 5
},
perPage: 5,
teamEvents: teamEvents,
course_id: testCourseID,
parse: true
......@@ -289,9 +286,6 @@ define([
sort_order: 'name'
},
{
state: {
pageSize: 5
},
teamEvents: teamEvents,
course_id: testCourseID,
parse: true,
......
......@@ -103,7 +103,7 @@
teamEvents: this.teamEvents,
course_id: this.context.courseID,
username: this.context.userInfo.username,
per_page: 2,
perPage: 2,
parse: true,
url: this.context.myTeamsUrl
}
......@@ -337,7 +337,7 @@
course_id: view.context.courseID,
topic_id: topicID,
url: view.context.teamsUrl,
per_page: 10
perPage: 10
});
view.teamsCollection = collection;
collection.getPage(1).then(function () {
......@@ -346,7 +346,7 @@
collection: collection,
breadcrumbs: view.createBreadcrumbs(),
showSortControls: true
});
});
deferred.resolve(teamsView);
});
});
......
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