2016-11-03 02:14:36 +00:00
|
|
|
import { createTest, createVue, triggerEvent, destroyVM } from '../util';
|
2016-10-21 08:14:14 +00:00
|
|
|
import Pagination from 'packages/pagination';
|
|
|
|
|
|
|
|
describe('Pagination', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
let vm;
|
|
|
|
afterEach(() => {
|
|
|
|
destroyVM(vm);
|
|
|
|
});
|
2016-10-21 08:14:14 +00:00
|
|
|
it('create', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination);
|
2016-10-21 08:14:14 +00:00
|
|
|
const elm = vm.$el;
|
|
|
|
// prev
|
|
|
|
expect(elm.querySelector('button.btn-prev')).to.exist;
|
|
|
|
// pager
|
|
|
|
expect(elm.querySelector('ul.el-pager')).to.exist;
|
|
|
|
// next
|
|
|
|
expect(elm.querySelector('button.btn-next')).to.exist;
|
|
|
|
// jumper
|
|
|
|
expect(elm.querySelector('.el-pagination__jump')).to.exist;
|
|
|
|
// ->
|
|
|
|
expect(elm.querySelector('.el-pagination__rightwrapper')).to.exist;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('set layout', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
layout: 'prev, pager, next'
|
|
|
|
});
|
|
|
|
const elm = vm.$el;
|
|
|
|
// prev
|
|
|
|
expect(elm.querySelector('button.btn-prev')).to.exist;
|
|
|
|
// pager
|
|
|
|
expect(elm.querySelector('ul.el-pager')).to.exist;
|
|
|
|
// next
|
|
|
|
expect(elm.querySelector('button.btn-next')).to.exist;
|
|
|
|
// not found jumper
|
|
|
|
expect(elm.querySelector('.el-pagination__jump')).to.not.exist;
|
|
|
|
// not found ->
|
|
|
|
expect(elm.querySelector('.el-pagination__rightwrapper')).to.not.exist;
|
|
|
|
// not found total
|
|
|
|
expect(elm.querySelector('.el-pagination__total')).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2016-12-21 04:37:45 +00:00
|
|
|
it('layout: all in right, need clear float', () => {
|
|
|
|
vm = createTest(Pagination, {
|
|
|
|
layout: '->, prev, pager, next',
|
|
|
|
total: 100
|
|
|
|
}, true);
|
|
|
|
const elm = vm.$el;
|
|
|
|
let right_div = elm.querySelector('.el-pagination__rightwrapper');
|
|
|
|
expect(elm.clientHeight > 0 && right_div.clientHeight > 0).to.equal(true);
|
|
|
|
// elm 将来 padding 可能会变化, 所以使用 >= 来判定
|
|
|
|
expect(elm.clientHeight >= right_div.clientHeight).to.equal(true);
|
|
|
|
});
|
|
|
|
|
2016-12-20 03:20:57 +00:00
|
|
|
it('custom slot', () => {
|
|
|
|
vm = createVue({
|
|
|
|
template: `
|
|
|
|
<el-pagination
|
|
|
|
layout="slot, prev, pager, next"
|
|
|
|
:page-size="25"
|
|
|
|
:total="100">
|
|
|
|
<span class="slot-test">slot test</span>
|
|
|
|
</el-pagination>
|
|
|
|
`
|
|
|
|
});
|
|
|
|
expect(vm.$el.querySelector('.slot-test')).to.exist;
|
|
|
|
});
|
|
|
|
|
2016-10-21 08:14:14 +00:00
|
|
|
it('small', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
small: true
|
|
|
|
});
|
|
|
|
expect(vm.$el.classList.contains('el-pagination--small')).to.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageSize', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
pageSize: 25,
|
|
|
|
total: 100
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.querySelectorAll('li.number')).to.length(4);
|
|
|
|
});
|
|
|
|
|
2016-11-04 12:04:46 +00:00
|
|
|
it('pageCount', () => {
|
|
|
|
const vm = createTest(Pagination, {
|
|
|
|
pageSize: 25,
|
|
|
|
pageCount: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.querySelectorAll('li.number')).to.length(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will work without total & page-count', (done) => {
|
|
|
|
const vm = createTest(Pagination, {
|
|
|
|
pageSize: 25,
|
|
|
|
currentPage: 2
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.$el.querySelector('.btn-prev').click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
vm.internalCurrentPage.should.be.equal(1);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.btn-prev').click();
|
|
|
|
vm.internalCurrentPage.should.be.equal(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 20);
|
|
|
|
});
|
|
|
|
|
2016-10-21 08:14:14 +00:00
|
|
|
it('currentPage', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
pageSize: 20,
|
|
|
|
total: 200,
|
|
|
|
currentPage: 3
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('3');
|
|
|
|
});
|
|
|
|
|
2016-11-24 08:03:00 +00:00
|
|
|
it('set currentPage & total', (done) => {
|
|
|
|
vm = createVue({
|
|
|
|
template: `
|
|
|
|
<el-pagination
|
|
|
|
@current-change="handleChange"
|
|
|
|
:current-page="currentPage"
|
|
|
|
:page-size="10"
|
|
|
|
:total="100" />
|
|
|
|
`,
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
handleChange(val) {
|
|
|
|
this.currentPage = val;
|
|
|
|
this.page = val;
|
|
|
|
},
|
|
|
|
resetTotal() {
|
|
|
|
this.total = 30;
|
|
|
|
this.currentPage = 1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
currentPage: 10
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('10');
|
|
|
|
vm.resetTotal();
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.$el.querySelector('li.number.active')).to.have.property('textContent').to.equal('1');
|
|
|
|
done();
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
2016-10-21 08:14:14 +00:00
|
|
|
it('pageSizes', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
pageSizes: [10, 15, 35, 50],
|
|
|
|
pageSize: 35,
|
|
|
|
total: 1000,
|
|
|
|
layout: 'sizes, prev, pager, next'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.el-select-dropdown__item.selected')).to.property('textContent').include('35');
|
|
|
|
expect([].slice.call(vm.$el.querySelectorAll('.el-select-dropdown__item'))
|
|
|
|
.map(node => parseInt(node.textContent, 10)))
|
|
|
|
.to.deep.equal([10, 15, 35, 50]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageSizes:not found pageSize', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
pageSizes: [10, 15, 35, 50],
|
|
|
|
pageSize: 24,
|
|
|
|
total: 1000,
|
|
|
|
layout: 'sizes, prev, pager, next'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.el-select-dropdown__item.selected')).to.property('textContent').include('10');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('layout is empty', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
layout: ''
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(vm.$el.textContent).to.empty;
|
|
|
|
});
|
|
|
|
|
2016-11-24 08:03:00 +00:00
|
|
|
it('jumper: change value', (done) => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createVue({
|
2016-10-21 08:14:14 +00:00
|
|
|
template: `
|
|
|
|
<el-pagination
|
2016-10-26 04:27:18 +00:00
|
|
|
@current-change="handleChange"
|
2016-10-21 08:14:14 +00:00
|
|
|
:page-size="10"
|
|
|
|
:total="100" />
|
|
|
|
`,
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
handleChange(val) {
|
|
|
|
this.page = val;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
2016-11-10 07:36:27 +00:00
|
|
|
return { page: 1 };
|
2016-10-21 08:14:14 +00:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
const input = vm.$el.querySelector('.el-pagination__jump input');
|
|
|
|
|
|
|
|
input.focus();
|
|
|
|
input.value = -1;
|
|
|
|
triggerEvent(input, 'change');
|
2016-11-24 08:03:00 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.page).to.equal(1);
|
|
|
|
|
|
|
|
input.value = 10000;
|
|
|
|
triggerEvent(input, 'change');
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.page).to.equal(10);
|
|
|
|
|
|
|
|
input.value = '我好帅';
|
|
|
|
triggerEvent(input, 'change');
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.page).to.equal(1);
|
|
|
|
done();
|
|
|
|
}, 50);
|
|
|
|
}, 50);
|
|
|
|
}, 50);
|
2016-10-21 08:14:14 +00:00
|
|
|
});
|
|
|
|
|
2016-11-24 08:03:00 +00:00
|
|
|
it('event:current-change', (done) => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createVue({
|
2016-10-21 08:14:14 +00:00
|
|
|
template: `
|
|
|
|
<el-pagination
|
|
|
|
:total="1000"
|
2016-10-26 04:27:18 +00:00
|
|
|
@current-change="change = true" />
|
2016-10-21 08:14:14 +00:00
|
|
|
`,
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return { change: false };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const next = vm.$el.querySelector('button.btn-next');
|
|
|
|
const prev = vm.$el.querySelector('button.btn-prev');
|
|
|
|
|
|
|
|
expect(vm.change).to.false;
|
|
|
|
// click 9
|
|
|
|
let count = 9;
|
|
|
|
while (--count) {
|
|
|
|
next.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
prev.click();
|
2016-11-24 08:03:00 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(vm.change).to.true;
|
|
|
|
done();
|
|
|
|
}, 50);
|
2016-10-21 08:14:14 +00:00
|
|
|
});
|
|
|
|
|
2016-10-26 04:27:18 +00:00
|
|
|
it('event:size-change', done => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createVue({
|
2016-10-21 08:14:14 +00:00
|
|
|
template: `
|
|
|
|
<el-pagination
|
|
|
|
:total="100"
|
|
|
|
layout="sizes, prev, pager, next"
|
2016-10-26 04:27:18 +00:00
|
|
|
@size-change="trigger = true"
|
2016-10-21 08:14:14 +00:00
|
|
|
:pageSize="10" />
|
|
|
|
`,
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return { trigger: false };
|
|
|
|
}
|
2016-11-24 08:03:00 +00:00
|
|
|
}, true);
|
2016-10-21 08:14:14 +00:00
|
|
|
|
|
|
|
expect(vm.trigger).to.false;
|
2016-11-24 08:03:00 +00:00
|
|
|
|
2016-10-21 08:14:14 +00:00
|
|
|
setTimeout(_ => {
|
2016-11-04 08:42:39 +00:00
|
|
|
vm.$el.querySelectorAll('li.el-select-dropdown__item')[1].click();
|
|
|
|
setTimeout(_ => {
|
|
|
|
expect(vm.trigger).to.true;
|
|
|
|
done();
|
|
|
|
}, 50);
|
2016-10-21 08:14:14 +00:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('pageSize > total', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createVue({
|
2016-10-21 08:14:14 +00:00
|
|
|
template: `
|
|
|
|
<el-pagination
|
2016-10-26 04:27:18 +00:00
|
|
|
@current-change="handleChange"
|
2016-10-21 08:14:14 +00:00
|
|
|
:page-size="1000"
|
|
|
|
:total="0" />
|
|
|
|
`,
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
handleChange(val) {
|
|
|
|
this.page = val;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
2016-11-10 07:36:27 +00:00
|
|
|
return { page: 1 };
|
2016-10-21 08:14:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
const input = vm.$el.querySelector('.el-pagination__jump input');
|
|
|
|
|
2016-11-04 12:04:46 +00:00
|
|
|
input.value = 2;
|
2016-10-21 08:14:14 +00:00
|
|
|
triggerEvent(input, 'change');
|
2016-11-04 12:04:46 +00:00
|
|
|
expect(vm.page).to.equal(1);
|
2016-10-21 08:14:14 +00:00
|
|
|
|
|
|
|
input.value = '我好帅';
|
|
|
|
triggerEvent(input, 'change');
|
2016-11-04 12:04:46 +00:00
|
|
|
expect(vm.page).to.equal(1);
|
2016-10-21 08:14:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('click pager', () => {
|
|
|
|
it('click ul', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
total: 1000
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.el-pager').click();
|
|
|
|
expect(vm.internalCurrentPage).to.equal(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('click li', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
total: 1000
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
vm.$el.querySelectorAll('.el-pager li.number')[1].click();
|
|
|
|
expect(vm.internalCurrentPage).to.equal(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('click next icon-more', () => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
total: 1000
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.el-pager .more').click();
|
|
|
|
expect(vm.internalCurrentPage).to.equal(6);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('click prev icon-more', done => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
total: 1000
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
vm.$el.querySelector('.btn-quicknext.more').click();
|
|
|
|
setTimeout(_ => {
|
|
|
|
expect(vm.$el.querySelector('.btn-quickprev.more')).to.exist;
|
|
|
|
vm.$el.querySelector('.btn-quickprev.more').click();
|
|
|
|
expect(vm.internalCurrentPage).to.equal(1);
|
|
|
|
done();
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('click last page', done => {
|
2016-11-03 02:14:36 +00:00
|
|
|
vm = createTest(Pagination, {
|
2016-10-21 08:14:14 +00:00
|
|
|
total: 1000
|
|
|
|
}, true);
|
|
|
|
const nodes = vm.$el.querySelectorAll('li.number');
|
|
|
|
|
|
|
|
nodes[nodes.length - 1].click();
|
|
|
|
setTimeout(_ => {
|
|
|
|
expect(vm.$el.querySelector('.btn-quickprev.more')).to.exist;
|
|
|
|
expect(vm.$el.querySelector('.btn-quicknext.more')).to.not.exist;
|
|
|
|
done();
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|