优化:整理指标目标并支持中文字段公式编辑
黑片和亮片按结果展示完整公式,在同一窗口维护条件与未匹配取值。支持中文字段选择、运算符和求和,并保留原计算语义及特殊策略。 移除重复账号入口与配置说明,统一紧凑表格。保留仓库既有权限判断,不包含此前未同步的角色迁移、预览快照或运行数据。 验证:前端构建及68项相关检查通过。
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { displayFormula, stageRuleRows, ruleChangeSummary, matchingTarget, policyDescription } from '../src/rulePresentation.ts';
|
||||
const original={sourceFields:{black:{platingWeight:'送电镀重量'},bright:{goodWeight:'合格重量'}},rowRules:Array.from({length:22},(_,i)=>({stage:i<13?'black':'bright',target:i%3===0?'black_good_weight':i%3===1?'black_scrap_weight':'black_reuse_good',formula:String(i),when:{field:'inspectionNote',operator:'CONTAINS',value:'过账'}})),metricRules:{blackRate:{formula:'blackGood / blackTotal'}}};
|
||||
test('stage tables keep every execution index and full rule unchanged',()=>{
|
||||
const before=JSON.stringify(original);const all=[...stageRuleRows(original,'black'),...stageRuleRows(original,'bright')].sort((a,b)=>a.index-b.index);
|
||||
assert.equal(all.length,22);assert.deepEqual(all.map(({index,...row})=>row),original.rowRules);assert.equal(JSON.stringify(original),before);assert.deepEqual(ruleChangeSummary(original,structuredClone(original)),[]);
|
||||
});
|
||||
test('business formula translation explains percentages without mutating source rules',()=>{
|
||||
assert.equal(displayFormula('blackRate * brightRate'),'黑片合格率 × 亮片合格率');assert.match(policyDescription({zeroDenominatorPolicy:'ONE',nullResultPolicy:'NULL'}),/分母为0:按100%处理/);assert.match(policyDescription({zeroDenominatorPolicy:'ONE'},false),/分母为0:取1/);
|
||||
const next=structuredClone(original);next.metricRules.blackRate.formula='(blackGood / blackTotal)';assert.deepEqual(ruleChangeSummary(original,next),['合格率公式 1 项']);assert.notEqual(original.metricRules.blackRate.formula,next.metricRules.blackRate.formula);
|
||||
});
|
||||
test('target display preserves existing specificity and group tie-break precedence',()=>{
|
||||
const overall={dimensions:{},value:.955},department={dimensions:{department:'A'},value:.96},group={dimensions:{group:'G'},value:.97},specific={dimensions:{department:'A',group:'G'},value:.98};const list=[overall,department,group,specific];const before=JSON.stringify(list);
|
||||
assert.equal(matchingTarget(list,{department:'A',group:'G'}),specific);assert.equal(matchingTarget(list.slice(0,3),{department:'A',group:'G'}),group);assert.equal(matchingTarget(list,{department:'A',group:'OTHER'}),department);assert.equal(matchingTarget(list,{department:'B'}),overall);assert.equal(JSON.stringify(list),before);
|
||||
});
|
||||
test('stage table reflects the actual row order without business grouping',()=>{
|
||||
const definition={rowRules:[{stage:'black',target:'black_responsibility_scrap',formula:'1'},{stage:'black',target:'black_good_weight',formula:'2'},{stage:'black',target:'black_material_scrap',formula:'3'}]};
|
||||
assert.deepEqual(stageRuleRows(definition,'black').map(row=>row.target),['black_responsibility_scrap','black_good_weight','black_material_scrap']);
|
||||
});
|
||||
Reference in New Issue
Block a user