优化:完善分类规则与Excel配置维护并加速查询翻页
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { editClassification, classificationRuleId } from '../src/classificationMaintenance.ts';
|
||||
const source = {stage:'black',department:'产业部A',product:'产品A',pdtCode:'',salesRegion:'销售区A'};
|
||||
const selection={kind:'group',row:source};
|
||||
const defaults=[{id:'default',target:'group',value:'默认分类'}];
|
||||
test('blank-key source creates a narrowly scoped rule and preserves inherited defaults',()=>{
|
||||
const base={projectGroupLookup:{'001|G':'项目组A'},extra:['keep']};
|
||||
const result=editClassification(base,selection,'业务组A',defaults);
|
||||
assert.deepEqual(result.matchRules[0].conditions,[
|
||||
{field:'@department',operator:'EQUALS',value:'产业部A'},
|
||||
{field:'@product',operator:'EQUALS',value:'产品A'},
|
||||
{field:'PDT代码',operator:'IS_BLANK',value:''},
|
||||
{field:'销售片区',operator:'EQUALS',value:'销售区A'},
|
||||
]);
|
||||
assert.equal(result.matchRules[0].stage,'black');assert.deepEqual(result.matchRules[1],defaults[0]);
|
||||
assert.deepEqual(base,{projectGroupLookup:{'001|G':'项目组A'},extra:['keep']});
|
||||
const changed=editClassification(result,selection,'业务组A',defaults);
|
||||
assert.equal(changed.matchRules.length,2);assert.equal(changed.matchRules[0].value,'业务组A');
|
||||
assert.throws(()=>editClassification(result,selection,'业务组B',defaults),/相同条件/);
|
||||
assert.notEqual(classificationRuleId(source),classificationRuleId({...source,stage:'bright'}));
|
||||
});
|
||||
test('successive group and project edits accumulate without replacing other mappings or explicit empty rules',()=>{
|
||||
let result=editClassification({matchRules:[],categoryLookup:{keep:'category'}},selection,'G',defaults);
|
||||
result=editClassification(result,{kind:'projectGroup',row:{mappingType:'PROJECT_GROUP',customerCode:'001',businessGroup:'G',sourceKey:'001|G'}},'P',defaults);
|
||||
assert.equal(result.projectGroupLookup['001|G'],'P');assert.equal(result.matchRules.length,1);assert.deepEqual(result.categoryLookup,{keep:'category'});
|
||||
assert.throws(()=>editClassification(result,selection,' ',defaults));
|
||||
assert.throws(()=>editClassification(result,{kind:'projectGroup',row:{customerCode:'001',businessGroup:'G',sourceKey:'002|G'}},'P',defaults));
|
||||
});
|
||||
test('interval overrides and conflicting rule identities cannot silently mask a classification edit',()=>{
|
||||
const project={kind:'projectGroup',row:{mappingType:'PROJECT_GROUP',customerCode:'001',businessGroup:'G',sourceKey:'001|G'}};
|
||||
assert.throws(()=>editClassification({effectiveRanges:[{mappingType:'PROJECT_GROUP',sourceKey:'001|G'}]},project,'P',[]),/期间规则/);
|
||||
const id=classificationRuleId(source);
|
||||
assert.throws(()=>editClassification({matchRules:[{id,stage:'bright',conditions:[]}]},selection,'G',[]),/冲突/);
|
||||
});
|
||||
|
||||
test('editing a disabled project relationship enables only that relationship and rejects unavailable targets',()=>{
|
||||
const selection={kind:'projectGroup',row:{mappingType:'PROJECT_GROUP',customerCode:'001',businessGroup:'G',sourceKey:'001|G'}};
|
||||
const base={masterData:{projectGroups:[{code:'P',name:'项目组A',enabled:true}]},disabledMappings:{projectGroupLookup:['001|G','002|G']}};
|
||||
const result=editClassification(base,selection,'项目组A',[]);
|
||||
assert.deepEqual(result.disabledMappings.projectGroupLookup,['002|G']);
|
||||
assert.deepEqual(base.disabledMappings.projectGroupLookup,['001|G','002|G']);
|
||||
assert.throws(()=>editClassification(base,selection,'不存在的项目组',[]),/未登记/);
|
||||
});
|
||||
|
||||
test('removable conditions apply to all matching rows without an implicit unclassified predicate',()=>{
|
||||
const options={stage:'all',conditions:[{field:'@department',operator:'EQUALS',value:'产业部A'},{field:'销售片区',operator:'EQUALS',value:'销售区A'}]};
|
||||
const result=editClassification({matchRules:[]},selection,'G',[],options);
|
||||
assert.deepEqual(result.matchRules[0].conditions,options.conditions);assert.equal(result.matchRules[0].stage,'all');
|
||||
assert.equal(result.matchRules[0].conditions.some(c=>c.field==='@group'),false);
|
||||
assert.equal(classificationRuleId(source,options),classificationRuleId(source,{...options,conditions:[...options.conditions].reverse()}));
|
||||
const specific=editClassification({matchRules:[]},selection,'G',[],{stage:'all'});
|
||||
assert.ok(specific.matchRules[0].priority<result.matchRules[0].priority);
|
||||
assert.throws(()=>editClassification({},selection,'G',[],{stage:'all',conditions:[]}),/至少一项/);
|
||||
});
|
||||
Reference in New Issue
Block a user