From 1a32b91eb21c022fb8a02bc35bdf707211fcf462 Mon Sep 17 00:00:00 2001 From: "chihao.ou" Date: Wed, 16 Sep 2026 18:15:12 +0800 Subject: [PATCH] fix(pagination): handle numeric jump input --- frontend/src/components/common/Pagination.vue | 2 +- .../common/__tests__/Pagination.jump.spec.ts | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/common/__tests__/Pagination.jump.spec.ts diff --git a/frontend/src/components/common/Pagination.vue b/frontend/src/components/common/Pagination.vue index 9b4ac200e2..cdccd965df 100644 --- a/frontend/src/components/common/Pagination.vue +++ b/frontend/src/components/common/Pagination.vue @@ -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 diff --git a/frontend/src/components/common/__tests__/Pagination.jump.spec.ts b/frontend/src/components/common/__tests__/Pagination.jump.spec.ts new file mode 100644 index 0000000000..59e0870dba --- /dev/null +++ b/frontend/src/components/common/__tests__/Pagination.jump.spec.ts @@ -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() + }) +})