FitTrackee/fittrackee_client/tests/unit/utils/tooltip.spec.ts

212 lines
5.9 KiB
TypeScript
Raw Normal View History

2023-11-11 17:12:20 +01:00
import { describe, it, expect } from 'vitest'
2021-09-04 21:36:59 +02:00
import { datasetKeys } from '@/utils/statistics'
import { formatTooltipValue } from '@/utils/tooltip'
describe('formatTooltipValue', () => {
const testsParams = [
{
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',
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
inputValue: 30,
expectedResult: '30',
2021-09-04 21:36:59 +02:00
},
{
description: 'returns 00m:03s if input is total duration',
inputDisplayedData: datasetKeys[2], // 'total_duration'
inputValue: 30,
expectedResult: '00m 30s',
2021-09-04 21:36:59 +02:00
},
{
description: 'returns 3.00 km if input is total distance',
inputDisplayedData: datasetKeys[3], // 'total_distance'
inputValue: 30,
expectedResult: '30.00 km',
},
{
description: 'returns 30 km if input is total ascent',
inputDisplayedData: datasetKeys[4], // 'total_ascent'
inputValue: 30,
expectedResult: '30.00 km',
},
{
description: 'returns 30 km if input is total descent',
inputDisplayedData: datasetKeys[5], // 'total_descent'
inputValue: 30,
expectedResult: '30.00 km',
2021-09-04 21:36:59 +02:00
},
]
testsParams.map((testParams) => {
it(testParams.description, () => {
2023-11-11 17:12:20 +01:00
expect(
2021-09-04 21:36:59 +02:00
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
false
2023-11-11 17:12:20 +01:00
)
).toStrictEqual(testParams.expectedResult)
})
})
})
describe('formatTooltipValue after conversion to imperial units', () => {
const testsParams = [
{
description: 'returns 30 if input is average speed',
inputDisplayedData: datasetKeys[0], // 'average_speed'
inputValue: 30,
expectedResult: '30.00 mi/h',
},
{
description: 'returns 30 if input is workouts count',
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
inputValue: 30,
expectedResult: '30',
},
{
description: 'returns 00m:03s if input is total duration',
inputDisplayedData: datasetKeys[2], // 'total_duration'
inputValue: 30,
expectedResult: '00m 30s',
},
{
description: 'returns 30 mi if input is total distance',
inputDisplayedData: datasetKeys[3], // 'total_distance'
inputValue: 30,
expectedResult: '30.00 mi',
},
{
description: 'returns 30 mi if input is total ascent',
inputDisplayedData: datasetKeys[4], // 'total_ascent'
inputValue: 30,
expectedResult: '30.00 mi',
},
{
description: 'returns 30 mi if input is total descent',
inputDisplayedData: datasetKeys[5], // 'total_descent'
inputValue: 30,
expectedResult: '30.00 mi',
},
]
testsParams.map((testParams) => {
it(testParams.description, () => {
2023-11-11 17:12:20 +01:00
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
true
2023-11-11 17:12:20 +01:00
)
).toStrictEqual(testParams.expectedResult)
2021-09-04 21:36:59 +02:00
})
})
})
2022-07-19 16:54:31 +02:00
describe('formatTooltipValue with unitFrom', () => {
const testsParams = [
{
description: 'returns 30 km if input is total ascent',
inputDisplayedData: datasetKeys[4], // 'total_ascent'
inputValue: 30,
expectedResult: '30.00 m',
useImperialUnits: false,
},
{
description: 'returns 30 km if input is total descent',
inputDisplayedData: datasetKeys[5], // 'total_descent'
inputValue: 30,
expectedResult: '30.00 m',
useImperialUnits: false,
},
{
description: 'returns 30 mi if input is total ascent',
inputDisplayedData: datasetKeys[4], // 'total_ascent'
inputValue: 30,
expectedResult: '30.00 ft',
useImperialUnits: true,
},
{
description: 'returns 30 mi if input is total descent',
inputDisplayedData: datasetKeys[5], // 'total_descent'
inputValue: 30,
expectedResult: '30.00 ft',
useImperialUnits: true,
},
]
testsParams.map((testParams) => {
it(testParams.description, () => {
2023-11-11 17:12:20 +01:00
expect(
2022-07-19 16:54:31 +02:00
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
testParams.useImperialUnits,
true,
'm'
2023-11-11 17:12:20 +01:00
)
).toStrictEqual(testParams.expectedResult)
2022-07-19 16:54:31 +02:00
})
})
})
describe('formatTooltipValue (formatWithUnits = false)', () => {
const testsParams = [
{
description: 'returns 3 if input is average speed',
inputDisplayedData: datasetKeys[0], // 'average_speed'
inputValue: 30,
expectedResult: '30.00 km/h',
},
{
description: 'returns 3 if input is workouts count',
inputDisplayedData: datasetKeys[1], // 'nb_workouts'
inputValue: 30,
expectedResult: '30',
},
{
description: 'returns 00:03 if input is total duration',
inputDisplayedData: datasetKeys[2], // 'total_duration'
inputValue: 30,
expectedResult: '00:30',
},
{
description: 'returns 3.00 km if input is total distance',
inputDisplayedData: datasetKeys[3], // 'total_distance'
inputValue: 30,
expectedResult: '30.00 km',
},
{
description: 'returns 30 km if input is total ascent',
inputDisplayedData: datasetKeys[4], // 'total_ascent'
inputValue: 30,
expectedResult: '30.00 km',
},
{
description: 'returns 30 km if input is total descent',
inputDisplayedData: datasetKeys[5], // 'total_descent'
inputValue: 30,
expectedResult: '30.00 km',
},
]
testsParams.map((testParams) => {
it(testParams.description, () => {
2023-11-11 17:12:20 +01:00
expect(
formatTooltipValue(
testParams.inputDisplayedData,
testParams.inputValue,
false,
false
2023-11-11 17:12:20 +01:00
)
).toStrictEqual(testParams.expectedResult)
})
})
})