优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
18 lines
2.7 KiB
JavaScript
18 lines
2.7 KiB
JavaScript
import {expect,it,vi,afterEach} from 'vitest'
|
|
import {mount,flushPromises} from '@vue/test-utils'
|
|
import ElementPlus from 'element-plus'
|
|
import Batch from '../../src/components/BatchFileUpload/index.vue'
|
|
import Files from '../../src/components/ProductAttachments/index.vue'
|
|
const api=vi.hoisted(()=>({list:vi.fn(),upload:vi.fn(),cancel:vi.fn(),remove:vi.fn(),read:vi.fn()}))
|
|
vi.mock('@/api/production/product-editions',()=>({productAttachments:api.list,uploadProductAttachment:api.upload,cancelProductAttachmentTransfer:api.cancel,removeProductAttachment:api.remove,readProductAttachment:api.read}))
|
|
let wrapper;afterEach(()=>{wrapper?.unmount();vi.resetAllMocks()})
|
|
async function start(){api.list.mockResolvedValue({data:[]});wrapper=mount(Files,{global:{plugins:[ElementPlus],mocks:{$can:()=>true,$dateTime:()=>''}}});await wrapper.vm.open({id:7,itemName:'测试产品'});await flushPromises();const input=wrapper.findComponent(Batch).find('input[type=file]');Object.defineProperty(input.element,'files',{value:[new File(['resume'],'说明.txt')],configurable:true});await input.trigger('change');await flushPromises()}
|
|
const button=text=>wrapper.findComponent(Batch).findAll('button').find(b=>b.text()===text)
|
|
function pauseable(){api.upload.mockImplementationOnce((_id,_file,_uploadId,signal,progress)=>new Promise((_resolve,reject)=>{progress({phase:'uploading',percent:50,sessionId:'11111111-1111-4111-8111-111111111111'});signal.addEventListener('abort',()=>reject(Error('aborted')),{once:true})}))}
|
|
it('product upload pause and resume preserve the file and original upload id; switching products clears old jobs',async()=>{
|
|
pauseable();await start();expect(api.upload).toHaveBeenCalledTimes(1);const originalId=api.upload.mock.calls[0][2];await button('暂停').trigger('click');await flushPromises();expect(wrapper.findComponent(Batch).text()).toContain('已暂停');api.upload.mockResolvedValue({});await button('继续 / 重试未完成').trigger('click');await flushPromises();expect(api.upload.mock.calls[1][2]).toBe(originalId);expect(wrapper.findComponent(Batch).text()).toContain('已上传 1 / 1');await wrapper.vm.open({id:8,itemName:'另一个产品'});await flushPromises();expect(wrapper.findComponent(Batch).text()).not.toContain('说明.txt')
|
|
})
|
|
it('cancelling a paused product upload cancels its transfer session, never a saved business attachment',async()=>{
|
|
pauseable();api.cancel.mockResolvedValue({});await start();await button('暂停').trigger('click');await flushPromises();await button('取消未完成').trigger('click');await flushPromises();expect(api.cancel).toHaveBeenCalledWith('11111111-1111-4111-8111-111111111111');expect(api.remove).not.toHaveBeenCalled();expect(wrapper.findComponent(Batch).text()).not.toContain('说明.txt')
|
|
})
|