mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 22:16:26 +00:00
fix(tours): preset a ski tour's actual track as ski, and cover the run and ride presets
Ski has been an importable type since SKI-02, yet a ski tour's recording still opened in the GPX preview as a hike. It now opens as ski with the tour's discipline, and its technique for cross-country. The run profile fallback and the ride preset get their tests.
This commit is contained in:
@@ -120,6 +120,26 @@ describe('the GPX preset', () => {
|
||||
});
|
||||
expect(importFieldsFor(tour({ tour_type: 'walk' }))).toEqual({ tour_type: 'walk' });
|
||||
expect(importFieldsFor(tour({ tour_type: 'ski' }))).toEqual({ tour_type: 'hike' });
|
||||
expect(importFieldsFor(tour({ tour_type: 'ski', ski_discipline: 'touring', ski_technique: null }))).toEqual({
|
||||
tour_type: 'ski',
|
||||
ski_discipline: 'touring',
|
||||
});
|
||||
const skating = { tour_type: 'ski', ski_discipline: 'cross_country', ski_technique: 'skating' } as const;
|
||||
expect(importFieldsFor(tour(skating))).toEqual(skating);
|
||||
expect(importFieldsFor(tour({ tour_type: 'ski', ski_discipline: 'cross_country', ski_technique: null }))).toEqual({
|
||||
tour_type: 'ski',
|
||||
ski_discipline: 'cross_country',
|
||||
ski_technique: 'unknown',
|
||||
});
|
||||
expect(importFieldsFor(tour({ tour_type: 'run', run_profile: 'trail' }))).toEqual({
|
||||
tour_type: 'run',
|
||||
run_profile: 'trail',
|
||||
});
|
||||
expect(importFieldsFor(tour({ tour_type: 'run', run_profile: null }))).toEqual({
|
||||
tour_type: 'run',
|
||||
run_profile: 'running',
|
||||
});
|
||||
expect(importFieldsFor(tour({ tour_type: 'horse' }))).toEqual({ tour_type: 'horse' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -80,15 +80,24 @@ export function trackCandidates(tours: readonly TourListItem[], placeId: number)
|
||||
|
||||
/**
|
||||
* The type a recording of this tour is imported as, preset in the GPX
|
||||
* preview: the tour's own, with its bike or run profile or its boat and water where
|
||||
* it has them. A type the import does not offer starts as a hike, as the
|
||||
* preview always did.
|
||||
* preview: the tour's own, with its bike or run profile, its boat and water,
|
||||
* or its ski discipline and technique where it has them. A type the import
|
||||
* does not offer, and a ski tour without a discipline (which the import
|
||||
* refuses for ski), starts as a hike, as the preview always did.
|
||||
*/
|
||||
export function importFieldsFor(
|
||||
tour: Pick<TourListItem, 'tour_type' | 'bike_profile' | 'boat_type' | 'water_context'> &
|
||||
Partial<Pick<TourListItem, 'run_profile'>>
|
||||
Partial<Pick<TourListItem, 'run_profile' | 'ski_discipline' | 'ski_technique'>>
|
||||
): TourGpxImportFields {
|
||||
switch (tour.tour_type) {
|
||||
case 'ski':
|
||||
if (!tour.ski_discipline) return { tour_type: 'hike' };
|
||||
return {
|
||||
tour_type: 'ski',
|
||||
ski_discipline: tour.ski_discipline,
|
||||
// Only cross-country is done in a technique; unknown when the travellers did not know it.
|
||||
...(tour.ski_discipline === 'cross_country' ? { ski_technique: tour.ski_technique ?? 'unknown' } : {}),
|
||||
};
|
||||
case 'bike':
|
||||
return { tour_type: 'bike', bike_profile: tour.bike_profile ?? 'touring' };
|
||||
case 'run':
|
||||
|
||||
Reference in New Issue
Block a user