2021-09-04 21:36:59 +02:00
|
|
|
import { assert } from 'chai'
|
|
|
|
|
|
|
|
import { datasetKeys } from '@/utils/statistics'
|
|
|
|
import { formatTooltipValue } from '@/utils/tooltip'
|
|
|
|
|
|
|
|
describe('formatTooltipValue', () => {
|
|
|
|
const testsParams = [
|
2021-11-24 18:01:38 +01:00
|
|
|
{
|
|
|
|
description: 'returns 3 if input is average speed',
|
|
|
|
inputDisplayedData: datasetKeys[0], // 'average_speed'
|
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 km/h',
|
|
|
|
},
|
2021-09-04 21:36:59 +02:00
|
|
|
{
|
|
|
|
description: 'returns 3 if input is workouts count',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30',
|
2021-09-04 21:36:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 00m:03s if input is total duration',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[2], // 'total_duration'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '00m 30s',
|
2021-09-04 21:36:59 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-03 20:39:14 +01:00
|
|
|
description: 'returns 3.00 km if input is total distance',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[3], // 'total_distance'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 km',
|
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 30 m if input is total ascent',
|
|
|
|
inputDisplayedData: datasetKeys[4], // 'total_ascent'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '30 m',
|
2021-11-03 20:39:14 +01:00
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 30 m if input is total descent',
|
|
|
|
inputDisplayedData: datasetKeys[5], // 'total_descent'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '30 m',
|
2021-09-04 21:36:59 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
|
|
|
assert.equal(
|
|
|
|
formatTooltipValue(
|
|
|
|
testParams.inputDisplayedData,
|
2021-11-14 12:26:36 +01:00
|
|
|
testParams.inputValue,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
testParams.expectedResult
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('formatTooltipValue after conversion to imperial units', () => {
|
|
|
|
const testsParams = [
|
2021-11-24 18:01:38 +01:00
|
|
|
{
|
|
|
|
description: 'returns 30 if input is average speed',
|
|
|
|
inputDisplayedData: datasetKeys[0], // 'average_speed'
|
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 mi/h',
|
|
|
|
},
|
2021-11-14 12:26:36 +01:00
|
|
|
{
|
|
|
|
description: 'returns 30 if input is workouts count',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
|
2021-11-14 12:26:36 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 00m:03s if input is total duration',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[2], // 'total_duration'
|
2021-11-14 12:26:36 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '00m 30s',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 30 mi if input is total distance',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[3], // 'total_distance'
|
2021-11-14 12:26:36 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 mi',
|
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 98.43 ft if input is total ascent',
|
|
|
|
inputDisplayedData: datasetKeys[4], // 'total_ascent'
|
2021-11-14 12:26:36 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '98.43 ft',
|
2021-11-14 12:26:36 +01:00
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 98.43 ft if input is total descent',
|
|
|
|
inputDisplayedData: datasetKeys[5], // 'total_descent'
|
2021-11-14 12:26:36 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '98.43 ft',
|
2021-11-14 12:26:36 +01:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
|
|
|
assert.equal(
|
|
|
|
formatTooltipValue(
|
|
|
|
testParams.inputDisplayedData,
|
|
|
|
testParams.inputValue,
|
|
|
|
true
|
2021-09-04 21:36:59 +02:00
|
|
|
),
|
|
|
|
testParams.expectedResult
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2021-09-05 09:41:39 +02:00
|
|
|
|
|
|
|
describe('formatTooltipValue (formatWithUnits = false)', () => {
|
|
|
|
const testsParams = [
|
2021-11-24 18:01:38 +01:00
|
|
|
{
|
|
|
|
description: 'returns 3 if input is average speed',
|
|
|
|
inputDisplayedData: datasetKeys[0], // 'average_speed'
|
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 km/h',
|
|
|
|
},
|
2021-09-05 09:41:39 +02:00
|
|
|
{
|
|
|
|
description: 'returns 3 if input is workouts count',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30',
|
2021-09-05 09:41:39 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: 'returns 00:03 if input is total duration',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[2], // 'total_duration'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '00:30',
|
2021-09-05 09:41:39 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-03 20:39:14 +01:00
|
|
|
description: 'returns 3.00 km if input is total distance',
|
2021-11-24 18:01:38 +01:00
|
|
|
inputDisplayedData: datasetKeys[3], // 'total_distance'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
|
|
|
expectedResult: '30.00 km',
|
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 30 m if input is total ascent',
|
|
|
|
inputDisplayedData: datasetKeys[4], // 'total_ascent'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '30 m',
|
2021-11-03 20:39:14 +01:00
|
|
|
},
|
|
|
|
{
|
2022-07-18 21:08:09 +02:00
|
|
|
description: 'returns 30 m if input is total descent',
|
|
|
|
inputDisplayedData: datasetKeys[5], // 'total_decent'
|
2021-11-03 20:39:14 +01:00
|
|
|
inputValue: 30,
|
2022-07-18 21:08:09 +02:00
|
|
|
expectedResult: '30 m',
|
2021-09-05 09:41:39 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
|
|
|
assert.equal(
|
|
|
|
formatTooltipValue(
|
|
|
|
testParams.inputDisplayedData,
|
|
|
|
testParams.inputValue,
|
2021-11-14 12:26:36 +01:00
|
|
|
false,
|
2021-09-05 09:41:39 +02:00
|
|
|
false
|
|
|
|
),
|
|
|
|
testParams.expectedResult
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|