优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
42 lines
6.9 KiB
JavaScript
42 lines
6.9 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()
|
|
})
|
|
|
|
it('acceptance invoices have a separate upload area and cannot be selected as the signed acceptance PDF',async()=>{
|
|
const data=groups();data.push({kind:'INVOICE',label:'验收发票',number:'',version:0,files:[{id:'invoice',name:'发票.pdf',contentType:'application/pdf',size:1000}]});api.list.mockResolvedValue({data});wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'批次','ACCEPTANCE');await flushPromises();
|
|
expect(button('上传PDF')).toBeTruthy();expect(button('上传验收发票')).toBeTruthy();expect(document.querySelector('[role=tab][aria-selected=true]').textContent.replace(/\s/g,'')).toBe('验收资料1');expect(document.querySelector('[aria-label="验收发票"]').textContent).toContain('发票.pdf');expect(document.querySelector('.acceptance-confirmation').textContent).not.toContain('发票.pdf');expect(button('确认验收').disabled).toBe(true);
|
|
});
|
|
it('payment controls are blocked without an invoice and enabled after an invoice is present',async()=>{
|
|
const data=groups();api.list.mockResolvedValue({data});wrapper=mount(Documents,{global:{plugins:[ElementPlus]},attachTo:document.body});await wrapper.vm.open('batch',7,'批次','PAYMENT');await flushPromises();expect(document.body.textContent).toContain('付款前需上传验收发票');expect(button('上传PDF').disabled).toBe(true);expect(document.querySelector('.purchase-documents__number input').disabled).toBe(true);
|
|
data.push({kind:'INVOICE',number:'',version:0,files:[{id:'invoice',name:'发票.png',contentType:'image/png',size:1000}]});api.list.mockResolvedValue({data});await wrapper.vm.open('batch',7,'批次','PAYMENT');await flushPromises();expect(button('上传PDF').disabled).toBe(false);expect(document.querySelector('.purchase-documents__number input').disabled).toBe(false);
|
|
});
|