cmvr-wms/ruoyi-ui-vue3/tests/runtime/purchase-edit-operations.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.2 KiB
JavaScript

import {expect,it,vi} from 'vitest'
import {readFileSync} from 'node:fs'
import {parse} from '@vue/compiler-sfc'
import {baseParse} from '@vue/compiler-dom'
import {defineComponent} from 'vue'
import {mount} from '@vue/test-utils'
it('purchase keeps template export on the main list only and removes quote-entry shortcuts',()=>{
const template=parse(readFileSync('src/components/PurchaseSheet/index.vue','utf8')).descriptor.template.content
const labels=[],exports=[]
function collect(node,ancestors=[]){if(node.tag==='el-button'){const label=(node.children||[]).filter(child=>child.type===2).map(child=>child.content.trim()).join('');labels.push(label);if(label==='导出模板')exports.push({node,ancestors})}for(const child of node.children||[])collect(child,[...ancestors,node])}
collect(baseParse(template))
expect(exports).toHaveLength(1);expect(exports[0].ancestors.some(node=>node.tag==='template'&&node.props.some(p=>p.name==='if'&&p.exp?.content==='!sheet'))).toBe(true)
expect(exports[0].node.props.some(p=>p.name==='on'&&p.arg?.content==='click'&&p.exp?.content==='exportTemplate')).toBe(true)
expect(labels).not.toContain('录入报价');expect(labels).toContain('导入采购')
expect(template).toContain('exportInquiry');expect(template).toContain('startEditing')
})
it.each([true,false])('main-list template export respects existing permissions (%s)',async allowed=>{
const template=parse(readFileSync('src/components/PurchaseSheet/index.vue','utf8')).descriptor.template.content
let toolbar;function find(node){if(node.tag==='div'&&node.props.some(p=>p.name==='class'&&p.value?.content==='sheet-list-tabs'))toolbar=node;for(const child of node.children||[])find(child)}find(baseParse(template))
const exportTemplate=vi.fn(),host=defineComponent({template:template.slice(toolbar.loc.start.offset,toolbar.loc.end.offset),data:()=>({viewMode:'batches',drafts:[]}),methods:{exportTemplate,changeView:vi.fn(),restoreDraft:vi.fn()}})
const wrapper=mount(host,{global:{mocks:{$can:()=>allowed},stubs:{ElRadioGroup:{template:'<div><slot/></div>'},ElRadioButton:true,ElDropdown:true,ElDropdownMenu:true,ElDropdownItem:true,BusinessIcon:true,ElButton:{emits:['click'],template:'<button @click="$emit(\'click\')"><slot/></button>'}}}})
const button=wrapper.findAll('button').find(b=>b.text()==='导出模板');expect(!!button).toBe(allowed)
if(button){await button.trigger('click');expect(exportTemplate).toHaveBeenCalledOnce()}else expect(exportTemplate).not.toHaveBeenCalled()
wrapper.unmount()
})
it('purchase editing removes the entire fixed operations column and restores it after editing',async()=>{
const source=readFileSync('src/components/PurchaseSheet/index.vue','utf8')
const template=parse(source).descriptor.template.content
let column
function find(node){
if(node.tag==='el-table-column'&&node.props.some(p=>p.name==='key'&&p.value?.content==='operations'))column=node
for(const child of node.children||[])find(child)
}
find(baseParse(template));expect(column).toBeTruthy()
const actual=template.slice(column.loc.start.offset,column.loc.end.offset)
const records=vi.fn()
const host=defineComponent({template:`<div>${actual}</div>`,data:()=>({isEditing:false,saving:false,canEdit:true}),methods:{canArrive:()=>false,records}})
const tableColumn=defineComponent({props:['label','width'],template:'<section class="operations"><strong>{{label}}</strong><slot :row="row"/></section>',data:()=>({row:{id:1,purchaseStatus:0,pendingArrivalQuantity:0,acceptedQuantity:0}})})
const button=defineComponent({emits:['click'],template:'<button @click="$emit(\'click\')"><slot/></button>'})
const wrapper=mount(host,{global:{stubs:{ElTableColumn:tableColumn,ElButton:button},mocks:{$can:()=>false}}})
expect(wrapper.get('.operations').text()).toContain('操作')
await wrapper.get('button').trigger('click');expect(records).toHaveBeenCalledOnce()
await wrapper.setData({isEditing:true})
expect(wrapper.find('.operations').exists()).toBe(false)
expect(wrapper.find('button').exists()).toBe(false)
await wrapper.setData({isEditing:false})
expect(wrapper.get('.operations').text()).toContain('到货记录')
expect(wrapper.findComponent(tableColumn).props('width')).toBe('270')
wrapper.unmount()
})