running-tools

A collection of tools for runners and their coaches
git clone https://git.ashermorgan.net/running-tools/
Log | Files | Refs | README

unit-calculator.spec.js (3242B)


      1 import { test, expect } from '@playwright/test';
      2 
      3 test('Unit Calculator', async ({ page }) => {
      4   // Go to unit calculator
      5   await page.goto('/');
      6   await page.getByRole('button', { name: 'Unit Calculator' }).click();
      7   await expect(page).toHaveTitle('Unit Calculator - Running Tools');
      8 
      9   // Test distance unit conversion
     10   {
     11     // Convert distance units (5000m to mi)
     12     await page.getByLabel('Input units').selectOption('Meters');
     13     await page.getByLabel('Input value').fill('5000');
     14     await page.getByLabel('Output units').selectOption('Miles');
     15     await expect(page.getByLabel('Output value')).toHaveText('3.107');
     16   }
     17 
     18   // Test speed and pace unit conversion
     19   {
     20     // Convert speed and pace units (0:04:32/km to mph)
     21     await page.getByLabel('Selected unit category').selectOption('Speed & Pace');
     22     await page.getByLabel('Input units').selectOption('Time per Kilometer');
     23     await page.getByLabel('Input time hours').fill('0');
     24     await page.getByLabel('Input time minutes').fill('4');
     25     await page.getByLabel('Input time seconds').fill('32');
     26     await page.getByLabel('Output units').selectOption('Miles per Hour');
     27     await expect(page.getByLabel('Output value')).toHaveText('8.224');
     28 
     29     // Convert speed and pace units (10 kph to time per mile)
     30     await page.getByLabel('Input units').selectOption('Kilometers per Hour');
     31     await page.getByLabel('Input value').fill('10');
     32     await page.getByLabel('Output units').selectOption('Time per Mile');
     33     await expect(page.getByLabel('Output value')).toHaveText('00:09:39.364');
     34   }
     35 
     36   // Test time unit conversion
     37   {
     38     // Convert time units (83.76 min to hh:mm:ss)
     39     await page.getByLabel('Selected unit category').selectOption('Time');
     40     await page.getByLabel('Input units').selectOption('Minutes');
     41     await page.getByLabel('Input value').fill('83.76');
     42     await page.getByLabel('Output units').selectOption('hh:mm:ss');
     43     await expect(page.getByLabel('Output value')).toHaveText('01:23:45.600');
     44 
     45     // Convert time units (6:54:32.100 to seconds)
     46     await page.getByLabel('Selected unit category').selectOption('Time');
     47     await page.getByLabel('Input units').selectOption('hh:mm:ss');
     48     await page.getByLabel('Input time hours').fill('6');
     49     await page.getByLabel('Input time minutes').fill('54');
     50     await page.getByLabel('Input time seconds').fill('32.1');
     51     await page.getByLabel('Output units').selectOption('seconds');
     52     await expect(page.getByLabel('Output value')).toHaveText('24872.100');
     53   }
     54 
     55   // Reload page
     56   await page.reload();
     57 
     58   // Assert inputs are still loaded
     59   {
     60     // Assert time result is correct (state not reset)
     61     await expect(page.getByLabel('Selected unit category')).toHaveValue('time');
     62     await expect(page.getByLabel('Output value')).toHaveText('24872.100');
     63 
     64     // Assert distance result is correct (state not reset)
     65     await page.getByLabel('Selected unit category').selectOption('Distance');
     66     await expect(page.getByLabel('Output value')).toHaveText('3.107');
     67 
     68     // Assert speed & pace result is correct (state not reset)
     69     await page.getByLabel('Selected unit category').selectOption('Speed & Pace');
     70     await expect(page.getByLabel('Output value')).toHaveText('00:09:39.364');
     71   }
     72 });