|
|
@@ -10,7 +10,7 @@ const route={params:{agentId:'bot'},query:{} as Record<string,unknown>}
|
|
|
vi.mock('vue-router',()=>({useRoute:()=>route}))
|
|
|
const agent={id:'bot',name:'竹儿',profile:'default',nodeId:'local'} as any
|
|
|
const permission={supported:true,authorized:true,screen:true,accessibility:true,ready:true,fullAuthorized:true}
|
|
|
-let hosts:any[],readFrame:(key:string)=>unknown
|
|
|
+let hosts:any[],readFrame:(key:string)=>unknown,vmProblem:string
|
|
|
const screenshot=(key:string)=>({id:key,data:key,width:100,height:80,generation:1})
|
|
|
const stubs={AppIcon:true,GrokAuthPanel:true,BrowserToolbar:true}
|
|
|
beforeEach(()=>{
|
|
|
@@ -18,6 +18,7 @@ beforeEach(()=>{
|
|
|
route.query={}
|
|
|
hosts=[{id:'local',name:'服务器',online:true,local:permission},{id:'client-mac',name:'Mac Studio',online:true,local:permission}]
|
|
|
readFrame=screenshot
|
|
|
+ vmProblem=''
|
|
|
vi.mocked(apiRequest).mockImplementation(async(path,options:any)=>{
|
|
|
const url=new URL(path,'http://fixture'),key=url.searchParams.get('host')||url.searchParams.get('backend')||'unspecified'
|
|
|
if(url.pathname==='/api/app/agents')return {agents:[agent]} as any
|
|
|
@@ -25,13 +26,30 @@ beforeEach(()=>{
|
|
|
if(url.pathname.endsWith('/desktop-environment'))return {hosts:hosts.map(h=>({...h}))} as any
|
|
|
if(url.pathname.endsWith('/cloud-computer'))return {configured:true,running:true,connected:true} as any
|
|
|
if(url.pathname.endsWith('/cloud-computer/open'))return {} as any
|
|
|
- if(url.pathname.endsWith('/local-vm'))return {enabled:true,image:true,container:'running',ready:true} as any
|
|
|
+ if(url.pathname.endsWith('/local-vm'))return {enabled:true,image:!vmProblem,container:vmProblem?'missing':'running',ready:!vmProblem,problem:vmProblem} as any
|
|
|
if(url.pathname.endsWith('/frame'))return await readFrame(key) as any
|
|
|
return {mode:options?.method==='POST'?'human':'idle',backend:key==='cloud'?'grok':key==='vm'?'docker':'local',generation:1,hostName:key,controlId:'control',token:'fixture-token'} as any
|
|
|
})
|
|
|
})
|
|
|
afterEach(()=>{vi.restoreAllMocks();vi.clearAllMocks()})
|
|
|
|
|
|
+it('scopes an unavailable VM to its own settings while the server preview remains usable',async()=>{
|
|
|
+ vmProblem='本地虚拟机执行节点尚未启用,请在本地虚拟机设置中完成配置'
|
|
|
+ const wrapper=mount(Preview,{props:{agents:[agent],isAdmin:true,active:true},global:{stubs}})
|
|
|
+ try{
|
|
|
+ await flushPromises()
|
|
|
+ expect(wrapper.get('.preview img').attributes('src')).toContain('base64,local')
|
|
|
+ expect(wrapper.find('.panel-body > .problem').exists()).toBe(false)
|
|
|
+ expect(wrapper.get('.computer-options [aria-label="本地虚拟机状态"]').text()).toBe(vmProblem)
|
|
|
+ await wrapper.get('.preview').trigger('click')
|
|
|
+ expect(wrapper.emitted('desktop')?.at(-1)).toEqual([agent,'desktop','local'])
|
|
|
+ await wrapper.get('[aria-label="显示的桌面"]').setValue('vm');await flushPromises()
|
|
|
+ expect(wrapper.get('.preview').text()).toContain(vmProblem)
|
|
|
+ expect(wrapper.find('.preview img').exists()).toBe(false)
|
|
|
+ expect(wrapper.get('.preview').attributes('disabled')).toBeDefined()
|
|
|
+ }finally{wrapper.unmount()}
|
|
|
+})
|
|
|
+
|
|
|
it('refreshes the selected preview immediately and never replaces it with a late frame from another computer',async()=>{
|
|
|
const wrapper=mount(Preview,{props:{agents:[agent],isAdmin:true,active:true},global:{stubs}})
|
|
|
try{
|