cmvr-wms/ruoyi-ui-vue3/tests/runtime/assistant-pagination.spec.js
lixiaolong 99cbd807a2 feat(item-category): 添加物品分类申请与审核管理功能
- 新增物品分类申请及审核记录相关数据库表结构
- 添加物品分类管理菜单及对应的角色权限配置
- 实现物品分类申请组件支持新增申请与历史记录查询
- 开发批量AI分类组件以支持采购明细的智能分类推荐
- 新增批量确认小类组件以便管理员快速处理待确认分类
- 构建物品分类管理页面提供分类审核调整及关联记录查看
2026-11-09 09:12:26 +08:00

53 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, it, vi } from 'vitest'
import { defineComponent, effectScope, nextTick, reactive } from 'vue'
import { mount, shallowMount, flushPromises } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import { useAssistantPagination } from '@/utils/assistant-pagination'
import Preview from '@/components/BusinessAssistant/AssistantReferencePricePreview.vue'
import Draft from '@/components/BusinessAssistant/AssistantDraft.vue'
vi.mock('@/components/BusinessAssistant/AssistantField.vue',()=>({default:{template:'<span/>'}}))
it('defaults to 50 rows, supports 20/50/100, resets on resizing, and clamps after exclusions',()=>{
const scope=effectScope(),rows=reactive(Array.from({length:121},(_,id)=>({id})))
try{
const pager=scope.run(()=>useAssistantPagination(()=>rows))
expect(pager.pageRows.value).toHaveLength(50);expect(pager.pageSizes).toEqual([20,50,100])
pager.page.value=3;expect(pager.pageRows.value).toHaveLength(21)
pager.pageSize.value=100;expect(pager.page.value).toBe(1);expect(pager.pageRows.value).toHaveLength(100)
pager.page.value=2;rows.splice(10);expect(pager.page.value).toBe(1);expect(pager.pageRows.value).toHaveLength(10)
}finally{scope.stop()}
})
it('a real AI price preview displays all 34 quote items on its first page',async()=>{
const wrapper=mount(Preview,{props:{rows:Array.from({length:34},(_,id)=>({name:`报价物品${id+1}`,quantity:1,newActualPrice:id,newActualAmount:id}))},global:{plugins:[ElementPlus]}})
try{await flushPromises();expect(wrapper.findAll('.el-table__body tbody tr')).toHaveLength(34);expect(wrapper.find('.el-pagination').text()).toContain('34')}
finally{wrapper.unmount()}
})
it('the AI confirmation table renders 50 rows and changing to 100 resets the page without losing rows',async()=>{
const table=defineComponent({props:['data'],template:'<div><slot/></div>'}),pager=defineComponent({emits:['update:currentPage','update:pageSize'],template:'<div/>'})
const rows=Array.from({length:103},(_,id)=>({_rowId:String(id),userName:`测试用户${id}`}))
const wrapper=shallowMount(Draft,{props:{draft:{id:'test-pagination',version:1,status:'DRAFT',action:'user.create',fields:[{key:'userName',label:'账号'}]},rows},global:{stubs:{ElTable:table,ElTableColumn:true,ElPagination:pager}}})
try{
expect(wrapper.findComponent(table).props('data')).toHaveLength(50)
wrapper.findComponent(pager).vm.$emit('update:currentPage',3);await nextTick();expect(wrapper.findComponent(table).props('data')).toHaveLength(3)
wrapper.findComponent(pager).vm.$emit('update:pageSize',100);await nextTick();expect(wrapper.findComponent(table).props('data')).toHaveLength(100)
expect(rows).toHaveLength(103);expect(wrapper.emitted('change')).toBeUndefined()
}finally{wrapper.unmount()}
})
it.each([101,200])('a %s-item PDF purchase draft keeps its last editable source row across pages',async count=>{
const table=defineComponent({props:['data'],template:'<div><slot/></div>'}),pager=defineComponent({emits:['update:currentPage','update:pageSize'],template:'<div/>'})
const rows=Array.from({length:count},(_,index)=>({_rowId:`pdf-${index+1}`,_sourceRow:index+1,materialName:`PDF物品${index+1}`,quantity:1,unit:'件',finalUnitPrice:11.3}))
const wrapper=shallowMount(Draft,{props:{draft:{id:'pdf-purchase',version:1,status:'NEEDS_INPUT',action:'purchase.create',fields:[{key:'materialName',label:'物品名称'},{key:'quantity',label:'数量'},{key:'unit',label:'单位'}]},rows},global:{stubs:{ElTable:table,ElTableColumn:true,ElPagination:pager}}})
try{
wrapper.findComponent(pager).vm.$emit('update:currentPage',Math.ceil(count/50));await nextTick()
const visible=wrapper.findComponent(table).props('data');expect(visible.at(-1)._sourceRow).toBe(count);expect(visible.at(-1).materialName).toBe(`PDF物品${count}`);expect(rows).toHaveLength(count);expect(wrapper.text()).toContain(`${count} 项`);expect(wrapper.emitted('change')).toBeUndefined()
}finally{wrapper.unmount()}
})
it('one shared project produces one batch-level warning while retaining every source row and server error',()=>{
const rows=Array.from({length:101},(_,id)=>({_rowId:`project-${id}`,_sourceRow:id+1,materialName:`物品${id+1}`,_errors:['请填写项目']}))
const draft={id:'shared-project',version:1,status:'NEEDS_INPUT',action:'purchase.create',ready:false,fields:[{key:'materialName',label:'物品名称'},{key:'projectId',label:'项目',ref:'project',required:true}],errors:rows.map((_,id)=>`第${id+1}行:请填写项目`)}
const table=defineComponent({props:['data'],template:'<div><slot/></div>'})
const wrapper=shallowMount(Draft,{props:{draft,rows},global:{plugins:[ElementPlus],stubs:{ElTable:table,ElTableColumn:true,ElAlert:false}}})
try{expect(wrapper.text()).toContain('请在上方为本批次统一选择项目');expect(wrapper.text()).not.toContain('第1行:请填写项目');expect(wrapper.text()).not.toContain('查看其余');expect(rows).toHaveLength(101);expect(rows.every(row=>row._errors.includes('请填写项目'))).toBe(true);expect(draft.ready).toBe(false);expect(wrapper.emitted('change')).toBeUndefined()}
finally{wrapper.unmount()}
})