import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import ts from 'typescript'; const source=fs.readFileSync(new URL('../src/StageSourceFilters.tsx',import.meta.url),'utf8'); const output=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.CommonJS,jsx:ts.JsxEmit.ReactJSX,target:ts.ScriptTarget.ES2022}}).outputText; const jsx=(type,props)=>({type,props});const exports={}; new Function('require','exports',output)(name=>{ if(name==='react/jsx-runtime')return {jsx,jsxs:jsx}; if(name==='antd')return {Select:'Select',Button:'Button',Alert:'Alert',Spin:'Spin'}; if(name==='@ant-design/icons')return {CloseOutlined:'CloseOutlined'}; if(name==='./readableSelectPopup')return {readableSelectPopup:{}}; return {}; },exports); const nodes=value=>!value||typeof value!=='object'?[]:[value,...[value.props?.children].flat(Infinity).flatMap(nodes)]; const field={key:'customer',label:'客户名称',type:'source_value',stages:['bright'],columns:{bright:'客户名称'}}; test('contains is selectable and accepts bounded free keywords without a value-candidate lookup',()=>{ let changed; const rule={field:'customer',stages:['bright'],operator:'contains',values:['日立']}; const root=exports.StageSourceFilters({stage:'bright',fields:[field],query:{year:2026},value:[rule],onChange:value=>{changed=value;},onUnauthorized:()=>false}); const all=nodes(root);const operation=all.find(x=>x.type==='Select'&&x.props['aria-label']==='客户名称筛选方式'); assert.ok(operation.props.options.some(x=>x.value==='contains'&&x.label==='包含')); const keywords=all.find(x=>x.type==='Select'&&x.props['aria-label']==='客户名称包含文字'); assert.equal(keywords.props.mode,'tags');assert.equal(keywords.props.maxCount,50);assert.equal(keywords.props.maxLength,256);assert.deepEqual(keywords.props.options,[]); keywords.props.onChange(['日立','%_',' ']); assert.deepEqual(changed,[{...rule,values:['日立','%_']}]); operation.props.onChange('in');assert.deepEqual(changed,[{...rule,operator:'in',values:[]}]); });