diff --git a/TESTING.md b/TESTING.md index 5d61c6e..231fe77 100644 --- a/TESTING.md +++ b/TESTING.md @@ -2,7 +2,59 @@ This guide explains how to test different workouts and training blocks without manually progressing through the entire program. -## Testing Different Workouts via IndexedDB +## Testing Different Workouts via URL Parameters (Recommended) + +The easiest way to test different workouts is by using URL parameters. Simply navigate to the `/workout` route with the following query parameters: + +- `block` - The block type (e.g., `endurance1`, `powerbuilding1`, `powerbuilding3`) +- `week` - The week number (1-based) +- `day` - The day number (1-based, 1-7 for each week) + +### Examples: + +**Test LISS workout:** +``` +http://localhost:5173/workout?block=endurance1&week=1&day=2 +``` +Shows: LISS run for 60 minutes + +**Test HIIT workout:** +``` +http://localhost:5173/workout?block=powerbuilding3&week=1&day=3 +``` +Shows: Reset-20 HIIT with 20 seconds, 5 rounds + +**Test different HIIT variation:** +``` +http://localhost:5173/workout?block=powerbuilding3&week=2&day=3 +``` +Shows: Reset-20 HIIT with 15 seconds, 4 rounds + +**Test strength workout:** +``` +http://localhost:5173/workout?block=powerbuilding1&week=1&day=1 +``` +Shows: Bench Press and Squat strength workout + +### Available Block Types: +- `getready` - Get Ready block (mostly rest days) +- `endurance1` - Endurance Block 1 (strength + LISS cardio) +- `powerbuilding1` - Powerbuilding Block 1 (strength + LISS) +- `powerbuilding2` - Powerbuilding Block 2 (strength + hypertrophy + LISS) +- `powerbuilding3` - Powerbuilding Block 3 (strength + hypertrophy + HIIT) +- `bodybuilding1` - Bodybuilding Block (hypertrophy + HIIT) +- `strength1` - Strength Block (strength + HIIT) + +### Notes: +- Parameters override the stored workout state, but don't modify it permanently +- If you navigate away and come back to `/workout` without parameters, it will return to the stored state +- Parameters are case-sensitive +- If an invalid block type is provided, the app will still attempt to load the workout (useful for testing new block types) +- All three parameters are optional - you can use any combination + +## Testing Different Workouts via IndexedDB (Alternative Method) + +For advanced testing scenarios or when you need to persist changes, you can modify IndexedDB directly. The app stores workout progress in IndexedDB, which can be modified directly in the browser to test different workout types (HIIT, LISS, strength, etc.) without completing entire blocks. @@ -160,19 +212,46 @@ You can also modify the workout state programmatically using the browser console ## Quick Testing Scenarios ### Test HIIT Timer Functionality -1. Set `currentWeek: 1, currentDay: 3` (Powerbuilding Block 3) -2. Refresh page and start workout -3. Test round progression, pause/resume, reset functionality +**Via URL (recommended):** +``` +http://localhost:5173/workout?block=powerbuilding3&week=1&day=3 +``` +**Via IndexedDB:** Set `currentWeek: 1, currentDay: 3` (Powerbuilding Block 3) + +Test round progression, pause/resume, reset functionality ### Test LISS Timer Functionality -1. Set `currentWeek: 1, currentDay: 2` (Endurance Block 1) -2. Refresh page and start workout -3. Test timer countdown, pause/resume functionality +**Via URL (recommended):** +``` +http://localhost:5173/workout?block=endurance1&week=1&day=2 +``` +**Via IndexedDB:** Set `currentWeek: 1, currentDay: 2` (Endurance Block 1) + +Test timer countdown, pause/resume functionality ### Test Different HIIT Variations -1. **Short rounds:** Set to Powerbuilding Block 3, Week 2/3 (15s rounds) -2. **Longer rounds:** Set to Powerbuilding Block 3, Week 1 (20s rounds) -3. **Different activities:** Set to Strength Block for "Tempo Run" or "600m Resets" +**Short rounds (15s):** +``` +http://localhost:5173/workout?block=powerbuilding3&week=2&day=3 +``` + +**Longer rounds (20s):** +``` +http://localhost:5173/workout?block=powerbuilding3&week=1&day=3 +``` + +**Different activities:** Use various blocks like `strength1` for different HIIT exercises + +### Test Strength Workouts +**Simple strength workout:** +``` +http://localhost:5173/workout?block=powerbuilding1&week=1&day=1 +``` + +**Complex strength workout:** +``` +http://localhost:5173/workout?block=powerbuilding2&week=1&day=1 +``` ## Reset Progress for Clean Testing @@ -204,7 +283,9 @@ To start fresh testing: ## Notes -- Always refresh the page after modifying IndexedDB data +- **URL parameter testing is the recommended approach** - no IndexedDB modification needed +- URL parameters override stored values temporarily without modifying the database +- Always refresh the page after modifying IndexedDB data (only needed for IndexedDB method) - The app will automatically load the new state on page refresh - Component-level timer state (HIIT/LISS timers) resets automatically when components re-render - Workout state persistence only applies to training progression, not UI timer state diff --git a/src/routes/workout/+page.ts b/src/routes/workout/+page.ts index 00022ed..3b901ae 100644 --- a/src/routes/workout/+page.ts +++ b/src/routes/workout/+page.ts @@ -2,14 +2,19 @@ import type { PageLoad } from './$types' import { browser } from '$app/environment' import { get } from 'svelte/store' -export const load: PageLoad = async ({ fetch }) => { +export const load: PageLoad = async ({ fetch, url }) => { + // Extract URL parameters for testing + const blockParam = url.searchParams.get('block') + const weekParam = url.searchParams.get('week') + const dayParam = url.searchParams.get('day') + // Return default data during SSR/build time if (!browser) { return { getCurrentWorkout: null, currentBlockInfo: { name: 'Loading...', weeks: 0 }, - currentWeek: 1, - currentDay: 1 + currentWeek: weekParam ? parseInt(weekParam) : 1, + currentDay: dayParam ? parseInt(dayParam) : 1 } } @@ -20,45 +25,57 @@ export const load: PageLoad = async ({ fetch }) => { // Get current state from stores const workoutState = get(workoutStore) const trainingState = get(trainingPlanStore) - const currentBlock = trainingState.customPlan[0] + + // Use URL parameters to override store values if provided + const currentWeek = weekParam ? parseInt(weekParam) : workoutState.currentWeek + const currentDay = dayParam ? parseInt(dayParam) : workoutState.currentDay + + // Determine the block to use + let currentBlock + if (blockParam) { + // If block parameter is provided, try to find it in the training plan or use it directly + const foundBlock = trainingState.customPlan.find(block => + block.type === blockParam || block.name === blockParam + ) + if (foundBlock) { + currentBlock = foundBlock + } else { + // If not found in custom plan, create a temporary block for testing + currentBlock = { name: blockParam, weeks: 12, type: blockParam } + } + } else { + // Use the first block from the training plan as before + currentBlock = trainingState.customPlan[0] + } if (!currentBlock) { return { getCurrentWorkout: null, currentBlockInfo: { name: 'No active block', weeks: 0 }, - currentWeek: workoutState.currentWeek, - currentDay: workoutState.currentDay + currentWeek, + currentDay } } - // Fetch current workout data from API with client state + // Fetch current workout data from API with the determined parameters const currentWorkoutResponse = await fetch( - `/api/workout/current?blockType=${encodeURIComponent(currentBlock.type)}¤tWeek=${workoutState.currentWeek}¤tDay=${workoutState.currentDay}` + `/api/workout/current?blockType=${encodeURIComponent(currentBlock.type)}¤tWeek=${currentWeek}¤tDay=${currentDay}` ) const getCurrentWorkout = await currentWorkoutResponse.json() - // We could prepare state data for API calls if needed in the future - // const stateParams = new URLSearchParams({ - // currentWeek: workoutState.currentWeek.toString(), - // currentDay: workoutState.currentDay.toString(), - // blockName: currentBlock.name, - // completedWorkouts: JSON.stringify(workoutState.completedWorkouts), - // completedSets: JSON.stringify(workoutState.completedSets) - // }) - return { getCurrentWorkout, currentBlockInfo: { name: currentBlock.name, weeks: currentBlock.weeks }, - currentWeek: workoutState.currentWeek, - currentDay: workoutState.currentDay + currentWeek, + currentDay } } catch (error) { console.error('Error loading workout data:', error) return { getCurrentWorkout: null, currentBlockInfo: { name: 'Error loading', weeks: 0 }, - currentWeek: 1, - currentDay: 1 + currentWeek: weekParam ? parseInt(weekParam) : 1, + currentDay: dayParam ? parseInt(dayParam) : 1 } } } \ No newline at end of file