Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
josecebe#172 Add tests to 'changeTotalPages' method
  • Loading branch information
josecebe committed Jul 23, 2018
1 parent fa9e8d6 commit 1d4b80e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jquery.twbsPagination.js
Expand Up @@ -93,12 +93,13 @@
}
this.currentPage = page;

this.render(this.getPages(page));
var pages = this.getPages(page);
this.render(pages);
this.setupEvents();

this.$element.trigger('page', page);

return this;
return pages;
},

enable: function () {
Expand Down Expand Up @@ -243,7 +244,7 @@

changeTotalPages: function(totalPages, currentPage) {
this.options.totalPages = totalPages;
this.show(currentPage);
return this.show(currentPage);
},

makeHref: function (page) {
Expand Down
19 changes: 19 additions & 0 deletions tests/test.js
Expand Up @@ -418,4 +418,23 @@
);
$html.remove();
});

QUnit.test("Test 'changeTotalPages' method", function (assert) {
destroyAndCreateWithOpts(pag1, {
totalPages: 6,
visiblePages: 5
});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 30, 1), {currentPage: 1, numeric: [1, 2, 3, 4, 5]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 30, 2), {currentPage: 2, numeric: [1, 2, 3, 4, 5]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 30, 3), {currentPage: 3, numeric: [1, 2, 3, 4, 5]});

assert.deepEqual(pag1.twbsPagination('changeTotalPages', 40, 4), {currentPage: 4, numeric: [2, 3, 4, 5, 6]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 40, 5), {currentPage: 5, numeric: [3, 4, 5, 6, 7]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 40, 20), {currentPage: 20, numeric: [18, 19, 20, 21, 22]});

assert.deepEqual(pag1.twbsPagination('changeTotalPages', 50, 47), {currentPage: 47, numeric: [45, 46, 47, 48, 49]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 50, 48), {currentPage: 48, numeric: [46, 47, 48, 49, 50]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 50, 49), {currentPage: 49, numeric: [46, 47, 48, 49, 50]});
assert.deepEqual(pag1.twbsPagination('changeTotalPages', 50, 50), {currentPage: 50, numeric: [46, 47, 48, 49, 50]});
});
})(window.jQuery);

0 comments on commit 1d4b80e

Please sign in to comment.