cmvr-wms/ruoyi-ui-vue3/tests/runtime/purchase-history-correction.spec.js
lixiaolong cd86623061 feat(app): 添加服务器连接管理和到货操作功能
- 集成 ServerConnection 组件用于开发环境服务器切换
- 实现多服务器令牌隔离存储机制
- 添加 ArrivalOperation 屏幕处理到货和验收流程
- 支持待登记到货和待验收状态切换
- 优化库存操作界面的字段显示逻辑
- 增强 Excel 文件分片上传支持产品文件识别
- 添加 AI 助手会话滚动跟踪功能
- 实现开发服务器地址持久化存储
- 优化登录界面集成服务器连接组件
- 添加领用出库功能支持项目物资使用
- 改进盘点确认生效的操作流程
- 增强采购到货登记和验收的权限控制
- 优化移动端文件上传的断点续传机制
- 添加服务器切换时的数据清理保护机制
- 实现紧凑金额显示模式减少界面冗余
- 增强库存操作的数量验证和错误提示
- 优化 AI 助手的会话状态同步机制
2026-10-20 10:04:17 +08:00

27 lines
2.7 KiB
JavaScript

import {expect,it,vi} from 'vitest'
import {mount,flushPromises} from '@vue/test-utils'
import ElementPlus from 'element-plus'
import History from '../../src/components/PurchaseSheet/HistoryCorrection.vue'
import Preview from '../../src/components/PurchaseSheet/HistoryPreview.vue'
const api=vi.hoisted(()=>({preview:vi.fn(),correct:vi.fn()}))
vi.mock('@/api/warehouse/purchase',()=>({previewPurchaseHistoryCorrection:api.preview,correctPurchaseHistory:api.correct}))
vi.mock('@/api/project/loan',()=>({loanOptions:vi.fn()}))
it('history edits only explicitly selected fields and retries the exact reviewed request after a lost response',async()=>{
api.preview.mockResolvedValue({data:{ready:true,rows:[{id:7,name:'原物品',version:'trusted',changes:[{field:'remark',label:'备注',before:'旧备注',after:'新备注'}]}]}})
api.correct.mockRejectedValueOnce(new Error('lost response')).mockResolvedValueOnce({data:{message:'已更正'}})
const wrapper=mount(History,{props:{projects:[],categories:[],units:['件'],plans:[]},global:{plugins:[ElementPlus],stubs:{ItemCategorySelect:true},mocks:{$modal:{msgWarning:vi.fn(),msgSuccess:vi.fn()}}}})
const vm=wrapper.vm;vm.open([{id:7,materialName:'原物品',remark:'旧备注',quantity:2,actualUnitPrice:3,finalUnitPrice:5}]);vm.reason='核对附件';vm.rows[0].values.remark='新备注'
expect(api.correct).not.toHaveBeenCalled();await vm.loadPreview();await flushPromises()
expect(api.preview.mock.calls[0][0].rows[0].changes).toEqual({remark:'新备注'})
expect(wrapper.findComponent(Preview).props('rows')[0].changes[0].after).toBe('新备注')
await vm.submit();expect(vm.attempted).toBe(true);expect(vm.visible).toBe(true)
const submitted=api.correct.mock.calls[0][0];expect(submitted.rows[0].version).toBe('trusted')
vm.rows[0].values.remark='不会混入重试';await vm.submit()
expect(api.correct.mock.calls[1][0]).toEqual(submitted);expect(submitted.rows[0].changes).toEqual({remark:'新备注'});expect(vm.visible).toBe(false)
wrapper.unmount()
})
it('history diff shows explicit zero, old/new values and the archive impact without using raw html',async()=>{
const wrapper=mount(Preview,{props:{rows:[{id:7,name:'水泵',oldActualAmount:10,newActualAmount:0,oldAmount:12,newAmount:18,receiptCount:1,costSourceCount:1,categoryUpdatesArchive:true,oldStatus:4,newStatus:3,changes:[{field:'actualUnitPrice',label:'实际单价',before:5,after:0}]}]},global:{plugins:[ElementPlus]}})
await flushPromises();expect(wrapper.text()).toContain('10 → 0');expect(wrapper.text()).toContain('物品类别将同步更正物品档案');expect(wrapper.text()).toContain('已到齐 → 部分到货');expect(wrapper.find('.history-new').text()).toBe('0');wrapper.unmount()
})