| | |
| | | import { readFile } from 'node:fs/promises' |
| | | import { test } from 'node:test' |
| | | import ts from 'typescript' |
| | | import load from './load-typescript.cjs' |
| | | const { stepCurveChartOption } = load(new URL('../src/utils/stepCurveChart.ts', import.meta.url)) |
| | | const { projectCycleChartOption, projectMetrics } = load(new URL('../src/utils/projectCycleChart.ts', import.meta.url)) |
| | | import { toTestDisplayValue } from '../src/utils/testDataUnits.ts' |
| | | |
| | | async function componentFunctions(path, names, bindings) { |
| | |
| | | return new Function(...Object.keys(bindings), 'toTestDisplayValue', script)(...Object.values(bindings), toTestDisplayValue) |
| | | } |
| | | |
| | | async function measurementModule() { |
| | | const name = 'reportMeasurementChart' |
| | | const source = await readFile(new URL(`../src/utils/${name}.ts`, import.meta.url), 'utf8') |
| | | const script = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText |
| | | const exports = {} |
| | | new Function('exports', 'require', script)(exports, id => { |
| | | assert.equal(id, './testDataUnits') |
| | | return { toTestDisplayValue } |
| | | }) |
| | | return exports |
| | | } |
| | | const { measurementChartOption } = await measurementModule() |
| | | const { measurementChartOption } = load(new URL('../src/utils/reportMeasurementChart.ts', import.meta.url)) |
| | | |
| | | test('工步图电流序列和纵轴同步为 mA,保留负数与零', async () => { |
| | | const records = [-8.1651, 0, -8.1674].map((current, index) => ({ batteryNo: 'BAT-1', current, deviceTime: index * 60000, sourceType: 'SNAPSHOT' })) |
| | | const { metricValue, chartOption } = await componentFunctions('components/ConsoleChartPanel.vue', ['metricValue', 'recordTime', 'chartOption'], { |
| | | props: { cells: [{ no: 'BAT-1' }] }, selectedRecords: () => records, selectedCells: { value: [{ no: 'BAT-1' }] }, metricMatches: () => true, seriesColors: { value: ['#3978f6'] }, |
| | | stepCurveChartOption, props: { cells: [{ no: 'BAT-1' }] }, selectedRecords: () => records, selectedCells: { value: [{ no: 'BAT-1' }] }, metricMatches: () => true, seriesColors: { value: ['#3978f6'] }, |
| | | }) |
| | | const option = chartOption({ key: 'current', unit: 'mA' }) |
| | | assert.deepEqual(option.series[0].data, [-8165.1, 0, -8167.4]) |
| | | assert.deepEqual(option.series[0].data, [[0,-8165.1], [60,0], [120,-8167.4]]) |
| | | assert.equal(option.yAxis[0].name, 'mA') |
| | | assert.ok(option.yAxis[0].min < -8167.4) |
| | | assert.ok(option.yAxis[0].max > 0) |
| | |
| | | |
| | | test('项目图表以 mAh 除以 F,缺失和无效 F 不造点,电压不缩放', async () => { |
| | | const capacityFactor = { value: 2 } |
| | | const funcs = await componentFunctions('components/ConsoleProjectChartPanel.vue', ['numericValue', 'lastStepVoltage', 'dischargeCapacityPerFactor', 'seriesValues', 'chartOption'], { |
| | | const funcs = await componentFunctions('components/ConsoleProjectChartPanel.vue', ['numericValue', 'lastStepVoltage', 'dischargeCapacityPerFactor'], { |
| | | props: { cells: [{ no: 'BAT-1' }], cycles: [{ batteryNo: 'BAT-1', cycleNo: 1, dischargeCapacity: 8.5122 }, { batteryNo: 'BAT-1', cycleNo: 2, dischargeCapacity: 0 }], steps: [{ batteryNo: 'BAT-1', cycleNo: 1, stepNo: 1, endVoltage: 0.8999 }] }, |
| | | capacityFactor, cycleLabels: { value: ['1', '2', '3'] }, seriesColors: { value: ['#3978f6'] }, |
| | | }) |
| | | const option = funcs.chartOption({ key: 'dischargeCapacityF', unit: 'mAh / F' }) |
| | | assert.deepEqual(option.series[0].data, [4256.1, 0, null]) |
| | | const option = projectCycleChartOption(projectMetrics[2], [{key:'BAT-1',name:'BAT-1',points:[1,2,3].map(position=>({position,values:{dischargeCapacityF:funcs.dischargeCapacityPerFactor('BAT-1',position)}}))}], [1,2,3], []) |
| | | assert.deepEqual(option.series[0].data.map(point=>point.value[1]), [4256.1, 0, null]) |
| | | assert.equal(option.yAxis.name, 'mAh / F') |
| | | assert.equal(option.yAxis.axisLabel.formatter(7366.332499999995), '7366.33') |
| | | assert.equal(funcs.lastStepVoltage('BAT-1', 1), 0.8999) |
| | |
| | | assert.equal(option.series[0].connectNulls, false) |
| | | assert.equal(option.xAxis.max, 7200) |
| | | assert.equal(option.xAxis.axisLabel.formatter(1800), '0.5') |
| | | assert.deepEqual(option.yAxis.map(axis => [axis.name, axis.min, axis.max]), [['mA', -143.75, 250], ['mA', -143.75, 250]]) |
| | | assert.deepEqual(option.yAxis.map(axis => [axis.name, axis.min, axis.max]), [['mA', -205, 330], ['mA', -205, 330]]) |
| | | const hidden = measurementChartOption(metric, [{ ...items[0], hidden: true }, items[1]], ['#123456', '#abcdef']) |
| | | assert.equal(hidden.series.length, 1) |
| | | assert.equal(hidden.series[0].lineStyle.color, '#abcdef') |
| | | assert.equal(hidden.legend.selected['测试甲 · 1号'], false) |
| | | assert.equal(hidden.series[1].itemStyle.color, '#abcdef') |
| | | assert.equal(hidden.xAxis.max, option.xAxis.max) |
| | | assert.equal(hidden.yAxis[0].min, option.yAxis[0].min) |
| | | assert.deepEqual(items, before) |
| | |
| | | assert.deepEqual(voltage.series[0].data, [[0, 3.2], [17, null], [180, 0]]) |
| | | const temperature = measurementChartOption({ key: 'temperature', unit: '℃' }, [items[0]], ['#123456']) |
| | | assert.deepEqual(temperature.series[0].data, [[8, 0], [21, null], [181, -5]]) |
| | | }) |
| | | }) |