running-tools

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

targets.spec.js (2025B)


      1 import { describe, test, expect } from 'vitest';
      2 import * as targets from '@/core/targets';
      3 
      4 describe('sort method', () => {
      5   test('should correctly sort targets', () => {
      6     // Initialize unsorted and sorted targets
      7     const input = [
      8       { time: 60, type: 'time' },
      9       { distanceUnit: 'kilometers', distanceValue: 5, type: 'distance' },
     10       { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
     11     ];
     12     const expected = [
     13       { distanceUnit: 'miles', distanceValue: 3, type: 'distance' },
     14       { distanceUnit: 'kilometers', distanceValue: 5, type: 'distance' },
     15       { time: 60, type: 'time' },
     16     ];
     17 
     18     // Assert sort method sorts targets correctly
     19     expect(targets.sort(input)).to.deep.equal(expected);
     20   });
     21 });
     22 
     23 describe('workoutTargetToString method', () => {
     24   test('should correctly stringify time target', () => {
     25     // Initialize original and stringified target
     26     const input = {
     27       splitValue: 1600, splitUnit: 'meters',
     28       type: 'time', time: 3600,
     29     };
     30     const expected = '1600 m @ 1:00:00';
     31 
     32     // Assert sort method sorts targets correctly
     33     expect(targets.workoutTargetToString(input)).to.deep.equal(expected);
     34   });
     35 
     36   test('should correctly stringify distance target', () => {
     37     // Initialize original and stringified target
     38     const input = {
     39         splitValue: 800, splitUnit: 'meters',
     40         type: 'distance', distanceValue: 5, distanceUnit: 'kilometers',
     41     };
     42     const expected = '800 m @ 5 km';
     43 
     44     // Assert sort method sorts targets correctly
     45     expect(targets.workoutTargetToString(input)).to.deep.equal(expected);
     46   });
     47 
     48   test('should correctly stringify race target', () => {
     49     // Initialize original and stringified target
     50     const input = {
     51         splitValue: 5, splitUnit: 'kilometers',
     52         type: 'distance', distanceValue: 5, distanceUnit: 'kilometers',
     53     };
     54     const expected = '5 km';
     55 
     56     // Assert sort method sorts targets correctly
     57     expect(targets.workoutTargetToString(input)).to.deep.equal(expected);
     58   });
     59 });