commit 6b9c27168d431654d0c8484167f5d97be2ae6d96
parent 621da008c90a490b8c2e6e1fc163438b329758b3
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Sun, 9 Jun 2024 13:47:49 -0700
Update format of target objects
Replace 'result' property with 'type' property
Diffstat:
11 files changed, 186 insertions(+), 186 deletions(-)
diff --git a/src/components/TargetEditor.vue b/src/components/TargetEditor.vue
@@ -22,7 +22,7 @@
<tbody>
<tr v-for="(item, index) in internalValue.targets" :key="index">
- <td v-if="item.result === 'time'">
+ <td v-if="item.type === 'distance'">
<decimal-input v-model="item.distanceValue" aria-label="Target distance value"
:min="0" :digits="2"/>
<select v-model="item.distanceUnit" aria-label="Target distance unit">
@@ -131,7 +131,7 @@ watch(internalValue, (newValue) => {
*/
function addDistanceTarget() {
internalValue.value.targets.push({
- result: 'time',
+ type: 'distance',
distanceValue: 1,
distanceUnit: unitUtils.getDefaultDistanceUnit(props.defaultUnitSystem),
});
@@ -142,7 +142,7 @@ function addDistanceTarget() {
*/
function addTimeTarget() {
internalValue.value.targets.push({
- result: 'distance',
+ type: 'time',
time: 600,
});
}
diff --git a/src/utils/calculators.js b/src/utils/calculators.js
@@ -46,14 +46,14 @@ function calculatePaceResults(input, target, defaultUnitSystem) {
distanceValue: target.distanceValue,
distanceUnit: target.distanceUnit,
time: target.time,
- result: target.result,
+ result: target.type === 'distance' ? 'time' : 'distance',
};
const pace = paceUtils.getPace(unitUtils.convertDistance(input.distanceValue, input.distanceUnit,
'meters'), input.time);
// Add missing value to result
- if (target.result === 'time') {
+ if (target.type === 'distance') {
// Convert target distance into meters
const d2 = unitUtils.convertDistance(target.distanceValue, target.distanceUnit, 'meters');
@@ -92,13 +92,13 @@ function calculateRaceResults(input, target, options, defaultUnitSystem) {
distanceValue: target.distanceValue,
distanceUnit: target.distanceUnit,
time: target.time,
- result: target.result,
+ result: target.type === 'distance' ? 'time' : 'distance',
};
const d1 = unitUtils.convertDistance(input.distanceValue, input.distanceUnit, 'meters');
// Add missing value to result
- if (target.result === 'time') {
+ if (target.type === 'distance') {
// Convert target distance into meters
const d2 = unitUtils.convertDistance(target.distanceValue, target.distanceUnit, 'meters');
diff --git a/src/utils/targets.js b/src/utils/targets.js
@@ -7,11 +7,11 @@ import unitUtils from '@/utils/units';
*/
function sort(targets) {
return [
- ...targets.filter((item) => item.result === 'time')
+ ...targets.filter((item) => item.type === 'distance')
.sort((a, b) => unitUtils.convertDistance(a.distanceValue, a.distanceUnit, 'meters')
- unitUtils.convertDistance(b.distanceValue, b.distanceUnit, 'meters')),
- ...targets.filter((item) => item.result === 'distance')
+ ...targets.filter((item) => item.type === 'time')
.sort((a, b) => a.time - b.time),
];
}
@@ -20,71 +20,71 @@ const defaultTargetSets = {
'_pace_targets': {
name: 'Common Pace Targets',
targets: [
- { result: 'time', distanceValue: 100, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 200, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 300, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 400, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 600, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 800, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1000, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1200, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1500, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1600, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 3200, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 100, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 200, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 300, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 400, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 600, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 800, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1000, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1200, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1500, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1600, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 3200, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 3, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 4, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 6, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 8, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 4, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 6, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 8, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 6, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 8, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 10, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 6, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 8, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 0.5, distanceUnit: 'marathons' },
- { result: 'time', distanceValue: 1, distanceUnit: 'marathons' },
+ { type: 'distance', distanceValue: 0.5, distanceUnit: 'marathons' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'marathons' },
- { result: 'distance', time: 600 },
- { result: 'distance', time: 1800 },
- { result: 'distance', time: 3600 },
+ { type: 'time', time: 600 },
+ { type: 'time', time: 1800 },
+ { type: 'time', time: 3600 },
],
},
'_race_targets': {
name: 'Common Race Targets',
targets: [
- { result: 'time', distanceValue: 400, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 800, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1500, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1600, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 3200, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 400, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 800, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1500, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1600, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 3200, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 6, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 8, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 15, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 6, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 8, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 15, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 0.5, distanceUnit: 'marathons' },
- { result: 'time', distanceValue: 1, distanceUnit: 'marathons' },
+ { type: 'distance', distanceValue: 0.5, distanceUnit: 'marathons' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'marathons' },
],
},
'_split_targets': {
name: '5K Mile Splits',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
},
};
diff --git a/src/views/SplitCalculator.vue b/src/views/SplitCalculator.vue
@@ -105,7 +105,7 @@ const results = computed(() => {
if (!targetSets.value[selectedTargetSet.value]) return [];
let targets = targetUtils.sort(targetSets.value[selectedTargetSet.value].targets.filter(x =>
- x.result === 'time'));
+ x.type === 'distance'));
for (let i = 0; i < targets.length; i += 1) {
// Calculate split and total times
diff --git a/tests/unit/components/TargetEditor.spec.js b/tests/unit/components/TargetEditor.spec.js
@@ -9,9 +9,9 @@ test('should correctly render target set', async () => {
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'kilometers', distanceValue: 1.61, result: 'time' },
- { distanceUnit: 'miles', distanceValue: 3.11, result: 'time' },
- { time: 600, result: 'distance' },
+ { distanceUnit: 'kilometers', distanceValue: 1.61, type: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 3.11, type: 'distance' },
+ { time: 600, type: 'time' },
],
},
},
@@ -72,8 +72,8 @@ test('add distance target button should correctly add imperial distance target',
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
],
},
defaultUnitSystem: 'imperial'
@@ -88,9 +88,9 @@ test('add distance target button should correctly add imperial distance target',
[{
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
- { distanceUnit: 'miles', distanceValue: 1, result: 'time'},
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
+ { distanceUnit: 'miles', distanceValue: 1, type: 'distance'},
],
}],
]);
@@ -103,8 +103,8 @@ test('add distance target button should correctly add metric distance target', a
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
],
},
defaultUnitSystem: 'metric'
@@ -119,9 +119,9 @@ test('add distance target button should correctly add metric distance target', a
[{
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
- { distanceUnit: 'kilometers', distanceValue: 1, result: 'time'},
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
+ { distanceUnit: 'kilometers', distanceValue: 1, type: 'distance'},
],
}],
]);
@@ -134,8 +134,8 @@ test('add time target button should correctly add time target', async () => {
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
],
},
},
@@ -148,9 +148,9 @@ test('add time target button should correctly add time target', async () => {
expect(wrapper.emitted()['update:modelValue']).to.deep.equal([
[{ name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 0, result: 'time' },
- { time: 0, result: 'distance' },
- { time: 600, result: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 0, type: 'distance' },
+ { time: 0, type: 'time' },
+ { time: 600, type: 'time' },
],
}],
]);
@@ -163,7 +163,7 @@ test('Should emit input event when targets are updated', async () => {
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 2, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 2, type: 'distance' },
],
},
},
@@ -178,7 +178,7 @@ test('Should emit input event when targets are updated', async () => {
{
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 3, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
],
},
],
@@ -192,7 +192,7 @@ test('Should emit input event when target set name is updated', async () => {
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 2, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 2, type: 'distance' },
],
},
},
@@ -207,7 +207,7 @@ test('Should emit input event when target set name is updated', async () => {
{
name: 'My target set #2',
targets: [
- { distanceUnit: 'miles', distanceValue: 2, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 2, type: 'distance' },
],
},
],
@@ -221,9 +221,9 @@ test('removeTarget button should correctly remove target', async () => {
modelValue: {
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 1, result: 'time' },
- { distanceUnit: 'miles', distanceValue: 2, result: 'time' },
- { distanceUnit: 'miles', distanceValue: 3, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 1, type: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 2, type: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
],
},
},
@@ -237,8 +237,8 @@ test('removeTarget button should correctly remove target', async () => {
[{
name: 'My target set',
targets: [
- { distanceUnit: 'miles', distanceValue: 1, result: 'time' },
- { distanceUnit: 'miles', distanceValue: 3, result: 'time' },
+ { distanceUnit: 'miles', distanceValue: 1, type: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
],
}],
]);
diff --git a/tests/unit/components/TargetSetSelector.spec.js b/tests/unit/components/TargetSetSelector.spec.js
@@ -11,17 +11,17 @@ test('should correctly render target sets options', async () => {
'A': {
name: '1st target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
],
},
'B': {
name: '2nd target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
],
},
},
@@ -48,17 +48,17 @@ test('Create New Target Set option should correctly add target set', async () =>
'A': {
name: '1st target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
],
},
'B': {
name: '2nd target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
],
},
};
@@ -102,17 +102,17 @@ test('Revert event should correctly reset a default target set', async () => {
'_split_targets': {
name: '1st target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
],
},
'1234567890123': {
name: '2nd target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
],
},
};
@@ -139,7 +139,7 @@ test('Revert event should correctly reset a default target set', async () => {
// Assert target sets were correctly updated
targetSets._split_targets.name = '5K Mile Splits';
targetSets._split_targets.targets[2] = {
- result: 'time',
+ type: 'distance',
distanceValue: 5,
distanceUnit: 'kilometers',
};
@@ -152,17 +152,17 @@ test('Revert event should correctly delete a custom target set', async () => {
'_split_targets': {
name: '1st target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
],
},
'1234567890123': {
name: '2nd target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
],
},
};
@@ -195,9 +195,9 @@ test('edit button should open target editor with the correct props for default s
'_split_targets': {
name: '5K Mile Splits',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
},
};
@@ -228,9 +228,9 @@ test('edit button should open target editor with the correct props for custom se
'1234567890123': {
name: '2nd target set',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 10, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 10, distanceUnit: 'kilometers' },
],
},
};
@@ -261,11 +261,11 @@ test('should sort target set before target editor is opened', async () => {
'_split_targets': {
name: '5K Mile Splits',
targets: [
- { result: 'distance', timeValue: 60 },
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'time', timeValue: 60 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
],
},
};
@@ -286,11 +286,11 @@ test('should sort target set before target editor is opened', async () => {
expect(wrapper.findComponent({ name: 'target-editor' }).vm.modelValue).to.deep.equal({
name: '5K Mile Splits',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 3, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
- { result: 'distance', timeValue: 60 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 3, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'time', timeValue: 60 },
],
});
});
diff --git a/tests/unit/utils/calculators.spec.js b/tests/unit/utils/calculators.spec.js
@@ -10,7 +10,7 @@ test('should correctly calculate pace times', () => {
const target = {
distanceValue: 20,
distanceUnit: 'meters',
- result: 'time',
+ type: 'distance',
};
const result = calculatorUtils.calculatePaceResults(input, target, 'metric');
@@ -32,7 +32,7 @@ test('should correctly calculate pace distances according to default units setti
};
const target = {
time: 600,
- result: 'distance',
+ type: 'time',
};
const result1 = calculatorUtils.calculatePaceResults(input, target, 'metric');
@@ -60,7 +60,7 @@ test('should correctly predict race times', () => {
const target = {
distanceValue: 10,
distanceUnit: 'kilometers',
- result: 'time',
+ type: 'distance',
};
const options = {
model: 'AverageModel',
@@ -84,7 +84,7 @@ test('should correctly calculate race distances according to default units setti
};
const target = {
time: 2495,
- result: 'distance',
+ type: 'time',
};
const options = {
model: 'AverageModel',
@@ -116,7 +116,7 @@ test('should correctly predict race times according to race options', () => {
const target = {
distanceValue: 5,
distanceUnit: 'kilometers',
- result: 'time',
+ type: 'distance',
};
const options = {
model: 'RiegelModel',
diff --git a/tests/unit/utils/targets.spec.js b/tests/unit/utils/targets.spec.js
@@ -5,14 +5,14 @@ describe('sort method', () => {
test('should correctly sort targets', () => {
// Initialize unsorted and sorted targets
const input = [
- { time: 60, result: 'distance' },
- { distanceUnit: 'kilometers', distanceValue: 5, result: 'time' },
- { distanceUnit: 'miles', distanceValue: 3, result: 'time' },
+ { time: 60, type: 'time' },
+ { distanceUnit: 'kilometers', distanceValue: 5, type: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
];
const expected = [
- { distanceUnit: 'miles', distanceValue: 3, result: 'time' },
- { distanceUnit: 'kilometers', distanceValue: 5, result: 'time' },
- { time: 60, result: 'distance' },
+ { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
+ { distanceUnit: 'kilometers', distanceValue: 5, type: 'distance' },
+ { time: 60, type: 'time' },
];
// Assert sort method sorts targets correctly
diff --git a/tests/unit/views/PaceCalculator.spec.js b/tests/unit/views/PaceCalculator.spec.js
@@ -23,7 +23,7 @@ test('should correctly calculate time results', async () => {
const result = calculateResult({
distanceValue: 20,
distanceUnit: 'meters',
- result: 'time',
+ type: 'distance',
});
// Assert result is correct
@@ -54,14 +54,14 @@ test('should correctly calculate distance results according to default units set
const calculateResult = wrapper.findComponent({ name: 'single-output-table' }).vm.calculateResult;
// Assert result is correct
- let result = calculateResult({ result: 'distance', time: 600 });
+ let result = calculateResult({ type: 'time', time: 600 });
expect(result.key).to.equal('1.61 km');
// Change default units
await wrapper.find('select[aria-label="Default units"]').setValue('imperial');
// Assert result is correct
- result = calculateResult({ result: 'distance', time: 600 });
+ result = calculateResult({ type: 'time', time: 600 });
expect(result.key).to.equal('1.00 mi');
});
@@ -137,18 +137,18 @@ test('should load selected target set from localStorage', async () => {
const targetSet2 = {
name: 'Pace targets #2',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
};
localStorage.setItem('running-tools.pace-calculator-target-sets', JSON.stringify({
'_pace_targets': {
name: 'Pace targets #1',
targets: [
- { result: 'time', distanceValue: 400, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 800, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1600, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 400, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 800, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1600, distanceUnit: 'meters' },
],
},
'B': targetSet2,
diff --git a/tests/unit/views/RaceCalculator.spec.js b/tests/unit/views/RaceCalculator.spec.js
@@ -23,7 +23,7 @@ test('should correctly predict race times', async () => {
const result = calculateResult({
distanceValue: 10,
distanceUnit: 'kilometers',
- result: 'time',
+ type: 'distance',
});
// Assert result is correct
@@ -52,7 +52,7 @@ test('should correctly calculate distance results according to default units set
const calculateResult = wrapper.findComponent({ name: 'single-output-table' }).vm.calculateResult;
// Assert result is correct
- let result = calculateResult({ result: 'distance', time: 2495 });
+ let result = calculateResult({ type: 'time', time: 2495 });
expect(result.key).to.equal('10.00 km');
expect(result.value).to.equal('41:35');
expect(result.pace).to.equal('4:09 / km');
@@ -63,7 +63,7 @@ test('should correctly calculate distance results according to default units set
await wrapper.find('select[aria-label="Default units"]').setValue('imperial');
// Assert result is correct
- result = calculateResult({ result: 'distance', time: 2495 });
+ result = calculateResult({ type: 'time', time: 2495 });
expect(result.key).to.equal('6.21 mi');
expect(result.value).to.equal('41:35');
expect(result.pace).to.equal('6:41 / mi');
@@ -145,7 +145,7 @@ test('should correctly calculate results according to advanced model options', a
let result = calculateResult({
distanceValue: 10,
distanceUnit: 'kilometers',
- result: 'time',
+ type: 'distance',
});
// Assert result is correct
@@ -161,7 +161,7 @@ test('should correctly calculate results according to advanced model options', a
result = calculateResult({
distanceValue: 10,
distanceUnit: 'kilometers',
- result: 'time',
+ type: 'distance',
});
// Assert result is correct
@@ -211,18 +211,18 @@ test('should load selected target set from localStorage', async () => {
const targetSet2 = {
name: 'Race targets #2',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
};
localStorage.setItem('running-tools.race-calculator-target-sets', JSON.stringify({
'_race_targets': {
name: 'Race targets #1',
targets: [
- { result: 'time', distanceValue: 400, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 800, distanceUnit: 'meters' },
- { result: 'time', distanceValue: 1600, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 400, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 800, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1600, distanceUnit: 'meters' },
],
},
'B': targetSet2,
diff --git a/tests/unit/views/SplitCalculator.spec.js b/tests/unit/views/SplitCalculator.spec.js
@@ -36,9 +36,9 @@ test('should correctly load split times from split targets', async () => {
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
],
},
}));
@@ -134,9 +134,9 @@ test('should correctly sort split targets', async () => {
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers' },
],
},
}));
@@ -170,10 +170,10 @@ test('should ignore time based targets', async () => {
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers' },
- { result: 'distance', time: 600 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers' },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers' },
+ { type: 'time', time: 600 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters' },
],
},
}));
@@ -206,9 +206,9 @@ test('should correctly save split times with split targets in localStorage', asy
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters', split: 180 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters', split: 180 },
],
},
}));
@@ -225,9 +225,9 @@ test('should correctly save split times with split targets in localStorage', asy
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
],
},
}));
@@ -239,17 +239,17 @@ test('should update results when a new target set is selected', async () => {
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
},
'B': {
name: 'Split targets #2',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
],
},
}));
@@ -295,17 +295,17 @@ test('should load selected target set from localStorage', async () => {
'_split_targets': {
name: 'Split targets',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 2, distanceUnit: 'miles' },
- { result: 'time', distanceValue: 5, distanceUnit: 'kilometers' },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'miles' },
+ { type: 'distance', distanceValue: 5, distanceUnit: 'kilometers' },
],
},
'B': {
name: 'Split targets #2',
targets: [
- { result: 'time', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
- { result: 'time', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
- { result: 'time', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
+ { type: 'distance', distanceValue: 1, distanceUnit: 'kilometers', split: 180 },
+ { type: 'distance', distanceValue: 2, distanceUnit: 'kilometers', split: 190 },
+ { type: 'distance', distanceValue: 3000, distanceUnit: 'meters', split: 200 },
],
},
}));