Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(pagination): hide pagination if there are not results
Browse files Browse the repository at this point in the history
Closes: #181
  • Loading branch information
rayrutjes committed Jul 19, 2017
1 parent e851553 commit f4dac58
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/Pagination.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<ul :class="bem()">
<ul :class="bem()" v-show="totalResults > 0">
<li :class="[bem('item', 'first'), page === 1 ? bem('item', 'disabled') : '']">
<a href="#" @click.prevent="goToFirstPage">
<slot name="first">&lt;&lt;</slot>
Expand Down Expand Up @@ -84,6 +84,9 @@ export default {
return pages;
},
totalResults() {
return this.searchStore.totalResults;
},
},
methods: {
goToPage(page) {
Expand Down
64 changes: 64 additions & 0 deletions src/components/__tests__/__snapshots__/pagination.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,70 @@ exports[`accepts custom padding 1`] = `
`;

exports[`it should be hidden if there are no results in the current context 1`] = `
<ul class="ais-pagination"
style="display: none;"
>
<li class="ais-pagination__item ais-pagination__item--first ais-pagination__item ais-pagination__item--disabled">
<a href="#">
&lt;&lt;
</a>
</li>
<li class="ais-pagination__item ais-pagination__item--previous ais-pagination__item ais-pagination__item--disabled">
<a href="#">
&lt;
</a>
</li>
<li class="ais-pagination__item ais-pagination__item ais-pagination__item--active">
<a href="#">
1
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
2
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
3
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
4
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
5
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
6
</a>
</li>
<li class="ais-pagination__item">
<a href="#">
7
</a>
</li>
<li class="ais-pagination__item ais-pagination__item--next">
<a href="#">
&gt;
</a>
</li>
<li class="ais-pagination__item ais-pagination__item--last">
<a href="#">
&gt;&gt;
</a>
</li>
</ul>
`;

exports[`renders proper HTML 1`] = `
<ul class="ais-pagination">
Expand Down
22 changes: 22 additions & 0 deletions src/components/__tests__/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test('renders proper HTML', () => {
const searchStore = {
page: 2,
totalPages: 10,
totalResults: 4000,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
Expand All @@ -21,6 +22,7 @@ test('accepts custom padding', () => {
const searchStore = {
page: 5,
totalPages: 10,
totalResults: 4000,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
Expand All @@ -38,6 +40,7 @@ test('it should not try to go to a previous page that would be inferior to 1', (
const searchStore = {
page: 1,
totalPages: 20,
totalResults: 4000,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
Expand All @@ -55,6 +58,7 @@ test('it should not try to go to a next page that would be superior to total exi
const searchStore = {
page: 20,
totalPages: 20,
totalResults: 4000,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
Expand All @@ -67,3 +71,21 @@ test('it should not try to go to a next page that would be superior to total exi

expect(searchStore.page).toEqual(20);
});

test('it should be hidden if there are no results in the current context', () => {
const searchStore = {
page: 1,
totalPages: 20,
totalResults: 0,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
propsData: {
searchStore,
},
});

vm.$mount();

expect(vm.$el.outerHTML).toMatchSnapshot();
});

0 comments on commit f4dac58

Please sign in to comment.