UNPKG

@sports-alliance/sports-lib

Version:

A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc

84 lines (83 loc) 4.59 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const xmldom_1 = require("@xmldom/xmldom"); const importer_tcx_1 = require("./importer.tcx"); const data_duration_1 = require("../../../../data/data.duration"); const data_elapsed_time_1 = require("../../../../data/data.elapsed-time"); const data_timer_time_1 = require("../../../../data/data.timer-time"); describe('EventImporterTCX duration policy', () => { it('keeps Duration as active timer time and exposes elapsed time separately', () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e; const tcxXml = ` <TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"> <Activities> <Activity Sport="Biking"> <Id>2026-01-01T10:00:00Z</Id> <Lap StartTime="2026-01-01T10:00:00Z"> <TotalTimeSeconds>100</TotalTimeSeconds> <DistanceMeters>1000</DistanceMeters> <Track> <Trackpoint> <Time>2026-01-01T10:00:00Z</Time> </Trackpoint> <Trackpoint> <Time>2026-01-01T10:02:10Z</Time> </Trackpoint> </Track> </Lap> </Activity> </Activities> </TrainingCenterDatabase> `; const parser = new xmldom_1.DOMParser(); const xmlDoc = parser.parseFromString(tcxXml, 'text/xml'); const event = yield importer_tcx_1.EventImporterTCX.getFromXML(xmlDoc); const activity = event.getFirstActivity(); expect((_a = activity.getStat(data_elapsed_time_1.DataElapsedTime.type)) === null || _a === void 0 ? void 0 : _a.getValue()).toBe(130); expect((_b = activity.getDuration()) === null || _b === void 0 ? void 0 : _b.getValue()).toBe(100); expect((_c = activity.getStat(data_timer_time_1.DataTimerTime.type)) === null || _c === void 0 ? void 0 : _c.getValue()).toBe(100); expect((_d = activity.getStat(data_duration_1.DataDuration.type)) === null || _d === void 0 ? void 0 : _d.getValue()).toBe(100); expect((_e = activity.getPause()) === null || _e === void 0 ? void 0 : _e.getValue()).toBe(30); })); it('falls back timer time to elapsed time when TotalTimeSeconds is missing', () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; const tcxXml = ` <TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"> <Activities> <Activity Sport="Biking"> <Id>2026-01-01T10:00:00Z</Id> <Lap StartTime="2026-01-01T10:00:00Z"> <DistanceMeters>1000</DistanceMeters> <Track> <Trackpoint> <Time>2026-01-01T10:00:00Z</Time> </Trackpoint> <Trackpoint> <Time>2026-01-01T10:01:30Z</Time> </Trackpoint> </Track> </Lap> </Activity> </Activities> </TrainingCenterDatabase> `; const parser = new xmldom_1.DOMParser(); const xmlDoc = parser.parseFromString(tcxXml, 'text/xml'); const event = yield importer_tcx_1.EventImporterTCX.getFromXML(xmlDoc); const activity = event.getFirstActivity(); expect(activity.getLaps().length).toBe(1); expect((_a = activity.getStat(data_elapsed_time_1.DataElapsedTime.type)) === null || _a === void 0 ? void 0 : _a.getValue()).toBe(90); expect((_b = activity.getDuration()) === null || _b === void 0 ? void 0 : _b.getValue()).toBe(90); expect((_c = activity.getStat(data_timer_time_1.DataTimerTime.type)) === null || _c === void 0 ? void 0 : _c.getValue()).toBe(90); expect((_d = activity.getPause()) === null || _d === void 0 ? void 0 : _d.getValue()).toBe(0); })); });