Commit c7fd48a0 by Tim Krones

Add integration tests for pagination.

parent 6ee520a0
...@@ -18,9 +18,16 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -18,9 +18,16 @@ function StudentAnswersDashboardBlock(runtime, element) {
model: Result, model: Result,
getCurrentPage: function() { getCurrentPage: function(object) {
var currentPage = this.state.currentPage; var currentPage = this.state.currentPage;
return this.getPage(currentPage); if (object) {
return this.getPage(currentPage);
}
return currentPage;
},
getTotalPages: function() {
return this.state.totalPages;
} }
}); });
...@@ -28,9 +35,9 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -28,9 +35,9 @@ function StudentAnswersDashboardBlock(runtime, element) {
var ResultsView = Backbone.View.extend({ var ResultsView = Backbone.View.extend({
render: function() { render: function() {
this._insertRecords(this.collection.getCurrentPage()); this._insertRecords(this.collection.getCurrentPage(true));
this._updateControls(); this._updateControls();
this.$('#total-pages').text(this.collection.state.totalPages); this.$('#total-pages').text(this.collection.getTotalPages() || 0);
return this; return this;
}, },
...@@ -47,7 +54,11 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -47,7 +54,11 @@ function StudentAnswersDashboardBlock(runtime, element) {
}); });
tbody.append(row); tbody.append(row);
}, this); }, this);
this.$('#current-page').text(this.collection.state.currentPage); if (this.collection.getTotalPages()) {
this.$('#current-page').text(this.collection.getCurrentPage());
} else {
this.$('#current-page').text(0);
}
}, },
events: { events: {
...@@ -82,8 +93,8 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -82,8 +93,8 @@ function StudentAnswersDashboardBlock(runtime, element) {
}, },
_updateControls: function() { _updateControls: function() {
var currentPage = this.collection.state.currentPage, var currentPage = this.collection.getCurrentPage(),
totalPages = this.collection.state.totalPages, totalPages = this.collection.getTotalPages(),
firstPage = '#first-page', firstPage = '#first-page',
prevPage = '#prev-page', prevPage = '#prev-page',
nextPage = '#next-page', nextPage = '#next-page',
...@@ -91,7 +102,7 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -91,7 +102,7 @@ function StudentAnswersDashboardBlock(runtime, element) {
all = [firstPage, prevPage, nextPage, lastPage], all = [firstPage, prevPage, nextPage, lastPage],
backward = [firstPage, prevPage], backward = [firstPage, prevPage],
forward = [nextPage, lastPage]; forward = [nextPage, lastPage];
if (totalPages === 1) { if (!totalPages || totalPages === 1) {
this._disable(all); this._disable(all);
} else { } else {
if (currentPage === 1) { if (currentPage === 1) {
......
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