import {expect,it,vi} from 'vitest' import {shallowMount} from '@vue/test-utils' import Operations from '../../src/components/Production/StockOperations.vue' import Sheet from '../../src/components/PurchaseSheet/index.vue' import Correction from '../../src/components/PurchaseSheet/PriceCorrection.vue' vi.mock('@/utils/request',()=>({default:vi.fn()})) vi.mock('@/store/modules/user',()=>({default:()=>({permissions:['*:*:*']})})) vi.mock('@/store/modules/app',()=>({default:()=>({size:'default'})})) vi.mock('@/utils/use-compact-layout',()=>({useCompactLayout:()=>({compact:false})})) it('the completed dialog renders a finish button, removes submit and reports success',()=>{ const wrapper=shallowMount(Operations,{data:()=>({visible:true,rows:[{done:true,quantity:1,stockNum:18,productName:'隔离测试物品'}],runRows:[{done:true,quantity:1}]}),global:{stubs:{ElTable:{template:'
'},ElTableColumn:true,ElDialog:{template:'
'},ElButton:{template:''},DialogWorkspace:{template:'
'}}}}) expect(wrapper.text()).toContain('成功 1 项');expect(wrapper.text()).toContain('完成');expect(wrapper.text()).not.toContain('本次 0 项');expect(wrapper.findAll('button').some(button=>button.text()==='确认')).toBe(false) wrapper.unmount() }) it('successful inventory operations keep a completed summary instead of reporting zero selected items',()=>{ const row={done:true,quantity:1,failed:false},vm={rows:[row],displayRows:[row],runRows:[row]} expect(Operations.computed.resultSummary.call(vm)).toBe('成功 1 项') expect(Operations.computed.allCompleted.call(vm)).toBe(true) vm.rows.push({done:false,failed:true,quantity:2}) expect(Operations.computed.resultSummary.call(vm)).toBe('成功 1 项 · 失败 1 项') expect(Operations.computed.allCompleted.call(vm)).toBe(false) vm.rows[1].failed=false expect(Operations.computed.resultSummary.call(vm)).toBe('成功 1 项 · 待处理 1 项') }) it('confirmed but not arrived purchases allow both prices; arrival locks quote while reference remains editable',()=>{ const vm={canViewQuotes:true,isEditing:true,saving:false,compactAmounts:false,readonly:Sheet.methods.readonly,fieldLocked:Sheet.methods.fieldLocked,canEditCategory:()=>true} const row={id:1,purchaseStatus:1,priceLocked:true,acceptedQuantity:0,pendingArrivalQuantity:0,receivedQuantity:0} expect(Sheet.methods.editableCell.call(vm,row,'finalUnitPrice')).toBe(true) expect(Sheet.methods.editableCell.call(vm,row,'actualUnitPrice')).toBe(true) row.pendingArrivalQuantity=1;expect(Sheet.methods.editableCell.call(vm,row,'finalUnitPrice')).toBe(false) expect(Sheet.methods.editableCell.call(vm,row,'actualUnitPrice')).toBe(true) row.historical=true;expect(Sheet.methods.editableCell.call(vm,row,'finalUnitPrice')).toBe(false) }) it('changing a correction input invalidates the preview and historical acknowledgement',()=>{ const vm={preview:{version:'old'},acknowledgeArchiveOnly:true};Correction.methods.invalidate.call(vm) expect(vm.preview).toBeNull();expect(vm.acknowledgeArchiveOnly).toBe(false) })