mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
fix(pagination): handle numeric jump input
This commit is contained in:
@@ -230,7 +230,7 @@ const handlePageSizeChange = (value: string | number | boolean | null) => {
|
||||
}
|
||||
|
||||
const submitJump = () => {
|
||||
const value = jumpPage.value.trim()
|
||||
const value = String(jumpPage.value).trim()
|
||||
if (!value) return
|
||||
const pageNum = Number.parseInt(value, 10)
|
||||
if (Number.isNaN(pageNum)) return
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { enableAutoUnmount, mount } from '@vue/test-utils'
|
||||
import Pagination from '../Pagination.vue'
|
||||
|
||||
vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
function mountPagination() {
|
||||
return mount(Pagination, {
|
||||
props: { total: 200, page: 1, pageSize: 20, showJump: true, showPageSizeSelector: false },
|
||||
global: { stubs: { Icon: true } }
|
||||
})
|
||||
}
|
||||
|
||||
describe('pagination jump input', () => {
|
||||
it.each(['click', 'enter'])('jumps to the entered numeric page using %s', async (action) => {
|
||||
const wrapper = mountPagination()
|
||||
const input = wrapper.get('input[type="number"]')
|
||||
await input.setValue('3')
|
||||
if (action === 'click') await wrapper.get('.btn').trigger('click')
|
||||
else await input.trigger('keyup', { key: 'Enter' })
|
||||
expect(wrapper.emitted('update:page')).toEqual([[3]])
|
||||
expect((input.element as HTMLInputElement).value).toBe('')
|
||||
})
|
||||
|
||||
it('clamps an entered page to the last page', async () => {
|
||||
const wrapper = mountPagination()
|
||||
await wrapper.get('input').setValue('99')
|
||||
await wrapper.get('.btn').trigger('click')
|
||||
expect(wrapper.emitted('update:page')).toEqual([[10]])
|
||||
})
|
||||
|
||||
it('ignores an empty jump input', async () => {
|
||||
const wrapper = mountPagination()
|
||||
await wrapper.get('.btn').trigger('click')
|
||||
expect(wrapper.emitted('update:page')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user