Files
quality_analyse/web/verification/source_records_context.test.mjs
T

27 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { freezeSourceRecordsQuery } from '../src/sourceRecordsContext.ts';
test('period rows bind their own year/month/quarter and keep the selected object',()=>{
const query={year:2026,month:10,monthStart:1,monthEnd:9,product:'产品A',department:'部门A',extraFilters:{customer:['001']}};
for(const [period,expected] of [['2026-02',{year:2026,month:2}],['2026-Q2',{year:2026,quarter:2}],['2025',{year:2025}]]) {
const result=freezeSourceRecordsQuery(query,'release','overall',{key:period,label:period,month:period,period,product:null});
assert.equal(result.product,query.product);assert.equal(result.department,query.department);
assert.deepEqual(Object.fromEntries(['year','month','quarter','monthStart','monthEnd'].filter(k=>result[k]!==undefined).map(k=>[k,result[k]])),expected);
assert.equal(result.releaseId,'release');
}
assert.equal(query.month,10);assert.equal(query.monthEnd,9);
});
test('clicking a month clears the parent range; object rows retain their original period',()=>{
const query={year:2026,monthStart:1,monthEnd:9,product:'产品A'};
const monthly=freezeSourceRecordsQuery(query,'release','overall',{key:'2026-02',month:'2026-02'},2);
assert.equal(monthly.month,2);assert.equal(monthly.monthStart,undefined);assert.equal(monthly.monthEnd,undefined);
for(const view of ['department','group','product','projectGroup']) {
for(const key of ['__UNASSIGNED__','',' ']) {
const object=freezeSourceRecordsQuery(query,'release',view,{key,[view]:null});
assert.equal(object[view],'__UNASSIGNED__');assert.equal(object.monthStart,1);assert.equal(object.monthEnd,9);
}
}
});