Files
ftb-project-management/apps/web/lib/effort-summary.test.ts
2026-06-26 15:12:24 +08:00

35 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from 'node:test';
import assert from 'node:assert/strict';
import { buildEffortSummaryMetrics, sumPositiveHours } from './effort-summary';
interface EffortMetricForTest {
label: string;
value: string;
}
test('sumPositiveHours only returns a total when at least one item has a positive value', () => {
const total = sumPositiveHours(
[{ hours: 0.25 }, { hours: undefined }, { hours: 1 }],
(item: { hours?: number }) => item.hours,
);
assert.equal(total, 1.25);
assert.equal(sumPositiveHours([{ hours: 0 }, { hours: undefined }], (item: { hours?: number }) => item.hours), undefined);
});
test('buildEffortSummaryMetrics keeps the shared top metric order and empty estimate placeholders', () => {
const metrics = buildEffortSummaryMetrics({
aiEstimateHours: 0.25,
estimateHours: undefined,
actualHours: 1.5,
manhours: 2,
});
assert.deepEqual(metrics.map((metric: EffortMetricForTest) => metric.label), ['AI预估', '执行预估', '实际耗时', '人力投入']);
assert.equal(metrics[0].value, '0.25h0.01天)');
assert.equal(metrics[1].value, '-');
assert.equal(metrics[2].value, '1.5h0.06天)');
assert.equal(metrics[3].value, '2h0.08天)');
});