Skip to content

Commit

Permalink
Merge branch 'callumacrae-fix-change'
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaSh committed Oct 21, 2016
2 parents b582c5c + f2bb71a commit 7b72817
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default {
this.list.currentPage = typeof page == 'number' ? page - 1 : page;

this.setLimitedPages(limit);
this.update(this.originalList);
};

// Another way to navigate pages (Next & Prev)
Expand All @@ -83,6 +84,8 @@ export default {
this.list.currentPage = (this.list.currentPage + 1 < this.list.numberOfPages) ?
this.list.currentPage + 1 :
this.list.currentPage;

this.update(this.originalList);
};

vm['prev' + utils.capitalize(this.listName) + 'Page'] = () => {
Expand All @@ -91,6 +94,8 @@ export default {
this.list.currentPage = (this.list.currentPage - 1 > 0) ?
this.list.currentPage - 1 :
0;

this.update(this.originalList);
};

vm['refresh' + utils.capitalize(this.listName) + 'Page'] = () => {
Expand Down
42 changes: 22 additions & 20 deletions test/functional/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,51 @@ describe('Vue-Paginate', () => {
vm.$data.langs.should.eql(['PHP', 'JS']);

vm.changeLangsPage(2);
triggerUpdate();

vm.$data.currentLangsPage.should.equal(2);
vm.$data.langs.should.eql(['Ruby', 'Python']);
});

it('refreshes the list', () => {
it('refreshes the list', (done) => {
vm.$data.langsLinks.should.have.length(2);
vm.$data.fullLangs = ['PHP', 'JS', 'Ruby', 'Python', 'Java', 'Erlang'];

vm.refreshLangsPage();
triggerUpdate();

vm.$data.langsLinks.should.have.length(3);
Vue.nextTick(() => {
vm.$data.langsLinks.should.have.length(3);
done();
});
});

it('supports next/prev navigation', () => {
it('supports next/prev navigation', (done) => {
vm.$data.currentLangsPage.should.equal(1);
vm.$data.langs.should.eql(['PHP', 'JS']);

vm.nextLangsPage();
triggerUpdate();

vm.$data.currentLangsPage.should.equal(2);
vm.$data.langs.should.eql(['Ruby', 'Python']);
Vue.nextTick(() => {
vm.$data.currentLangsPage.should.equal(2);
vm.$data.langs.should.eql(['Ruby', 'Python']);

vm.prevLangsPage();
triggerUpdate();
vm.prevLangsPage();

vm.$data.currentLangsPage.should.equal(1);
vm.$data.langs.should.eql(['PHP', 'JS']);
Vue.nextTick(() => {
vm.$data.currentLangsPage.should.equal(1);
vm.$data.langs.should.eql(['PHP', 'JS']);

done();
});
});
});

it('checks if there is a need to show the navigation links', () => {
it('checks if there is a need to show the navigation links', (done) => {
vm.$data.hasLangsLinks.should.be.true;

vm.$data.fullLangs = ['PHP', 'JS'];
vm.refreshLangsPage();
triggerUpdate();

vm.$data.hasLangsLinks.should.be.false;
Vue.nextTick(() => {
vm.$data.hasLangsLinks.should.be.false;
done();
});
});

it('can be applied on multiple lists at the same time', () => {
Expand Down Expand Up @@ -178,5 +182,3 @@ describe('Vue-Paginate', () => {

});
});

var triggerUpdate = () => vm._directives[0].update(vm.$data.fullLangs);

0 comments on commit 7b72817

Please sign in to comment.