Client - display converted distance in stats charts

This commit is contained in:
Sam
2021-11-14 12:26:36 +01:00
parent 1c6b70d454
commit c0acff9e3d
6 changed files with 209 additions and 18 deletions

View File

@ -316,7 +316,7 @@ describe('formatStats', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [], inputStats),
formatStats(inputParams, false, sports, [], inputStats, false),
expected
)
})
@ -369,7 +369,7 @@ describe('formatStats', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [2], inputStats),
formatStats(inputParams, false, sports, [2], inputStats, false),
expected
)
})
@ -427,7 +427,7 @@ describe('formatStats', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [], inputStats),
formatStats(inputParams, false, sports, [], inputStats, false),
expected
)
})
@ -515,7 +515,7 @@ describe('formatStats', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [1], inputStats),
formatStats(inputParams, false, sports, [1], inputStats, false),
expected
)
})
@ -605,7 +605,7 @@ describe('formatStats (duration)', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [1], inputStats),
formatStats(inputParams, false, sports, [1], inputStats, false),
expected
)
})
@ -692,7 +692,7 @@ describe('formatStats (duration)', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [1], inputStats),
formatStats(inputParams, false, sports, [1], inputStats, false),
expected
)
})
@ -780,7 +780,7 @@ describe('formatStats (duration)', () => {
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [1], inputStats),
formatStats(inputParams, false, sports, [1], inputStats, false),
expected
)
})
@ -868,7 +868,95 @@ describe('formatStats (duration)', () => {
},
}
assert.deepEqual(
formatStats(inputParams, true, sports, [1], inputStats),
formatStats(inputParams, true, sports, [1], inputStats, false),
expected
)
})
it('returns datasets after conversion to imperial units', () => {
const inputStats: TStatisticsFromApi = {
'2021-10-03': {
1: {
nb_workouts: 1,
total_distance: 10,
total_duration: 3000,
total_ascent: 150,
total_descent: 100,
},
},
'2021-10-10': {
1: {
nb_workouts: 1,
total_distance: 15,
total_duration: 3500,
total_ascent: 250,
total_descent: 150,
},
2: {
nb_workouts: 2,
total_distance: 20,
total_duration: 3000,
total_ascent: 150,
total_descent: 200,
},
},
'2021-10-17': {
3: {
nb_workouts: 2,
total_distance: 20,
total_duration: 3000,
total_ascent: 100,
total_descent: 100,
},
},
}
const inputParams = {
duration: 'week',
start: new Date('October 03, 2021 00:00:00'),
end: new Date('October 23, 2021 23:59:59.999'),
}
const expected: IStatisticsChartData = {
labels: ['03/10/2021', '10/10/2021', '17/10/2021'],
datasets: {
nb_workouts: [
{
label: 'Cycling (Sport)',
backgroundColor: ['#4c9792'],
data: [1, 1, 0],
},
],
total_distance: [
{
label: 'Cycling (Sport)',
backgroundColor: ['#4c9792'],
data: [6.21, 9.32, 0],
},
],
total_duration: [
{
label: 'Cycling (Sport)',
backgroundColor: ['#4c9792'],
data: [3000, 3500, 0],
},
],
total_ascent: [
{
label: 'Cycling (Sport)',
backgroundColor: ['#4c9792'],
data: [492.13, 820.21, 0],
},
],
total_descent: [
{
label: 'Cycling (Sport)',
backgroundColor: ['#4c9792'],
data: [328.08, 492.13, 0],
},
],
},
}
assert.deepEqual(
formatStats(inputParams, false, sports, [1], inputStats, true),
expected
)
})

View File

@ -42,7 +42,56 @@ describe('formatTooltipValue', () => {
assert.equal(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue
testParams.inputValue,
false
),
testParams.expectedResult
)
})
})
})
describe('formatTooltipValue after conversion to imperial units', () => {
const testsParams = [
{
description: 'returns 30 if input is workouts count',
inputDisplayedData: datasetKeys[0], // 'nb_workouts'
inputValue: 30,
expectedResult: '30',
},
{
description: 'returns 00m:03s if input is total duration',
inputDisplayedData: datasetKeys[1], // 'total_duration'
inputValue: 30,
expectedResult: '00m 30s',
},
{
description: 'returns 30 mi if input is total distance',
inputDisplayedData: datasetKeys[2], // 'total_distance'
inputValue: 30,
expectedResult: '30.00 mi',
},
{
description: 'returns 0.03 mi if input is total ascent',
inputDisplayedData: datasetKeys[3], // 'total_distance'
inputValue: 30,
expectedResult: '0.03 mi',
},
{
description: 'returns 0.03 mi if input is total descent',
inputDisplayedData: datasetKeys[4], // 'total_distance'
inputValue: 30,
expectedResult: '0.03 mi',
},
]
testsParams.map((testParams) => {
it(testParams.description, () => {
assert.equal(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
true
),
testParams.expectedResult
)
@ -90,6 +139,7 @@ describe('formatTooltipValue (formatWithUnits = false)', () => {
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
false,
false
),
testParams.expectedResult