commit a453d2764980fd01b21cb96bd89e51b095bfd363
parent 12d49f0ff558fd801f2416d6f758d54c0d81df0e
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Sun, 29 Jun 2025 15:46:26 -0700
Save unit calculator category to localStorage
Diffstat:
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/views/UnitCalculator.vue b/src/views/UnitCalculator.vue
@@ -70,7 +70,7 @@ const inputs = useStorage('unit-calculator-inputs', {
/**
* The unit category
*/
-const category = ref('distance');
+const category = useStorage('unit-calculator-category', 'distance');
/**
* The inputs for the current category
diff --git a/tests/e2e/cross-calculator.spec.js b/tests/e2e/cross-calculator.spec.js
@@ -216,7 +216,7 @@ test('Cross-calculator', async ({ page }) => {
await expect(page.getByRole('row')).toHaveCount(5);
// Assert general localStorage entries are correct
- await expect(await page.evaluate(() => localStorage.length)).toEqual(17);
+ await expect(await page.evaluate(() => localStorage.length)).toEqual(18);
await expect(await page.evaluate(() => localStorage.getItem('running-tools.default-unit-system')))
.toEqual(JSON.stringify('metric'));
@@ -349,6 +349,9 @@ test('Cross-calculator', async ({ page }) => {
// Assert localStorage entries for the unit calculator are correct
await expect(await page.evaluate(() =>
+ localStorage.getItem('running-tools.unit-calculator-category')))
+ .toEqual(JSON.stringify('speed_and_pace'));
+ await expect(await page.evaluate(() =>
localStorage.getItem('running-tools.unit-calculator-inputs'))).toEqual(JSON.stringify({
distance: {
inputValue: 1,
@@ -491,8 +494,7 @@ test('Cross-calculator', async ({ page }) => {
await page.getByRole('button', { name: 'Unit Calculator' }).click();
// Assert result is correct (state not reset)
- // TODO: add unit-calculator-category setting?
- // await expect(page.getByLabel('Output value')).toHaveText('00:09:39.366');
+ await expect(page.getByLabel('Output value')).toHaveText('00:09:39.366');
// Return to workout calculator
await page.getByRole('link', { name: 'Back' }).click();
diff --git a/tests/e2e/unit-calculator.spec.js b/tests/e2e/unit-calculator.spec.js
@@ -55,13 +55,13 @@ test('Unit Calculator', async ({ page }) => {
// Reload page
await page.reload();
- // Assert distance result is correct (state not reset)
- await expect(page.getByLabel('Output value')).toHaveText('3.107');
-
// Assert time result is correct (state not reset)
- await page.getByLabel('Selected unit category').selectOption('Time');
await expect(page.getByLabel('Output value')).toHaveText('24872.100');
+ // Assert distance result is correct (state not reset)
+ await page.getByLabel('Selected unit category').selectOption('Distance');
+ await expect(page.getByLabel('Output value')).toHaveText('3.107');
+
// Assert speed & pace result is correct (state not reset)
await page.getByLabel('Selected unit category').selectOption('Speed & Pace');
await expect(page.getByLabel('Output value')).toHaveText('00:09:39.366');