优化记录页趋势分析展示
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
|
||||
const { getTrendData, getBarPercent } = require('../utils/util')
|
||||
const { getTrendData, getBestTrendData, getTrendSummary, getBarPercent } = require('../utils/util')
|
||||
|
||||
test('weekly trend combines multiple sessions from the same day', () => {
|
||||
const records = {
|
||||
@@ -45,3 +45,34 @@ test('bar height remains proportional for very short sessions', () => {
|
||||
assert.ok(getBarPercent(1, 120) < 1)
|
||||
assert.equal(getBarPercent(120, 120), 100)
|
||||
})
|
||||
|
||||
test('trend summary reports total, active periods, and the highest period', () => {
|
||||
const summary = getTrendSummary([
|
||||
{ label: '一', value: 60 },
|
||||
{ label: '二', value: 0 },
|
||||
{ label: '今天', value: 75 }
|
||||
], 'week')
|
||||
|
||||
assert.deepEqual(summary, {
|
||||
totalText: '02:15',
|
||||
activeCount: 2,
|
||||
activeLabel: '训练天数',
|
||||
peakTitle: '最高训练日',
|
||||
peakText: '今天 · 01:15'
|
||||
})
|
||||
})
|
||||
|
||||
test('personal best trend keeps the longest single session in each period', () => {
|
||||
const records = {
|
||||
'2026-07': [
|
||||
{ date: '2026-07-29 08:00:00', duration: 30 },
|
||||
{ date: '2026-07-29 20:00:00', duration: 45 },
|
||||
{ date: '2026-07-23 08:00:00', duration: 60 }
|
||||
]
|
||||
}
|
||||
|
||||
const data = getBestTrendData(records, 'week', new Date(2026, 6, 29))
|
||||
assert.equal(data[0].value, 60)
|
||||
assert.equal(data[6].value, 45)
|
||||
assert.equal(data[6].valueText, '00:45')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user