fix(pagination): bug #2025 (#2062)

* fix(pagination): fix parent #2025

* fix(pagination): add test case for pagination

Co-authored-by: xing.wu <wuxing@bjca.org.cn>
This commit is contained in:
Xing.Wu 2021-05-27 16:38:54 +08:00 committed by GitHub
parent 35ae8f4a33
commit b7450ff21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View File

@ -321,3 +321,87 @@ describe('click pager', () => {
})
test('repeat click next & change current page', async () => {
const onCurrentChange = jest.fn()
const wrapper = mount({
components: {
[Pagination.name]: Pagination,
},
template: `
<el-pagination
:total="total"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
@current-change="onCurrentChange"
v-model:currentPage="currentPage"
/>
},
`,
methods: {
onCurrentChange,
},
data() {
return {
currentPage: 1,
total: 400,
pageSize: 100,
}
},
})
await nextTick()
expect(wrapper.vm.currentPage).toBe(1)
wrapper.find('.btn-next').trigger('click')
await nextTick()
expect(wrapper.vm.currentPage).toBe(2)
wrapper.vm.currentPage = 1
await nextTick()
expect(wrapper.vm.currentPage).toBe(1)
wrapper.find('.btn-next').trigger('click')
await nextTick()
expect(wrapper.vm.currentPage).toBe(2)
})
test('repeat click prev & change current page', async () => {
const onCurrentChange = jest.fn()
const wrapper = mount({
components: {
[Pagination.name]: Pagination,
},
template: `
<el-pagination
:total="total"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
@current-change="onCurrentChange"
v-model:currentPage="currentPage"
/>
},
`,
methods: {
onCurrentChange,
},
data() {
return {
currentPage: 2,
total: 400,
pageSize: 100,
}
},
})
await nextTick()
expect(wrapper.vm.currentPage).toBe(2)
wrapper.find('.btn-prev').trigger('click')
await nextTick()
expect(wrapper.vm.currentPage).toBe(1)
wrapper.vm.currentPage = 2
await nextTick()
expect(wrapper.vm.currentPage).toBe(2)
wrapper.find('.btn-prev').trigger('click')
await nextTick()
expect(wrapper.vm.currentPage).toBe(1)
})

View File

@ -176,6 +176,7 @@ export default defineComponent({
watch(() => props.currentPage, val => {
internalCurrentPage.value = getValidCurrentPage(val)
lastEmittedPage.value = internalCurrentPage.value
})
watch(() => props.pageSize, val => {