commit b70e7221387e9e65f2e82c4866cb9fda46288a3d
parent 7ba09be38250b4360d800309a9dc15b0612fc117
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Sat, 23 Aug 2025 14:47:26 -0700
Update unit tests
Test loading of default calculator options and address gap in workout
calculator tests.
Diffstat:
5 files changed, 330 insertions(+), 207 deletions(-)
diff --git a/tests/unit/views/BatchCalculator.spec.js b/tests/unit/views/BatchCalculator.spec.js
@@ -1,36 +1,100 @@
import { beforeEach, test, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import BatchCalculator from '@/views/BatchCalculator.vue';
+import { defaultTargetSets } from '@/core/targets';
+import { detectDefaultUnitSystem } from '@/core/units';
beforeEach(() => {
localStorage.clear();
});
-test('should load global options from localStorage', async () => {
- // Initialize localStorage
- localStorage.setItem('running-tools.global-options', JSON.stringify({
- defaultUnitSystem: 'imperial',
+test('should initialize regular options to default values', async () => {
+ // Initialize component
+ const wrapper = shallowMount(BatchCalculator);
+
+ // Assert regular options are initialized
+ expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ });
+ expect(wrapper.findComponent({ name: 'time-input' }).vm.modelValue).to.equal(15);
+ expect(wrapper.findComponent({ name: 'integer-input' }).vm.modelValue).to.equal(20);
+ expect(wrapper.find('select[aria-label="Calculator"]').element.value).to.equal('workout');
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
+ defaultUnitSystem: detectDefaultUnitSystem(),
racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
+ model: 'AverageModel',
+ riegelExponent: 1.06,
},
- }));
+ });
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.batchOptions).to.deep.equal({
+ calculator: 'workout',
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ increment: 15,
+ label: '',
+ rows: 20,
+ });
+});
+test('should initialize calculator options to default values', async () => {
// Initialize component
const wrapper = shallowMount(BatchCalculator);
- // Assert data loaded
- expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
+ // Assert pace calculator options are initialized
+ await wrapper.find('select[aria-label="Calculator"]').setValue('pace');
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ selectedTargetSet: '_pace_targets',
+ });
+ expect(wrapper.findComponent({ name: 'double-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._pace_targets.targets);
+
+ // Assert race calculator options are loaded
+ await wrapper.find('select[aria-label="Calculator"]').setValue('race');
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ selectedTargetSet: '_race_targets',
+ });
+ expect(wrapper.findComponent({ name: 'double-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._race_targets.targets);
+
+ // Assert workout calculator options are loaded
+ await wrapper.find('select[aria-label="Calculator"]').setValue('workout');
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ customTargetNames: false,
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
},
+ selectedTargetSet: '_workout_targets',
});
+ expect(wrapper.findComponent({ name: 'double-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._workout_targets.targets);
});
-test('should load batch options from localStorage', async () => {
+test('should load regular options from localStorage', async () => {
// Initialize localStorage
+ localStorage.setItem('running-tools.global-options', JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }));
localStorage.setItem('running-tools.batch-calculator-options', JSON.stringify({
calculator: 'race',
increment: 32,
@@ -46,6 +110,15 @@ test('should load batch options from localStorage', async () => {
// Initialize component
const wrapper = shallowMount(BatchCalculator);
+ // Assert data loaded
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ });
+
// Assert options loaded
expect(wrapper.find('select[aria-label="Calculator"]').element.value).to.equal('race');
expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
@@ -190,7 +263,7 @@ test('should load calculator options from localStorage', async () => {
.to.deep.equal(selectedTargetSets[2].targets);
});
-test('should save global options to localStorage when modified', async () => {
+test('should save regular options to localStorage when modified', async () => {
// Initialize localStorage
localStorage.setItem('running-tools.default-unit-system', '"metric"');
@@ -214,11 +287,6 @@ test('should save global options to localStorage when modified', async () => {
riegelExponent: 1.30,
},
}));
-});
-
-test('should save batch options to localStorage when modified', async () => {
- // Initialize component
- const wrapper = shallowMount(BatchCalculator);
// Update input pace
await wrapper.findComponent({ name: 'pace-input' }).setValue({
diff --git a/tests/unit/views/PaceCalculator.spec.js b/tests/unit/views/PaceCalculator.spec.js
@@ -2,31 +2,39 @@ import { beforeEach, test, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import PaceCalculator from '@/views/PaceCalculator.vue';
import { defaultTargetSets } from '@/core/targets';
+import { detectDefaultUnitSystem } from '@/core/units';
beforeEach(() => {
localStorage.clear();
});
-test('should load global options from localStorage', async () => {
- // Initialize localStorage
- localStorage.setItem('running-tools.global-options', JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
- },
- }));
-
+test('should initialize options to default values', async () => {
// Initialize component
const wrapper = shallowMount(PaceCalculator);
- // Assert selection is loaded
+ // Assert options are initialized
+ expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ });
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions
- .defaultUnitSystem).to.equal('imperial');
+ .defaultUnitSystem).to.equal(detectDefaultUnitSystem());
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ selectedTargetSet: '_pace_targets',
+ });
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.targetSets)
+ .to.deep.equal({ _pace_targets: defaultTargetSets._pace_targets });
+ expect(wrapper.findComponent({ name: 'single-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._pace_targets.targets);
});
-test('should load pace options and target sets from localStorage', async () => {
- // Initialize localStorage
+test('should load options from localStorage', async () => {
const targetSets = {
'_pace_targets': {
name: 'Pace targets #1',
@@ -45,6 +53,15 @@ test('should load pace options and target sets from localStorage', async () => {
],
},
};
+
+ // Initialize localStorage
+ localStorage.setItem('running-tools.global-options', JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }));
localStorage.setItem('running-tools.pace-calculator-target-sets', JSON.stringify(targetSets));
localStorage.setItem('running-tools.pace-calculator-options', JSON.stringify({
input: {
@@ -58,12 +75,14 @@ test('should load pace options and target sets from localStorage', async () => {
// Initialize component
const wrapper = shallowMount(PaceCalculator);
- // Assert selection is loaded
+ // Assert options are loaded
expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
distanceValue: 1,
distanceUnit: 'miles',
time: 600,
});
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions
+ .defaultUnitSystem).to.equal('imperial');
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
input: {
distanceValue: 1,
@@ -78,30 +97,7 @@ test('should load pace options and target sets from localStorage', async () => {
.to.deep.equal(targetSets.B.targets);
});
-test('should save global options to localStorage when modified', async () => {
- // Initialize component
- const wrapper = shallowMount(PaceCalculator);
-
- // Change default units
- await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }, 'globalOptions');
-
- // New default units should be saved to localStorage
- expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }));
-});
-
-test('should save pace options and target sets to localStorage when modified', async () => {
+test('should save options to localStorage when modified', async () => {
const targetSets = {
'_pace_targets': {
name: 'Pace targets #1',
@@ -124,6 +120,24 @@ test('should save pace options and target sets to localStorage when modified', a
// Initialize component
const wrapper = shallowMount(PaceCalculator);
+ // Change default units
+ await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }, 'globalOptions');
+
+ // New default units should be saved to localStorage
+ expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }));
+
// Update input pace
await wrapper.findComponent({ name: 'pace-input' }).setValue({
distanceValue: 1,
diff --git a/tests/unit/views/RaceCalculator.spec.js b/tests/unit/views/RaceCalculator.spec.js
@@ -2,36 +2,44 @@ import { beforeEach, test, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import RaceCalculator from '@/views/RaceCalculator.vue';
import { defaultTargetSets } from '@/core/targets';
+import { detectDefaultUnitSystem } from '@/core/units';
beforeEach(() => {
localStorage.clear();
});
-test('should load global options from localStorage', async () => {
- // Initialize localStorage
- localStorage.setItem('running-tools.global-options', JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
- },
- }));
-
+test('should initialize options to default values', async () => {
// Initialize component
const wrapper = shallowMount(RaceCalculator);
- // Assert data loaded
+ // Assert options are initialized
+ expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ });
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
- defaultUnitSystem: 'imperial',
+ defaultUnitSystem: detectDefaultUnitSystem(),
racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
+ model: 'AverageModel',
+ riegelExponent: 1.06,
},
});
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ selectedTargetSet: '_race_targets',
+ });
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.targetSets)
+ .to.deep.equal({ _race_targets: defaultTargetSets._race_targets });
+ expect(wrapper.findComponent({ name: 'single-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._race_targets.targets);
});
-test('should load race options and target sets from localStorage', async () => {
- // Initialize localStorage
+test('should load options from localStorage', async () => {
const targetSets = {
'_race_targets': {
name: 'Race targets #1',
@@ -50,6 +58,15 @@ test('should load race options and target sets from localStorage', async () => {
],
},
};
+
+ // Initialize localStorage
+ localStorage.setItem('running-tools.global-options', JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }));
localStorage.setItem('running-tools.race-calculator-target-sets', JSON.stringify(targetSets));
localStorage.setItem('running-tools.race-calculator-options', JSON.stringify({
input: {
@@ -63,7 +80,14 @@ test('should load race options and target sets from localStorage', async () => {
// Initialize component
const wrapper = shallowMount(RaceCalculator);
- // Assert data loaded
+ // Assert options are loaded
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ });
expect(wrapper.findComponent({ name: 'pace-input' }).vm.modelValue).to.deep.equal({
distanceValue: 1,
distanceUnit: 'miles',
@@ -83,30 +107,7 @@ test('should load race options and target sets from localStorage', async () => {
.to.deep.equal(targetSets.B.targets);
});
-test('should save global options to localStorage when modified', async () => {
- // Initialize component
- const wrapper = shallowMount(RaceCalculator);
-
- // Update options
- await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
- },
- }, 'globalOptions');
-
- // New global options should be saved to localStorage
- expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
- },
- }));
-});
-
-test('should save local options and target sets to localStorage when modified', async () => {
+test('should save options to localStorage when modified', async () => {
const targetSets = {
'_race_targets': {
name: 'Race targets #1',
@@ -129,6 +130,24 @@ test('should save local options and target sets to localStorage when modified',
// Initialize component
const wrapper = shallowMount(RaceCalculator);
+ // Update options
+ await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }, 'globalOptions');
+
+ // New global options should be saved to localStorage
+ expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }));
+
// Update input race
await wrapper.findComponent({ name: 'pace-input' }).setValue({
distanceValue: 1,
diff --git a/tests/unit/views/SplitCalculator.spec.js b/tests/unit/views/SplitCalculator.spec.js
@@ -1,33 +1,32 @@
import { beforeEach, test, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import SplitCalculator from '@/views/SplitCalculator.vue';
+import { defaultTargetSets } from '@/core/targets';
+import { detectDefaultUnitSystem } from '@/core/units';
beforeEach(() => {
localStorage.clear();
});
-test('should load global options from localStorage', async () => {
- // Initialize localStorage
- localStorage.setItem('running-tools.global-options', JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }));
-
+test('should initialize options to default values', async () => {
// Initialize component
const wrapper = shallowMount(SplitCalculator);
- // Assert data loaded
+ // Assert options are initialized
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions
- .defaultUnitSystem).to.equal('imperial');
+ .defaultUnitSystem).to.equal(detectDefaultUnitSystem());
expect(wrapper.findComponent({ name: 'split-output-table' }).vm.defaultUnitSystem)
- .to.equal('imperial');
+ .to.equal(detectDefaultUnitSystem());
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ selectedTargetSet: '_split_targets',
+ });
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.targetSets)
+ .to.deep.equal({ _split_targets: defaultTargetSets._split_targets });
+ expect(wrapper.findComponent({ name: 'split-output-table' }).vm.modelValue)
+ .to.deep.equal(defaultTargetSets._split_targets.targets);
});
-test('should load split options and target sets from localStorage', async () => {
- // Initialize localStorage
+test('should load options from localStorage', async () => {
const targetSets = {
'_split_targets': {
name: 'Split targets',
@@ -46,6 +45,15 @@ test('should load split options and target sets from localStorage', async () =>
],
},
};
+
+ // Initialize localStorage
+ localStorage.setItem('running-tools.global-options', JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }));
localStorage.setItem('running-tools.split-calculator-target-sets', JSON.stringify(targetSets));
localStorage.setItem('running-tools.split-calculator-options', JSON.stringify({
selectedTargetSet: 'B',
@@ -54,7 +62,11 @@ test('should load split options and target sets from localStorage', async () =>
// Initialize component
const wrapper = shallowMount(SplitCalculator);
- // Assert data loaded
+ // Assert options are loaded
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions
+ .defaultUnitSystem).to.equal('imperial');
+ expect(wrapper.findComponent({ name: 'split-output-table' }).vm.defaultUnitSystem)
+ .to.equal('imperial');
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
selectedTargetSet: 'B',
});
@@ -64,48 +76,7 @@ test('should load split options and target sets from localStorage', async () =>
.to.deep.equal(targetSets.B.targets);
});
-test('should save global options to localStorage when modified', async () => {
- // Initialize component
- const wrapper = shallowMount(SplitCalculator);
-
- // Set default units setting
- await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
- defaultUnitSystem: 'metric',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }, 'globalOptions');
-
- // New default units should be saved to localStorage
- expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
- defaultUnitSystem: 'metric',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }));
-
- // Update default units setting
- await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }, 'globalOptions');
-
- // New default units should be saved to localStorage
- expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'AverageModel',
- riegelExponent: 1.06,
- },
- }));
-});
-
-test('should save split options and target sets to localStorage when modified', async () => {
+test('should save options to localStorage when modified', async () => {
const targetSets1 = {
'_split_targets': {
name: 'Split targets',
@@ -147,6 +118,42 @@ test('should save split options and target sets to localStorage when modified',
// Initialize component
const wrapper = shallowMount(SplitCalculator);
+ // Set default units setting
+ await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
+ defaultUnitSystem: 'metric',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }, 'globalOptions');
+
+ // New default units should be saved to localStorage
+ expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
+ defaultUnitSystem: 'metric',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }));
+
+ // Update default units setting
+ await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }, 'globalOptions');
+
+ // New default units should be saved to localStorage
+ expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'AverageModel',
+ riegelExponent: 1.06,
+ },
+ }));
+
// Update target sets and selected target set via AdvancedOptionsInput
await wrapper.findComponent({ name: 'advanced-options-input' }).setValue(targetSets1,
'targetSets');
diff --git a/tests/unit/views/WorkoutCalculator.spec.js b/tests/unit/views/WorkoutCalculator.spec.js
@@ -2,36 +2,40 @@ import { beforeEach, test, expect } from 'vitest';
import { shallowMount } from '@vue/test-utils';
import WorkoutCalculator from '@/views/WorkoutCalculator.vue';
import { defaultTargetSets } from '@/core/targets';
+import { detectDefaultUnitSystem } from '@/core/units';
beforeEach(() => {
localStorage.clear();
});
-test('should load global options from localStorage', async () => {
- // Initialize localStorage
- localStorage.setItem('running-tools.global-options', JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
- },
- }));
-
+test('should initialize options to default values', async () => {
// Initialize component
const wrapper = shallowMount(WorkoutCalculator);
- // Assert data loaded
+ // Assert options are initialized
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
- defaultUnitSystem: 'imperial',
+ defaultUnitSystem: detectDefaultUnitSystem(),
racePredictionOptions: {
- model: 'PurdyPointsModel',
- riegelExponent: 1.2,
+ model: 'AverageModel',
+ riegelExponent: 1.06,
},
});
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
+ customTargetNames: false,
+ input: {
+ distanceValue: 5,
+ distanceUnit: 'kilometers',
+ time: 1200,
+ },
+ selectedTargetSet: '_workout_targets',
+ });
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.targetSets)
+ .to.deep.equal({ _workout_targets: defaultTargetSets._workout_targets });
+ expect(wrapper.findComponent({ name: 'single-output-table' }).vm.targets)
+ .to.deep.equal(defaultTargetSets._workout_targets.targets);
});
-test('should load workout options and target sets from localStorage', async () => {
- // Initialize localStorage
+test('should load options from localStorage', async () => {
const targetSets = {
'_workout_targets': {
name: 'Workout targets #1',
@@ -75,6 +79,15 @@ test('should load workout options and target sets from localStorage', async () =
],
},
};
+
+ // Initialize localStorage
+ localStorage.setItem('running-tools.global-options', JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ }));
localStorage.setItem('running-tools.workout-calculator-target-sets', JSON.stringify(targetSets));
localStorage.setItem('running-tools.workout-calculator-options', JSON.stringify({
customTargetNames: true,
@@ -89,7 +102,14 @@ test('should load workout options and target sets from localStorage', async () =
// Initialize component
const wrapper = shallowMount(WorkoutCalculator);
- // Assert data loaded
+ // Assert options are loaded
+ expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.globalOptions).to.deep.equal({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'PurdyPointsModel',
+ riegelExponent: 1.2,
+ },
+ });
expect(wrapper.findComponent({ name: 'advanced-options-input' }).vm.options).to.deep.equal({
customTargetNames: true,
input: {
@@ -105,30 +125,7 @@ test('should load workout options and target sets from localStorage', async () =
.to.deep.equal(targetSets.B.targets);
});
-test('should save global options to localStorage when modified', async () => {
- // Initialize component
- const wrapper = shallowMount(WorkoutCalculator);
-
- // Update options
- await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'CameronModel',
- riegelExponent: 1.3,
- },
- }, 'globalOptions');
-
- // Assert data saved to localStorage
- expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
- defaultUnitSystem: 'imperial',
- racePredictionOptions: {
- model: 'CameronModel',
- riegelExponent: 1.3,
- },
- }));
-});
-
-test('should save workout options and target sets to localStorage when modified', async () => {
+test('should save options to localStorage when modified', async () => {
const targetSets = {
'_workout_targets': {
name: 'Workout targets #1',
@@ -176,6 +173,24 @@ test('should save workout options and target sets to localStorage when modified'
// Initialize component
const wrapper = shallowMount(WorkoutCalculator);
+ // Update options
+ await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'CameronModel',
+ riegelExponent: 1.3,
+ },
+ }, 'globalOptions');
+
+ // Assert data saved to localStorage
+ expect(localStorage.getItem('running-tools.global-options')).to.equal(JSON.stringify({
+ defaultUnitSystem: 'imperial',
+ racePredictionOptions: {
+ model: 'CameronModel',
+ riegelExponent: 1.3,
+ },
+ }));
+
// Update input race
await wrapper.findComponent({ name: 'pace-input' }).setValue({
distanceValue: 1,
@@ -309,9 +324,9 @@ test('should correctly calculate results according to options', async () => {
// Enter input race data
await wrapper.findComponent({ name: 'pace-input' }).setValue({
- distanceValue: 5,
- distanceUnit: 'kilometers',
- time: 1200,
+ distanceValue: 2,
+ distanceUnit: 'miles',
+ time: 630,
});
// Update model and Riegel exponent
@@ -333,15 +348,15 @@ test('should correctly calculate results according to options', async () => {
// Assert result is correct
expect(result.key).to.equal('1 km @ 10 km');
- expect(result.value).to.equal('4:17.23');
+ expect(result.value).to.equal('3:39.23');
// Update target name customization
await wrapper.findComponent({ name: 'advanced-options-input' }).setValue({
customTargetNames: true,
input: {
- distanceValue: 5,
- distanceUnit: 'kilometers',
- time: 1200,
+ distanceValue: 2,
+ distanceUnit: 'miles',
+ time: 630,
},
selectedTargetSet: '_workout_targets',
}, 'options');
@@ -355,7 +370,7 @@ test('should correctly calculate results according to options', async () => {
// Assert result is correct
expect(result.key).to.equal('foo');
- expect(result.value).to.equal('4:17.23');
+ expect(result.value).to.equal('3:39.23');
});
test('should correctly set AdvancedOptionsInput type prop', async () => {