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

18 lines
4.3 KiB
JavaScript

import {afterEach,expect,it,vi} from 'vitest'
import {mount,flushPromises} from '@vue/test-utils'
import ElementPlus from 'element-plus'
import AcceptanceReport from '../../src/components/PurchaseSheet/AcceptanceReport.vue'
const api=vi.hoisted(()=>({request:vi.fn()}))
vi.mock('@/utils/request',()=>({default:api.request}))
const mounted=[];afterEach(()=>{mounted.splice(0).forEach(w=>w.unmount());document.body.innerHTML='';vi.resetAllMocks()})
const fields={purchaser:'甲方',supplier:'乙方',description:'材料',address:'重庆市九龙坡区金凤镇招商局检测车辆技术研究院有限公司',contractNo:'HT-2026-001',projectNo:'',deliveryLocation:'招商车研',date:null,checks:Array(7).fill('')}
const snapshot=(ready=true)=>({data:{ready,count:2,version:'fresh-version',fields,documents:[{label:'采购申请',numberLabel:'随行编号',numbered:true,files:1},{label:'合同',numberLabel:'合同编号',numbered:true,files:1}],checkLabels:['供货范围是否与合同/技术协议一致','机械安装','电气安装','系统调试','运行结果','培训','资料'],issues:ready?[]:[{line:2,name:'试验物品B',reason:'尚未全部验收通过'}]}})
function render(disabled=false){const w=mount(AcceptanceReport,{props:{sheet:{batch:{id:7,batchName:'验收批次'},version:'old-ui-version'},disabled},global:{plugins:[ElementPlus]},attachTo:document.body});mounted.push(w);return w}
const button=text=>[...document.querySelectorAll('button')].find(b=>b.textContent.trim()===text)
it('shows the exact incomplete row and blocks generation for partially accepted goods',async()=>{api.request.mockResolvedValue(snapshot(false));const w=render();await w.vm.open();await flushPromises();expect(document.body.textContent).toContain('试验物品B');expect(button('生成并保存').disabled).toBe(true)})
it('saves the whole batch as an attachment and emits the saved file',async()=>{api.request.mockResolvedValueOnce(snapshot()).mockResolvedValueOnce({data:{id:'saved-file',name:'验收资料_待签章.pdf'}});const w=render();await w.vm.open();await flushPromises();button('生成并保存').click();await flushPromises();const call=api.request.mock.calls[1][0];expect(call).toMatchObject({url:'/warehouse/purchase/sheet/7/acceptance-generate',params:{version:'fresh-version'},data:{fields:{contractNo:'HT-2026-001',projectNo:'',deliveryLocation:'招商车研'}}});expect(call.data.requestId).toMatch(/^[0-9a-f-]{36}$/);expect(call.data).not.toHaveProperty('rowIds');expect(w.emitted('generated')[0][0].id).toBe('saved-file')})
it('requires request and contract documents even when all goods passed',async()=>{const data=snapshot();data.data.ready=false;data.data.documents[0]={label:'采购申请',numberLabel:'随行编号',numbered:false,files:0};api.request.mockResolvedValue(data);const w=render();await w.vm.open();await flushPromises();expect(document.body.textContent).toContain('缺少随行编号');expect(document.body.textContent).toContain('缺少PDF附件');expect(button('生成并保存').disabled).toBe(true)})
it('reuses the generation identity after a failed response',async()=>{api.request.mockResolvedValueOnce(snapshot()).mockRejectedValueOnce(new Error('response lost')).mockResolvedValueOnce({data:{id:'saved-file'}});const w=render();await w.vm.open();await flushPromises();button('生成并保存').click();await flushPromises();button('生成并保存').click();await flushPromises();expect(api.request.mock.calls[1][0].data.requestId).toBe(api.request.mock.calls[2][0].data.requestId)})
it('reads the contract number and fixes both destinations',async()=>{api.request.mockResolvedValue(snapshot());const w=render();await w.vm.open();await flushPromises();const inputs=[...document.querySelectorAll('input')];expect(inputs.find(input=>input.value==='HT-2026-001').readOnly).toBe(true);expect(inputs.some(input=>[fields.address,fields.deliveryLocation].includes(input.value))).toBe(false);expect(document.querySelector('.acceptance-report__fixed').textContent).toContain('招商车研')})
it('blocks unsaved documents and batch switches',async()=>{const blocked=render(true);await blocked.vm.open();expect(api.request).not.toHaveBeenCalled();api.request.mockResolvedValue(snapshot());const w=render();await w.vm.open();await flushPromises();await w.setProps({sheet:{batch:{id:8}}});button('生成并保存').click();await flushPromises();expect(api.request).toHaveBeenCalledTimes(1)})