修复:项目组分类仅补齐未分类并在完成后刷新列表

This commit is contained in:
2026-10-31 20:04:24 +08:00
parent cbe7fc17bb
commit 572873c6b8
21 changed files with 257 additions and 64 deletions
@@ -23,22 +23,22 @@ test('blank-key source creates a narrowly scoped rule and preserves inherited de
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.equal(result.projectGroupLookup,undefined);assert.equal(result.matchRules.length,2);assert.equal(result.matchRules[0].target,'projectGroup');assert.equal(result.matchRules[0].onlyUnclassified,true);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 ranges=[{mappingType:'PROJECT_GROUP',sourceKey:'001|G'}];assert.deepEqual(editClassification({effectiveRanges:ranges},project,'P',[]).effectiveRanges,ranges);
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',()=>{
test('project maintenance creates only-unclassified rules without changing disabled lookups or existing classifications',()=>{
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(result.disabledMappings.projectGroupLookup,['001|G','002|G']);assert.equal(result.matchRules[0].onlyUnclassified,true);assert.equal(result.matchRules[0].target,'projectGroup');assert.deepEqual(result.matchRules[0].conditions,[{field:'客户代码',operator:'EQUALS',value:'001'},{field:'@group',operator:'EQUALS',value:'G'}]);assert.equal(editClassification(result,selection,'项目组A',[]).matchRules.length,1);
assert.deepEqual(base.disabledMappings.projectGroupLookup,['001|G','002|G']);
assert.throws(()=>editClassification(base,selection,'不存在的项目组',[]),/未登记/);
});
@@ -51,3 +51,9 @@ test('legacy twelve-column workbooks preserve the existing unclassified-only res
const tables=configurationTables(base,'matchRules');tables[0].headers.pop();tables[0].rows.forEach(row=>row.pop());
for(const mode of ['MERGE','REPLACE'])assert.equal(importConfigurationTables(base,tables,'matchRules',mode).definition.matchRules[0].onlyUnclassified,true);
});
test('project unclassified-only rules retain their scope and customer codes through Excel',async()=>{
const projectRule={...rule,target:'projectGroup',conditions:[{field:'客户代码',operator:'EQUALS',value:'00001'},{field:'@group',operator:'EQUALS',value:'G'}]};const source={matchRules:[projectRule]};
const workbook=await createConfigurationWorkbook(source,'matchRules');const tables=await readConfigurationWorkbook(await workbook.xlsx.writeBuffer());
assert.deepEqual(importConfigurationTables(source,tables,'matchRules','REPLACE').definition,source);
});
@@ -0,0 +1,32 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import ts from 'typescript';
const source=ts.transpileModule(readFileSync(new URL('../src/useDataWorkflowOperation.ts',import.meta.url),'utf8'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}}).outputText.replace(/^import .*;\n/gm,'').replace(/export /g,'');
const tick=()=>new Promise(resolve=>setImmediate(resolve));
const deferred=()=>{let resolve;const promise=new Promise(done=>{resolve=done;});return{promise,resolve};};
test('the actual workflow hook refreshes retained data after completion, rather than while work is pending',async()=>{
const final=deferred(),events=[],callbacks=[],storage=new Map();let calls=0;
const window={localStorage:storage,setTimeout:fn=>setImmediate(fn),dispatchEvent:event=>events.push(event.type)};
const localStorage={getItem:key=>storage.get(key)??null,setItem:(key,value)=>storage.set(key,value),removeItem:key=>storage.delete(key)};
const api={dataWorkflowOperation:async()=>++calls===1?{operationId:'job',status:'RUNNING'}:final.promise};
const hooks={useState:value=>[value,()=>{}],useRef:current=>({current}),useCallback:fn=>fn,useEffect:fn=>{fn();}};
const load=new Function('api','window','localStorage','WORKSPACE_INVALIDATED','hooks',`const {useState,useRef,useCallback,useEffect}=hooks;${source};return useDataWorkflowOperation;`);
const hook=load(api,window,localStorage,'quality-workspace-invalidated',hooks)('project',value=>callbacks.push(value));
await hook.start(async()=>({operationId:'job',status:'QUEUED'}));await tick();await tick();
assert.equal(calls,2);assert.deepEqual(events,[]);assert.equal(storage.size,1);
final.resolve({operationId:'job',status:'COMPLETED',currentReleaseId:'new-release'});await tick();
assert.deepEqual(events,['quality-workspace-invalidated']);assert.equal(callbacks[0].currentReleaseId,'new-release');assert.equal(storage.size,0);
});
test('failed work never refreshes retained data as though a new version had been published',async()=>{
const events=[],callbacks=[];const api={dataWorkflowOperation:async()=>({operationId:'job',status:'FAILED',errors:[{message:'rejected'}]})};
const hooks={useState:value=>[value,()=>{}],useRef:current=>({current}),useCallback:fn=>fn,useEffect:fn=>{fn();}};
const localStorage={getItem:()=>null,setItem:()=>{},removeItem:()=>{}};
const window={setTimeout:fn=>setImmediate(fn),dispatchEvent:event=>events.push(event.type)};
const load=new Function('api','window','localStorage','WORKSPACE_INVALIDATED','hooks',`const {useState,useRef,useCallback,useEffect}=hooks;${source};return useDataWorkflowOperation;`);
const hook=load(api,window,localStorage,'quality-workspace-invalidated',hooks)('project',value=>callbacks.push(value));
await hook.start(async()=>({operationId:'job',status:'QUEUED'}));await tick();assert.deepEqual(events,[]);assert.deepEqual(callbacks,[]);
});