cmvr-wms/ruoyi-ui-vue3/tests/runtime/purchase-live-editor.spec.js
lixiaolong b39fc01865 feat(purchase): 实现采购PDF解析与验收确认功能
- 新增采购验收确认表及附件系统生成标识字段
- 实现采购PDF多页明细解析合并与数据校验逻辑
- 支持报价与实际金额一致的自动赋值指令处理
- 添加移动端到货照片补充上传及重试机制测试
- 补充后端PDF解析路由分发及事务处理单元测试
2026-11-09 09:49:38 +08:00

48 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {it,expect,vi} from 'vitest'
import {reactive} from 'vue'
import {createSheetEditor,readSheetDraft} from '../../src/utils/purchase-sheet-editor'
function fixture(){
const vm=reactive({live:{enabled:true},sheet:null,baseline:'',editing:true,isEditing:true,history:[],redoHistory:[],changedKeys:new Set(),selected:[],persistDraft:vi.fn(),draftPrefix:()=> 'live-test:',draftId:()=> 'one',refreshDrafts:vi.fn(),$modal:{msgWarning:vi.fn()}})
const editor=createSheetEditor(vm)
vm.sheet={batch:{id:1,batchName:'原名称',progressRemark:'原批次备注'},deletedIds:[],rows:[{id:1,_key:'saved-1',quantity:2,remark:'原备注'}]}
vm.baseline=JSON.stringify(vm.sheet)
return {vm,editor}
}
it('collaborative undo changes only the local field while retaining a different field from a peer',()=>{
const {vm,editor}=fixture();try{
editor.beginCell(vm.sheet.rows[0],'remark');vm.sheet.rows[0].remark='我的';editor.flush()
vm._liveRebasing=true;vm.sheet.rows[0].quantity=9;vm.baseline=JSON.stringify(vm.sheet);vm._liveRebasing=false
editor.undo();expect(vm.sheet.rows[0].remark).toBe('原备注');expect(vm.sheet.rows[0].quantity).toBe(9)
editor.redo();expect(vm.sheet.rows[0].remark).toBe('我的');expect(vm.sheet.rows[0].quantity).toBe(9)
}finally{editor.stop()}
})
it('undo cannot replace a later peer edit to the same field',()=>{
const {vm,editor}=fixture();try{
editor.beginCell(vm.sheet.rows[0],'remark');vm.sheet.rows[0].remark='我的';editor.flush()
vm._liveRebasing=true;vm.sheet.rows[0].remark='他人后改';vm.baseline=JSON.stringify(vm.sheet);vm._liveRebasing=false
editor.undo();expect(vm.sheet.rows[0].remark).toBe('他人后改');expect(vm.$modal.msgWarning).toHaveBeenCalledOnce()
}finally{editor.stop()}
})
it('a header undo retains another user’s changed header fields',()=>{
const {vm,editor}=fixture();try{
editor.beginHeader('batchName');vm.sheet.batch.batchName='我改的名称';editor.flush()
vm._liveRebasing=true;vm.sheet.batch.progressRemark='别人更新的备注';vm.baseline=JSON.stringify(vm.sheet);vm._liveRebasing=false
editor.undo();expect(vm.sheet.batch.batchName).toBe('原名称');expect(vm.sheet.batch.progressRemark).toBe('别人更新的备注')
}finally{editor.stop()}
})
it('undoing a local insertion preserves rows added by another user',()=>{
const {vm,editor}=fixture();try{
editor.remember([]);vm.sheet.rows.push({_key:'mine-new',id:2,quantity:1});editor.flush()
vm._liveRebasing=true;editor.acceptRemoteRows(['saved-3']);vm.sheet.rows.push({_key:'saved-3',id:3,quantity:8});vm.baseline=JSON.stringify(vm.sheet);vm._liveRebasing=false
editor.undo();expect(vm.sheet.rows.map(r=>r.id)).toEqual([1,3]);expect(vm.sheet.deletedIds).toContain(2)
}finally{editor.stop()}
})
it('unfinished identity text and pending save receipts survive a local draft reload',()=>{
const {vm,editor}=fixture();try{
vm.dirty=true;vm.sheet.liveText={'saved-1|materialParams':{key:'saved-1',field:'materialParams',value:'第一段 第二段'}};vm.sheet.livePending={key:'same-retry-key',version:'v1',recover:true}
expect(editor.persist()).toBe(true);const draft=readSheetDraft('live-test:one')
expect(draft.sheet.liveText['saved-1|materialParams'].value).toBe('第一段 第二段');expect(draft.sheet.livePending.key).toBe('same-retry-key');expect(draft.sheet.rows[0].quantity).toBe(2)
}finally{editor.stop();localStorage.clear()}
})