- 新增物品分类申请及审核记录相关数据库表结构 - 添加物品分类管理菜单及对应的角色权限配置 - 实现物品分类申请组件支持新增申请与历史记录查询 - 开发批量AI分类组件以支持采购明细的智能分类推荐 - 新增批量确认小类组件以便管理员快速处理待确认分类 - 构建物品分类管理页面提供分类审核调整及关联记录查看
33 lines
5.1 KiB
JavaScript
33 lines
5.1 KiB
JavaScript
import {afterEach,beforeEach,expect,it,vi} from 'vitest'
|
|
import {mount,flushPromises} from '@vue/test-utils'
|
|
import ElementPlus,{ElMessageBox} from 'element-plus'
|
|
import Documents from '../../src/components/PurchaseDocuments/index.vue'
|
|
const api=vi.hoisted(()=>({list:vi.fn(),request:vi.fn(),status:vi.fn(),confirm:vi.fn()}))
|
|
vi.mock('@/utils/request',()=>({default:api.request}))
|
|
vi.mock('@/store/modules/user',()=>({default:()=>({permissions:['warehouse:purchase:list','warehouse:purchase:edit']})}))
|
|
vi.mock('@/api/warehouse/purchase-documents',()=>({getPurchaseAcceptanceConfirmation:api.status,confirmPurchaseAcceptance:api.confirm,listPurchaseDocuments:api.list,savePurchaseDocumentNumber:vi.fn(),uploadPurchaseDocument:vi.fn(),removePurchaseDocument:vi.fn(),readPurchaseDocument:vi.fn()}))
|
|
const groups=()=>['REQUEST','CONTRACT','ACCEPTANCE','PAYMENT','OTHER'].map(kind=>({kind,label:{REQUEST:'采购申请',CONTRACT:'合同',ACCEPTANCE:'验收资料',PAYMENT:'付款资料',OTHER:'其他附件'}[kind],number:kind==='REQUEST'?'SX-1':kind==='CONTRACT'?'HT-1':'',version:1,files:[]}))
|
|
beforeEach(()=>api.status.mockResolvedValue({data:{ready:true,current:false,latest:{},version:'h1',canConfirm:true}}))
|
|
let wrapper;afterEach(()=>{wrapper?.unmount();document.body.innerHTML='';vi.resetAllMocks()})
|
|
const button=text=>[...document.querySelectorAll('button')].find(b=>b.textContent.trim()===text)
|
|
it('generates inside acceptance documents and refreshes the saved attachment list',async()=>{
|
|
const next=groups();next.find(g=>g.kind==='ACCEPTANCE').files=[{id:'saved-file',name:'验收资料_待签章.pdf',size:1000,contentType:'application/pdf'}]
|
|
api.list.mockResolvedValueOnce({data:groups()}).mockResolvedValueOnce({data:next});api.request.mockResolvedValueOnce({data:{ready:true,count:1,version:'v1',issues:[],documents:[{label:'采购申请',numberLabel:'随行编号',numbered:true,files:1},{label:'合同',numberLabel:'合同编号',numbered:true,files:1}],fields:{purchaser:'甲方',supplier:'乙方',contractNo:'HT-1',address:'固定地址',deliveryLocation:'招商车研',checks:Array(7).fill('')},checkLabels:Array(7).fill('检查项')}}).mockResolvedValueOnce({data:{id:'saved-file'}})
|
|
wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'批次','ACCEPTANCE');await flushPromises();expect(document.querySelectorAll('[role="tab"]')).toHaveLength(5);expect(document.body.textContent).not.toContain('报价编号');button('生成验收资料').click();await flushPromises();button('生成并保存').click();await flushPromises();expect(api.list).toHaveBeenCalledTimes(2);expect(document.body.textContent).toContain('验收资料_待签章.pdf');expect(button('下载')).toBeTruthy();expect(button('上传PDF')).toBeTruthy()
|
|
})
|
|
it('retains the request number and prevents generation with an unsaved number',async()=>{api.list.mockResolvedValue({data:groups()});wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'批次','REQUEST');await flushPromises();expect(document.body.textContent).toContain('随行编号');const input=document.querySelector('.purchase-documents__number input');input.value='UNSAVED';input.dispatchEvent(new Event('input',{bubbles:true}));await flushPromises();[...document.querySelectorAll('[role="tab"]')].find(b=>b.textContent.includes('验收资料')).click();await flushPromises();expect(button('生成验收资料').disabled).toBe(true)})
|
|
|
|
it('requires a separately uploaded signed PDF and records explicit confirmation without overwriting the generated draft',async()=>{
|
|
const data=groups();data.find(g=>g.kind==='ACCEPTANCE').files=[{id:'draft',name:'材料_待签章.pdf',serverGenerated:true,contentType:'application/pdf',size:1000},{id:'signed',name:'材料_待签章.pdf',serverGenerated:false,contentType:'application/pdf',size:2000}]
|
|
api.list.mockResolvedValue({data});api.confirm.mockResolvedValue({data:{current:true}})
|
|
const dialog=vi.spyOn(ElMessageBox,'confirm').mockResolvedValue('confirm')
|
|
wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'批次','ACCEPTANCE');await flushPromises()
|
|
expect(button('确认验收').disabled).toBe(false);button('确认验收').click();await flushPromises()
|
|
expect(api.confirm).toHaveBeenCalledWith(7,expect.objectContaining({attachmentId:'signed',version:'h1',acknowledged:true,requestKey:expect.stringMatching(/^accept-/)}),expect.anything())
|
|
expect(dialog).toHaveBeenCalled();expect(api.list).toHaveBeenCalledTimes(2);expect(document.body.textContent).toContain('材料_待签章.pdf');dialog.mockRestore()
|
|
})
|
|
it('blocks write controls for a foreign batch while keeping document viewing available',async()=>{
|
|
api.list.mockResolvedValue({data:groups().map(g=>({...g,editable:false}))});wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'其他人的批次','ACCEPTANCE');await flushPromises()
|
|
expect(button('上传PDF')).toBeUndefined();expect(button('生成验收资料')).toBeUndefined();expect(button('确认验收')).toBeUndefined()
|
|
})
|