54 lines
3.5 KiB
JavaScript
54 lines
3.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { defaultFullMetricFields, metricStageColumnPlan } from '../src/metricColumnPlan.ts';
|
|
|
|
const columnKeys = columns => columns.map(column => column.kind === 'defect' ? `defect:${column.name}` : column.field);
|
|
|
|
test('six query views start with the requested key/full metric selection', () => {
|
|
for (const page of ['overall', 'department', 'group', 'product']) assert.equal(defaultFullMetricFields(page), false, page);
|
|
for (const page of ['blackProduct', 'brightProduct']) assert.equal(defaultFullMetricFields(page), true, page);
|
|
});
|
|
|
|
test('key metrics preserve the current four-column stage table', () => {
|
|
const rows = [{ black: { defects: [{ name: '责废', weight: 10 }] }, bright: { defects: [{ name: '镀废', weight: 5 }] } }];
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'black', false, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'rate']);
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'bright', false, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'rate']);
|
|
});
|
|
|
|
test('full trend fields share summary ordering, including bright headquarters scrap', () => {
|
|
const rows = [{
|
|
black: { defects: [{ name: '责废', weight: 8 }, { name: '料废', weight: 2 }, { name: '外废', weight: 1 }] },
|
|
bright: { defects: [{ name: '镀废', weight: 4 }, { name: '材料废', weight: 3 }, { name: '加工废', weight: 2 }, { name: '扩散废', weight: 1 }] },
|
|
}];
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'black', true, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:责废', 'defect:料废', 'defect:外废', 'rate']);
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'bright', true, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:镀废', 'defect:材料废', 'defect:加工废', 'defect:扩散废', 'headquartersScrapWeight', 'rate']);
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'bright', true, 'withoutHeadquartersScrap')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:镀废', 'defect:材料废', 'defect:加工废', 'defect:扩散废', 'rate']);
|
|
});
|
|
|
|
test('bright headquarters scrap stays immediately after diffusion scrap when defect order varies', () => {
|
|
const rows = [{ bright: { defects: [
|
|
{ name: '材料废', weight: 3 }, { name: '扩散废', weight: 1 },
|
|
{ name: '镀废', weight: 4 }, { name: '加工废', weight: 2 },
|
|
] } }];
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'bright', true, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:材料废', 'defect:扩散废', 'headquartersScrapWeight', 'defect:镀废', 'defect:加工废', 'rate']);
|
|
});
|
|
|
|
test('full field plan only uses defect values returned in the trend rows and does not mutate them', () => {
|
|
const rows = [
|
|
{ black: { defects: [{ name: '责废', weight: 8 }] }, bright: { defects: [] } },
|
|
{ black: { defects: [{ name: '料废', weight: null }] }, bright: { defects: [{ name: '镀废', weight: 1 }] } },
|
|
];
|
|
const before = structuredClone(rows);
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'black', true, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:责废', 'defect:料废', 'rate']);
|
|
assert.deepEqual(columnKeys(metricStageColumnPlan(rows, 'bright', true, 'original')),
|
|
['totalWeight', 'qualifiedWeight', 'scrapWeight', 'defect:镀废', 'headquartersScrapWeight', 'rate']);
|
|
assert.deepEqual(rows, before);
|
|
});
|