Files
ftb-project-management/apps/web/lib/analysis-chart-renderer.test.ts

46 lines
1.6 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { toEChartsOption } from './analysis-chart-renderer';
import type { UnifiedChartSpec } from '@ftb/shared';
test('toEChartsOption renders line_area with smooth line and area gradient', () => {
const spec: UnifiedChartSpec = {
kind: 'line_area',
title: '需求完成趋势',
dataset: { source: [{ label: '2026-07-01', value: 3 }], x: 'label', y: 'value' },
encoding: {
x: { field: 'label', label: '日期' },
y: { field: 'value', label: '完成数' },
value: { field: 'value', label: '完成数' },
color: { mode: 'single' },
},
annotations: [{ type: 'peak', label: '峰值', field: 'value', value: 3 }],
stylePreset: 'apple_vision_light',
};
const option: any = toEChartsOption(spec);
assert.equal(option.series[0].type, 'line');
assert.equal(option.series[0].smooth, true);
assert.ok(option.series[0].areaStyle);
assert.equal(option.xAxis.show, true);
assert.equal(option.yAxis.splitLine.show, false);
});
test('toEChartsOption renders horizontal_bar with rounded bars and single color', () => {
const option: any = toEChartsOption({
kind: 'horizontal_bar',
title: '部门负载',
dataset: { source: [{ label: '研发', value: 8 }], label: 'label', value: 'value' },
encoding: {
value: { field: 'value', label: '待办数' },
color: { mode: 'single' },
},
stylePreset: 'apple_vision_light',
});
assert.equal(option.series[0].type, 'bar');
assert.deepEqual(option.series[0].itemStyle.borderRadius, [0, 8, 8, 0]);
assert.equal(option.color.length, 1);
});