cmvr-wms/ruoyi-ui-vue3/tests/runtime/stock-fill-available.spec.js
lixiaolong ebac97185e feat(assistant): 新增用户核对功能并优化对话流程
- 新增 user.check 功能用于核对人员是否已有系统账号
- 在 assistant-table-layout.js 中为用户表格添加 checkedIdentity 和 matchResult 字段
- 优化 AssistantConversationService 中的任务记忆和澄清流程
- 支持对草稿特定行进行修改,无需重新填写整张表
- 限制 user.check 操作最大查询数量为 100 条记录
- 实现中断任务恢复机制,保持原始请求上下文
- 添加针对多行数据选择性修改的目标行标识支持
2026-10-23 17:00:47 +08:00

54 lines
4.6 KiB
JavaScript

import {afterEach,expect,it,vi} from 'vitest'
import {shallowMount} from '@vue/test-utils'
import Operations from '../../src/components/Production/StockOperations.vue'
const api=vi.hoisted(()=>({outStock:vi.fn().mockResolvedValue({}),moveStock:vi.fn(),taskAction:vi.fn()}))
vi.mock('@/api/warehouse/stock',()=>({outStock:api.outStock,moveStock:api.moveStock}))
vi.mock('@/api/production/tasks',()=>({taskAction:api.taskAction}))
vi.mock('@/api/warehouse/area',()=>({optionselectArea:vi.fn().mockResolvedValue({data:[]})}))
vi.mock('@/utils/use-compact-layout',()=>({useCompactLayout:()=>({compact:false})}))
const mounted=[]
afterEach(()=>{for(const wrapper of mounted.splice(0))wrapper.unmount();vi.clearAllMocks()})
function render(data={}){
const wrapper=shallowMount(Operations,{data:()=>({visible:true,date:'2026-10-23',rows:[8,6,14,16,24].map((stockNum,i)=>({id:i+1,projectId:71,productId:i+10,areaId:1,stockNum,quantity:1,done:false,failed:false,key:`test-${i}`})),...data}),global:{stubs:{ElDialog:{template:'<div><slot/><slot name="footer"/></div>'},ElButton:{props:['disabled'],template:'<button :disabled="disabled"><slot/></button>'},ElTable:{template:'<div/>'},ElTableColumn:true,DialogWorkspace:{template:'<div><slot name="header"/><slot :tableHeight="180"/></div>'}}}})
mounted.push(wrapper);return wrapper
}
const fillButton=w=>w.findAll('button').find(button=>button.text()==='全部填入可用数量')
it('fills all selected quantities without submitting and still permits individual edits',async()=>{
const w=render();expect(w.vm.rows.map(r=>r.quantity)).toEqual([1,1,1,1,1])
await fillButton(w).trigger('click');expect(w.vm.rows.map(r=>r.quantity)).toEqual([8,6,14,16,24])
expect(api.outStock).not.toHaveBeenCalled();expect(api.moveStock).not.toHaveBeenCalled();expect(api.taskAction).not.toHaveBeenCalled()
w.vm.rows[0].quantity=2;expect(w.vm.rows[0].quantity).toBe(2)
expect(w.findAll('button').some(button=>button.text()==='确认出库')).toBe(true)
})
it('only the explicit confirmation submits the filled quantities',async()=>{
const w=render();await fillButton(w).trigger('click');await w.vm.submit()
expect(api.outStock.mock.calls.map(([data])=>data.outNum)).toEqual([8,6,14,16,24]);expect(w.vm.rows.every(r=>r.done)).toBe(true)
expect(api.outStock.mock.calls[0][0]).toMatchObject({id:1,usageProjectId:71,outType:4,outTime:'2026-10-23 00:00:00'})
})
it('supports decimal and string quantities without changing successful or invalid rows',async()=>{
const w=render({rows:[{stockNum:'0.1250',quantity:0},{stockNum:2.3456,quantity:1},{stockNum:9,quantity:1,done:true},...['invalid',Infinity,0,-1,null].map(stockNum=>({stockNum,quantity:0}))]})
await fillButton(w).trigger('click');expect(w.vm.rows.map(r=>r.quantity)).toEqual([0.125,2.3456,1,0,0,0,0,0])
})
it('never fills during submission or after an attempt using the old stock snapshot',async()=>{
const w=render({saving:true});expect(fillButton(w).element.disabled).toBe(true);w.vm.fillAvailableQuantities();expect(w.vm.rows[0].quantity).toBe(1)
await w.setData({saving:false,runRows:[{failed:true}]});expect(fillButton(w)).toBeUndefined();w.vm.fillAvailableQuantities();expect(w.vm.rows[0].quantity).toBe(1)
})
it('does not offer or execute whole-stock filling for production allocation or other operation kinds',async()=>{
const w=render()
for(const kind of ['ISSUE','MOVE','DELIVERY','SCRAP_STOCK','SCRAP_FINISHED']){await w.setData({kind});expect(fillButton(w)).toBeUndefined();w.vm.fillAvailableQuantities();expect(w.vm.rows[0].quantity).toBe(1)}
await w.setData({kind:'USE',taskContext:{id:9}});expect(fillButton(w)).toBeUndefined();w.vm.fillAvailableQuantities();expect(w.vm.rows[0].quantity).toBe(1)
})
it('disables the action if no pending row has a positive available quantity',()=>{
const w=render({rows:[{stockNum:9,quantity:1,done:true},{stockNum:0,quantity:0}]});expect(fillButton(w).element.disabled).toBe(true)
})
it('exposes the same non-submitting shortcut on the compact layout',async()=>{
const w=render();await w.setData({compact:true});await fillButton(w).trigger('click');expect(w.vm.rows.map(r=>r.quantity)).toEqual([8,6,14,16,24]);expect(api.outStock).not.toHaveBeenCalled()
})
it('keeps the form aligned above the quantity toolbar and reduces blank space for small batches',()=>{
const w=render();expect(w.find('.stock-operation-form').attributes('label-position')).toBe('top')
expect(w.find('.stock-quantity-toolbar .stock-selection-summary').text()).toBe('待处理 5 项库存')
expect(w.vm.workspaceStyle.height).toContain('504px');expect(w.find('.stock-batch-submit').text()).toBe('确认出库')
expect(api.outStock).not.toHaveBeenCalled()
})