mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-18 10:59:10 +08:00
* 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:
parent
35ae8f4a33
commit
b7450ff21d
@ -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)
|
||||
})
|
||||
|
||||
|
@ -176,6 +176,7 @@ export default defineComponent({
|
||||
|
||||
watch(() => props.currentPage, val => {
|
||||
internalCurrentPage.value = getValidCurrentPage(val)
|
||||
lastEmittedPage.value = internalCurrentPage.value
|
||||
})
|
||||
|
||||
watch(() => props.pageSize, val => {
|
||||
|
Loading…
Reference in New Issue
Block a user