cmvr-wms/ruoyi-ui-vue3/tests/runtime/purchase-catalog-search.spec.js
lixiaolong 95effeeff2 feat(app): 优化移动端应用配置和功能实现
- 添加生产环境服务器地址配置支持内外网切换
- 实现采购列表只看我创建的功能开关
- 更新构建脚本中的默认生产环境API地址
- 优化采购单表格单元格编辑体验改用自动补全组件
- 调整应用更新检查逻辑增强生产环境兼容性
- 修复开发服务器切换时的一些验证问题
- 增强应用启动时的服务地址配置灵活性
2026-10-29 17:27:46 +08:00

46 lines
2.8 KiB
JavaScript

import { afterEach, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import Cell from '@/components/PurchaseSheet/Cell.vue'
import Sheet from '@/components/PurchaseSheet/index.vue'
import { candidates } from '@/utils/purchase-sheet'
vi.mock('@/utils/request',()=>({default:vi.fn()}))
vi.mock('@/store/modules/user',()=>({default:()=>({permissions:['*:*:*']})}))
vi.mock('@/store/modules/app',()=>({default:()=>({size:'default'})}))
const wrappers=[]
afterEach(()=>wrappers.splice(0).forEach(w=>w.unmount()))
function setup(field, row, items) {
const owner={saving:false,nameMenuRow:null,nameItems:items, items, fieldLocked:()=>false,cellError:()=>'',editableCell:()=>true,isEditing:true,displayCell:(r,f)=>r[f],
rememberCell:()=>{},paste:()=>{},navigate:()=>{},searchNames:vi.fn(async()=>{}),loadName:vi.fn(async()=>{}),
nameChoices:Sheet.methods.nameChoices,specs(r){return candidates(this.items,r,'spec')},brands:()=>[],
specChanged:vi.fn(),nameChanged:vi.fn(),brandChanged:vi.fn(),itemLabel:i=>[i.productName,i.spec].filter(Boolean).join(' / ')}
const w=mount(Cell,{props:{row,column:{field,label:field},index:0,owner,active:true},global:{plugins:[ElementPlus]}})
wrappers.push(w)
return {w,owner,autocomplete:w.findComponent({name:'ElAutocomplete'})}
}
it('产品远程搜索结果即使没有旧下拉状态也可选择档案',async()=>{
const items=[{id:1,productName:'电机',spec:'型号A'},{id:2,productName:'电机支架',spec:'型号B'}]
const {autocomplete,owner}=setup('materialName',{_key:'r',materialName:''},items)
let suggestions
await autocomplete.props('fetchSuggestions')('电机',value=>suggestions=value)
expect(suggestions.map(x=>x.id)).toEqual([1,2])
await autocomplete.vm.$emit('select',suggestions[1])
expect(owner.nameChanged).toHaveBeenCalledWith(expect.anything(),'@item:2')
})
it('规格保留原文本、展开可选其他规格并支持搜索和选择档案',async()=>{
const items=[{id:1,productName:'电机',brand:'甲',spec:'型号A',unit:'个'},{id:2,productName:'电机',brand:'甲',spec:'型号B',unit:'个'}]
const {autocomplete,owner}=setup('materialParams',{_key:'r',materialName:'电机',materialBrand:'甲',materialParams:'型号A'},items)
expect(autocomplete.props('modelValue')).toBe('型号A')
let suggestions
await autocomplete.props('fetchSuggestions')('型号A',value=>suggestions=value)
expect(owner.loadName).toHaveBeenCalledWith('电机')
expect(suggestions.map(x=>x.id)).toEqual([1,2])
await autocomplete.props('fetchSuggestions')('型号B',value=>suggestions=value)
expect(suggestions.map(x=>x.id)).toEqual([2])
await autocomplete.vm.$emit('select',suggestions[0])
expect(owner.specChanged).toHaveBeenCalledWith(expect.anything(),'@item:2')
})