新增:月度数据关键和完整指标切换及分视图默认
This commit is contained in:
@@ -5,6 +5,7 @@ import ts from 'typescript';
|
||||
import React from 'react';
|
||||
import { queryScrapWeight } from '../src/queryMetricValues.ts';
|
||||
import { defectWeightRate } from '../src/trendMetrics.ts';
|
||||
import { metricStageColumnPlan } from '../src/metricColumnPlan.ts';
|
||||
import { createMetricWorkbook, workbookColumns } from '../src/metricWorkbook.ts';
|
||||
|
||||
const source = fs.readFileSync(new URL('../src/QueryPage.tsx', import.meta.url), 'utf8');
|
||||
@@ -17,13 +18,13 @@ const table = slice('export function MetricTable(', 'function MetricTablePaginat
|
||||
function fixture(props) {
|
||||
let exported, detail = 0, basis = 0;
|
||||
const ref = {};
|
||||
const render = new Function('React', 'useImperativeHandle', 'defectWeightRate', 'queryScrapWeight', 'downloadMetricWorkbook', ts.transpileModule(`
|
||||
const render = new Function('React', 'useImperativeHandle', 'defectWeightRate', 'queryScrapWeight', 'metricStageColumnPlan', 'downloadMetricWorkbook', ts.transpileModule(`
|
||||
const MONTHS=Array.from({length:12},(_,i)=>String(i+1).padStart(2,'0')+'月');
|
||||
const SUMMARY_PAGE_SIZE=15;
|
||||
const useCompactTable=()=>false, useState=v=>[v,()=>{}], useEffect=()=>{};
|
||||
const AnimatedMetricText='AnimatedMetricText', Button='Button', Table='Table', MetricTablePagination='Pagination', Tooltip='Tooltip', InfoCircleOutlined='Info';
|
||||
${helpers}\n${table}\nreturn MetricTable;
|
||||
`, {compilerOptions:{jsx:ts.JsxEmit.React,target:ts.ScriptTarget.ES2022}}).outputText)(React, (target, create) => Object.assign(target, create()), defectWeightRate, queryScrapWeight, async (filename, columns, rows, value) => {
|
||||
`, {compilerOptions:{jsx:ts.JsxEmit.React,target:ts.ScriptTarget.ES2022}}).outputText)(React, (target, create) => Object.assign(target, create()), defectWeightRate, queryScrapWeight, metricStageColumnPlan, async (filename, columns, rows, value) => {
|
||||
exported = { filename, columns, rows, workbook: await createMetricWorkbook(columns, rows, value) };
|
||||
});
|
||||
const tree = render({ref,exportFilename:'验收',period:'month',month:9,quarter:3,rateBasis:'original',fullFields:false,onDetail(){detail++;},onBasis(){basis++;},onDrilldown(){},...props});
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user