Skip to content

Commit

Permalink
Merge pull request #567 from QingWei-Li/test/pagination
Browse files Browse the repository at this point in the history
Pagination: add test
  • Loading branch information
Leopoldthecoder committed Oct 21, 2016
2 parents d6721ee + ef75d0d commit 6f15664
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/docs/zh-cn/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
padding: 30px 24px;
border-bottom: solid 1px #EFF2F6;
&:last-child {
border-bottom: none;
border-bottom: none;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/pagination/src/pager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
}
}
/* istanbul ignore if */
if (!isNaN(newPage)) {
if (newPage < 1) {
newPage = 1;
Expand Down
61 changes: 34 additions & 27 deletions packages/pagination/src/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default {

render(h) {
let template = <div class='el-pagination'></div>;
const layout = this.$options.layout || this.layout || '';
const layout = this.layout || '';
if (!layout) return;
const TEMPLATE_MAP = {
prev: <prev></prev>,
jumper: <jumper></jumper>,
Expand Down Expand Up @@ -116,7 +117,9 @@ export default {
Sizes: {
created() {
if (Array.isArray(this.$parent.pageSizes)) {
this.$parent.internalPageSize = this.$parent.pageSizes.indexOf(this.$parent.pageSize) > -1 ? this.$parent.pageSize : this.$parent.pageSizes[0];
this.$parent.internalPageSize = this.$parent.pageSizes.indexOf(this.$parent.pageSize) > -1
? this.$parent.pageSize
: this.$parent.pageSizes[0];
}
},

Expand Down Expand Up @@ -232,25 +235,26 @@ export default {
}
},

first() {
const oldPage = this.internalCurrentPage;
const newVal = 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal);
// XXX: 暂时没有到第一页和最后一页的交互
// first() {
// const oldPage = this.internalCurrentPage;
// const newVal = 1;
// this.internalCurrentPage = this.getValidCurrentPage(newVal);

if (this.internalCurrentPage !== oldPage) {
this.$emit('currentchange', this.internalCurrentPage);
}
},
// if (this.internalCurrentPage !== oldPage) {
// this.$emit('currentchange', this.internalCurrentPage);
// }
// },

last() {
const oldPage = this.internalCurrentPage;
const newVal = this.pageCount;
this.internalCurrentPage = this.getValidCurrentPage(newVal);
// last() {
// const oldPage = this.internalCurrentPage;
// const newVal = this.pageCount;
// this.internalCurrentPage = this.getValidCurrentPage(newVal);

if (this.internalCurrentPage !== oldPage) {
this.$emit('currentchange', this.internalCurrentPage);
}
},
// if (this.internalCurrentPage !== oldPage) {
// this.$emit('currentchange', this.internalCurrentPage);
// }
// },

getValidCurrentPage(value) {
value = parseInt(value, 10);
Expand All @@ -273,21 +277,23 @@ export default {
computed: {
pageCount() {
return Math.ceil(this.total / this.internalPageSize);
},
}

startRecordIndex() {
const result = (this.internalCurrentPage - 1) * this.internalPageSize + 1;
return result > 0 ? result : 0;
},
// XXX: 暂时没用到
// startRecordIndex() {
// const result = (this.internalCurrentPage - 1) * this.internalPageSize + 1;
// return result > 0 ? result : 0;
// },

endRecordIndex() {
const result = this.internalCurrentPage * this.internalPageSize;
return result > this.total ? this.total : result;
}
// endRecordIndex() {
// const result = this.internalCurrentPage * this.internalPageSize;
// return result > this.total ? this.total : result;
// }
},

watch: {
pageCount(newVal) {
/* istanbul ignore if */
if (newVal > 0 && this.internalCurrentPage === 0) {
this.internalCurrentPage = 1;
} else if (this.internalCurrentPage > newVal) {
Expand All @@ -312,6 +318,7 @@ export default {
internalCurrentPage(newVal, oldVal) {
newVal = parseInt(newVal, 10);

/* istanbul ignore if */
if (isNaN(newVal)) {
newVal = oldVal || 1;
} else {
Expand Down
16 changes: 8 additions & 8 deletions test/unit/specs/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ describe('DatePicker', () => {
expect(spans[1].textContent).to.include(date.getMonth() + 1);
$el.querySelector('.el-date-picker__prev-btn.el-icon-d-arrow-left').click();
// click 5
arrowLeftElm.click();
arrowLeftElm.click();
arrowLeftElm.click();
arrowLeftElm.click();
arrowLeftElm.click();
let count = 5;
while (--count) {
arrowLeftElm.click();
}

// click 3
arrowRightElm.click();
arrowRightElm.click();
arrowRightElm.click();
count = 3;
while (--count) {
arrowRightElm.click();
}
setTimeout(_ => {
expect(spans[0].textContent).to.include(date.getFullYear() - 1);
expect(spans[1].textContent).to.include(date.getMonth() - 1);
Expand Down
Loading

0 comments on commit 6f15664

Please sign in to comment.