Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination: add test #567

Merged
merged 1 commit into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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