Workout Management tests done

This commit is contained in:
AG
2025-12-09 18:11:55 +02:00
parent f32661d892
commit 2352ac04d6
14 changed files with 557 additions and 67 deletions

View File

@@ -0,0 +1,53 @@
import { WorkoutSet, ExerciseType, Language } from '../types';
import { t } from '../services/i18n';
/**
* Formats a workout set's metrics into a standardized string.
* Format: "20 kg x 10 reps" or "300s / 1000m" depending on type.
* Ensures consistent delimiter usage and unit display.
*/
export const formatSetMetrics = (set: WorkoutSet, lang: Language): string => {
switch (set.type) {
case ExerciseType.STRENGTH:
return `${set.weight ? `${set.weight} kg` : ''} ${set.reps ? `x ${set.reps} ${t('reps', lang).toLowerCase()}` : ''}`.trim();
case ExerciseType.BODYWEIGHT:
case 'BODYWEIGHT': // Fallback for potential string type issues
// For bodyweight, format weight with sign if it exists, otherwise just BW
// If weight is undefined/null, standard active session logic used "BW" only in specific contexts,
// but let's standardize: if weight is 0 or undefined, maybe imply Bodyweight.
// Following ActiveSessionView logic: if weight is present, show it.
// Using signed logic: +10 kg, -10 kg
let weightStr = '';
if (set.weight !== undefined && set.weight !== null) {
weightStr = `${set.weight > 0 ? '+' : ''}${set.weight} kg`;
}
// If no weight is added, usually we just show reps.
// But History.tsx showed 'BW' if no weight. ActiveSessionView showed nothing.
// Let's stick to the richest information: if weight is set (even 0?), show it?
// Usually 0 added weight means just bodyweight.
// Let's mimic ActiveSessionView's concise approach but keep checks robust.
return `${weightStr} ${set.reps ? `x ${set.reps} ${t('reps', lang).toLowerCase()}` : ''}`.trim();
case ExerciseType.CARDIO:
return `${set.durationSeconds ? `${set.durationSeconds}s` : ''} ${set.distanceMeters ? `/ ${set.distanceMeters}m` : ''}`.trim();
case ExerciseType.STATIC:
return `${set.durationSeconds ? `${set.durationSeconds}s` : ''}`.trim();
case ExerciseType.HIGH_JUMP:
return `${set.height ? `${set.height}cm` : ''}`.trim();
case ExerciseType.LONG_JUMP:
return `${set.distanceMeters ? `${set.distanceMeters}m` : ''}`.trim();
case ExerciseType.PLYOMETRIC:
return `${set.reps ? `x ${set.reps} ${t('reps', lang).toLowerCase()}` : ''}`.trim();
default:
return '';
}
};