Bound contains keyword input and clear duplicate search drafts

This commit is contained in:
2026-11-13 21:51:31 +08:00
parent 3c022e8614
commit f8432b4e02
2 changed files with 15 additions and 3 deletions
+8 -2
View File
@@ -5,9 +5,11 @@ 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;
let lastSearch;
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==='react')return {useState:initial=>[initial,value=>{lastSearch=value;} ]};
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:{}};
@@ -22,8 +24,12 @@ test('contains is selectable and accepts bounded free keywords without a value-c
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,[]);
const free=all.find(x=>typeof x.type==='function'&&x.type.name==='ContainsValues');
const keywords=free.type(free.props);
assert.equal(keywords.props.mode,'tags');assert.equal(keywords.props.maxCount,50);assert.deepEqual(keywords.props.options,[]);
keywords.props.onSearch('x'.repeat(257));assert.equal(lastSearch.length,256);
keywords.props.onSearch('x'.repeat(255)+'😀');assert.equal(lastSearch,'x'.repeat(255));
keywords.props.onSearch('日立');keywords.props.onBlur();assert.equal(lastSearch,'');
keywords.props.onChange(['日立','%_',' ']);
assert.deepEqual(changed,[{...rule,values:['日立','%_']}]);
operation.props.onChange('in');assert.deepEqual(changed,[{...rule,operator:'in',values:[]}]);