返回 DeepSeek-Reasonix
provider-model-discovery-selection.test.tsx
根目录 / desktop / frontend / src / __tests__ / provider-model-discovery-selection.test.tsx
1 import {JSDOM} from 'jsdom';
2 import React,{act} from 'react';
3 import assert from 'node:assert/strict';
4 const dom=new JSDOM('<div id="root"></div>',{url:'http://localhost',pretendToBeVisual:true});
5 Object.assign(globalThis,{window:dom.window,document:dom.window.document,localStorage:dom.window.localStorage,requestAnimationFrame:dom.window.requestAnimationFrame.bind(dom.window),cancelAnimationFrame:dom.window.cancelAnimationFrame.bind(dom.window),IS_REACT_ACT_ENVIRONMENT:true});
6 const {createRoot}=await import('react-dom/client');
7 const {ProviderEditor}=await import('../components/SettingsPanel');
8 const {LocaleProvider}=await import('../lib/i18n');
9 const {installDesktopHostStub}=await import('./desktopHostStub');
10 installDesktopHostStub({FetchProviderModelCatalog:async()=>[{model:'new-model',inputModalities:['text']}]});
11 const p={name:'custom',kind:'openai',baseUrl:'https://example.com/v1',models:['manual-model'],default:'manual-model',apiKeyEnv:'TEST_KEY',keySet:true,added:true,builtIn:false,visionModels:[],supportedEfforts:[],modelsUrl:'',balanceUrl:'',contextWindow:128000};
12 const root=createRoot(document.getElementById('root')!);
13 await act(async()=>root.render(<LocaleProvider><ProviderEditor initial={p as any} kinds={['openai']} busy={false} onCancel={()=>{}} onSave={()=>{}} onSaveKey={async()=>{}}/></LocaleProvider>));
14 assert.equal(document.querySelectorAll('.provider-model-draft__context-field[open]').length,0);
15 assert.ok(document.querySelector('input[type="password"]'), 'key entry is always visible and masked');
16 assert.equal(document.querySelectorAll('.provider-model-toolbar .provider-model-draft__tools > button').length,2);
17
18 await act(async()=>{(document.querySelector('.provider-model-toolbar button') as HTMLButtonElement).click();await new Promise(r=>setTimeout(r,20));});
19 const rows=[...document.querySelectorAll('.provider-model-draft__option')];
20 const manual=rows.find(row=>row.textContent?.includes('manual-model'))!;
21 const found=rows.find(row=>row.textContent?.includes('new-model'))!;
22 assert.ok(manual);assert.ok(found);
23 assert.equal(manual.querySelector('input')!.checked,true);
24 assert.equal(found.querySelector('input')!.checked,false);
25 await act(async()=>root.unmount());
26 dom.window.close();
27 console.log('PASS: discovery retains manual models and selection; new models are not auto-enabled; advanced fields start collapsed');
28
28 lines Plain Text