Add literal contains filters across source queries and analysis context
This commit is contained in:
@@ -1042,3 +1042,12 @@ test('adaptive trends cover every series, preserve missing values, and keep non-
|
||||
assert.equal(formatVisualValue(.9639601707533932, 'ratio'), '96.40%');
|
||||
assert.equal(formatVisualValue(3, 'kg'), '3.00 kg');
|
||||
});
|
||||
|
||||
test('contains keywords survive analysis scope and display as substring filters',()=>{
|
||||
const rule={field:'src_any',stages:['bright'],operator:'contains',values:['日立','%_']};
|
||||
const parsed=parseAnalysisVisuals([visual({scope:{columnFilters:[rule],columnLabels:{src_any:'客户'}}})]);
|
||||
assert.equal(parsed.visuals.length,1);
|
||||
assert.deepEqual(parsed.visuals[0].scope.columnFilters,[rule]);
|
||||
assert.match(columnFilterSummary([rule],{src_any:'客户'})[0],/包含.*日立/);
|
||||
assert.equal(parseAnalysisVisuals([visual({scope:{columnFilters:[{...rule,values:[]}]}})]).visuals.length,0);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
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:[]}]);
|
||||
});
|
||||
@@ -30,3 +30,9 @@ test('stage query includes unclassified source rows even when an old link exclud
|
||||
assert.equal(base.includeUnassigned,false);
|
||||
}
|
||||
});
|
||||
|
||||
test('contains keywords are retained while an unfilled contains rule is inactive',()=>{
|
||||
const rule={field:'customer',stages:['bright'],operator:'contains',values:['日立','%_']};
|
||||
assert.deepEqual(activeStageFilters([rule],'bright'),[rule]);
|
||||
assert.deepEqual(activeStageFilters([{...rule,values:[]}],'bright'),[]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user