import {expect,it,vi} from 'vitest' import {mount,flushPromises} from '@vue/test-utils' import ElementPlus from 'element-plus' import RemotePicker from '../../src/components/BomEditor/RemotePicker.vue' it('an empty remote search explains the result while keeping the existing selection',async()=>{ const fetchPage=vi.fn(async()=>({rows:[],total:0})) const wrapper=mount(RemotePicker,{attachTo:document.body,props:{modelValue:7,item:{id:7,name:'原产品'},fetchPage,optionKey:p=>p.id,label:p=>p.name,createLabel:'产品',createHref:'/businessBasics/products?create=1'},global:{plugins:[ElementPlus]}}) try{ await wrapper.find('.el-select__wrapper').trigger('click');await flushPromises() await wrapper.vm.search('不存在的产品');await flushPromises() expect(wrapper.vm.options).toEqual([{id:7,name:'原产品'}]) expect(document.querySelector('.el-select-dropdown').textContent).toContain('没有匹配结果') expect(wrapper.props('modelValue')).toBe(7) expect(wrapper.emitted('update:modelValue')).toBeUndefined() }finally{wrapper.unmount()} })