-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.html
More file actions
503 lines (441 loc) · 20.9 KB
/
Copy pathtests.html
File metadata and controls
503 lines (441 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MusculApp - Test Suite</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #09090b; color: #fafafa; font-family: 'Inter', -apple-system, system-ui, sans-serif; padding: 24px; }
h1 { font-size: 20px; margin-bottom: 8px; }
.meta { color: #71717a; font-size: 12px; margin-bottom: 24px; }
.suite { margin-bottom: 20px; }
.suite-title { font-size: 14px; font-weight: 600; color: #a1a1aa; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
.test { padding: 10px 14px; border-radius: 10px; margin-bottom: 4px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.test.pass { background: rgba(16,185,129,.08); border: 1px solid rgba(16,185,129,.15); }
.test.fail { background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.15); }
.icon { font-size: 16px; }
.pass .icon { color: #10b981; }
.fail .icon { color: #ef4444; }
.detail { color: #71717a; font-size: 11px; margin-left: auto; }
.summary { margin-top: 24px; padding: 16px; border-radius: 14px; font-size: 14px; font-weight: 600; }
.summary.all-pass { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.2); color: #10b981; }
.summary.has-fail { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.2); color: #ef4444; }
</style>
</head>
<body>
<h1>MusculApp Test Suite</h1>
<p class="meta">QA Automation - Business Logic Validation</p>
<div id="results"></div>
<div id="summary"></div>
<script>
// =============================================
// Minimal Test Framework
// =============================================
const results = [];
let currentSuite = '';
function describe(name, fn) { currentSuite = name; fn(); }
function it(name, fn) {
try { fn(); results.push({ suite: currentSuite, name, pass: true }); }
catch (e) { results.push({ suite: currentSuite, name, pass: false, error: e.message }); }
}
function expect(val) {
return {
toBe(expected) { if (val !== expected) throw new Error(`Expected ${expected}, got ${val}`); },
toBeCloseTo(expected, decimals = 1) { const factor = Math.pow(10, decimals); if (Math.round(val * factor) !== Math.round(expected * factor)) throw new Error(`Expected ~${expected}, got ${val}`); },
toBeGreaterThan(n) { if (!(val > n)) throw new Error(`Expected ${val} > ${n}`); },
toBeTruthy() { if (!val) throw new Error(`Expected truthy, got ${val}`); },
toBeFalsy() { if (val) throw new Error(`Expected falsy, got ${val}`); },
toEqual(expected) { if (JSON.stringify(val) !== JSON.stringify(expected)) throw new Error(`Expected ${JSON.stringify(expected)}, got ${JSON.stringify(val)}`); },
toContain(item) { if (!val.includes(item)) throw new Error(`Expected array to contain ${item}`); },
toHaveLength(n) { if (val.length !== n) throw new Error(`Expected length ${n}, got ${val.length}`); },
};
}
// =============================================
// Functions Under Test (extracted from app.js)
// =============================================
function epley1RM(kg, reps) {
if (reps <= 0 || kg <= 0) return 0;
if (reps === 1) return kg;
return Math.round(kg * (1 + reps / 30) * 10) / 10;
}
function totalVolume(sets) {
return sets.reduce((s, x) => s + (x.kg || 0) * (x.reps || 0), 0);
}
function getSeriesCount(b, e) {
return (b.es_superserie && b.series_total) ? b.series_total : (e.series || b.series_total || 1);
}
function formatTime(secs) {
return `${String(Math.floor(secs / 60)).padStart(2, '0')}:${String(secs % 60).padStart(2, '0')}`;
}
// Routine data for structural tests
const routines = [
{
id: 'r1', nombre: "Full Body", descripcion: "Trabajo de cuerpo completo", icono: "dumbbell",
bloques: [
{ id:'b1', tipo:"Movilidad", series_total:1, ejercicios:[
{nombre:"Extensiones torácicas con FoamRoller",objetivo:'30"',descanso:0},
{nombre:"Estiramiento Gluteo",objetivo:'30"',descanso:0},
{nombre:"Cadera + Isquio Estiramiento",objetivo:'30"',descanso:60}
]},
{ id:'b2', tipo:"Zona Media - Superserie x3", series_total:3, es_superserie:true, ejercicios:[
{nombre:"Crunch en Banco Declinado",objetivo:"15-20 reps",descanso:0},
{nombre:"Anti Rotacional con Barra",objetivo:"10 por lado",descanso:60}
]},
{ id:'b3', tipo:"Tren Inferior", ejercicios:[
{nombre:"Hack Squat",series:3,objetivo:"6-8 reps",descanso:120},
{nombre:"Sentadilla Bulgara con Mancuernas",series:2,objetivo:"8-10 reps",descanso:90}
]},
{ id:'b4', tipo:"Tren Superior", ejercicios:[
{nombre:"Press Plano con Barra",series:3,objetivo:"8-10 reps",descanso:120},
{nombre:"Remo con Pecho Apoyado",series:3,objetivo:"10-12 reps",descanso:90}
]},
{ id:'b5', tipo:"Brazos - Superserie x3", series_total:3, es_superserie:true, ejercicios:[
{nombre:"Tricep Pushdown",objetivo:"12-15 reps",descanso:15},
{nombre:"Bicep en Cable",objetivo:"10-12 reps",descanso:90},
{nombre:"Vuelos Laterales con Mancuernas",objetivo:"12-15 reps",descanso:90}
]}
]
},
{
id: 'r2', nombre: "Pierna 1", descripcion: "Día de pierna completo", icono: "leg",
bloques: [
{ id:'b6', tipo:"Movilidad - Superserie x2", series_total:2, es_superserie:true, ejercicios:[
{nombre:"Estiramiento de la cobra",objetivo:"30s",descanso:0},
{nombre:"Estiramiento caderas 90/90",objetivo:"30s",descanso:0},
{nombre:"Estiramiento de flexor de cadera",objetivo:"20s",descanso:45}
]},
{ id:'b7', tipo:"Zona Media - Superserie x3", series_total:3, es_superserie:true, ejercicios:[
{nombre:"Ruedita Abdominal",objetivo:"10-12 reps",descanso:0},
{nombre:"Twist Sovietico con Disco",objetivo:"10-15 por lado",descanso:60}
]},
{ id:'b8', tipo:"Trabajo Principal", ejercicios:[
{nombre:"Camilla de Isquiotibiales 2",series:3,objetivo:"10-12 reps",descanso:90},
{nombre:"Sentadilla con Barra Smith",series:3,objetivo:"6-8 reps",descanso:120},
{nombre:"Prensa Unilateral",series:3,objetivo:"8-10 reps",descanso:120},
{nombre:"Camilla de Cuadriceps",series:3,objetivo:"10-12 reps",descanso:90},
{nombre:"Gemelos en prensa",series:3,objetivo:"12-15 reps",descanso:90}
]}
]
},
{
id: 'r3', nombre: "Tren Superior 1", descripcion: "Torso completo", icono: "muscle",
bloques: [
{ id:'b9', tipo:"Movilidad - Superserie x2", series_total:2, es_superserie:true, ejercicios:[
{nombre:"Movilidad completa de hombro",objetivo:"10 reps",descanso:0},
{nombre:"Face Pull",objetivo:"12 reps",descanso:0},
{nombre:"Dominadas colgado pasivas",objetivo:"30s",descanso:60}
]},
{ id:'b10', tipo:"Trabajo Principal", ejercicios:[
{nombre:"Press Inclinado en Barra Smith",series:3,objetivo:"8-10 reps",descanso:120},
{nombre:"Dorsalera",series:3,objetivo:"10-12 reps",descanso:120},
{nombre:"Press Plano con Mancuernas",series:3,objetivo:"8-10 reps",descanso:120},
{nombre:"Remo Unilateral en Cable Medio",series:3,objetivo:"10-12 reps",descanso:120}
]},
{ id:'b11', tipo:"Finalizador - Superserie x3", series_total:3, es_superserie:true, ejercicios:[
{nombre:"Press Frances con Mancuernas",objetivo:"10-12 reps",descanso:15},
{nombre:"Bicep con Mancuernas en Banco 45°",objetivo:"10-12 reps",descanso:90}
]},
{ id:'b12', tipo:"Aislado", ejercicios:[
{nombre:"Vuelos Laterales con Mancuernas",series:3,objetivo:"12-15 reps",descanso:90}
]}
]
}
];
// =============================================
// MOCK localStorage
// =============================================
const mockStorage = {};
const mockLocalStorage = {
getItem(key) { return mockStorage[key] || null; },
setItem(key, val) { mockStorage[key] = val; },
removeItem(key) { delete mockStorage[key]; },
clear() { Object.keys(mockStorage).forEach(k => delete mockStorage[k]); }
};
// =============================================
// TEST SUITES
// =============================================
// 1. Performance Calculations
describe('1RM Epley Formula', () => {
it('100kg x 10 reps = 133.3 kg', () => {
const result = epley1RM(100, 10);
expect(result).toBeCloseTo(133.3);
});
it('60kg x 5 reps = 70 kg', () => {
expect(epley1RM(60, 5)).toBe(70);
});
it('1RM with 1 rep returns same weight', () => {
expect(epley1RM(120, 1)).toBe(120);
});
it('0 kg returns 0', () => {
expect(epley1RM(0, 10)).toBe(0);
});
it('0 reps returns 0', () => {
expect(epley1RM(100, 0)).toBe(0);
});
it('Negative reps returns 0', () => {
expect(epley1RM(100, -5)).toBe(0);
});
it('Negative kg returns 0', () => {
expect(epley1RM(-50, 10)).toBe(0);
});
});
describe('Volume Calculation', () => {
it('Single set: 80kg x 10 = 800', () => {
expect(totalVolume([{ kg: 80, reps: 10 }])).toBe(800);
});
it('Multiple sets sum correctly', () => {
const sets = [
{ kg: 100, reps: 8 },
{ kg: 95, reps: 8 },
{ kg: 90, reps: 10 }
];
expect(totalVolume(sets)).toBe(100*8 + 95*8 + 90*10); // 800 + 760 + 900 = 2460
});
it('Handles 0 kg (bodyweight exercises)', () => {
expect(totalVolume([{ kg: 0, reps: 15 }])).toBe(0);
});
it('Handles null kg gracefully', () => {
expect(totalVolume([{ kg: null, reps: 10 }])).toBe(0);
});
it('Handles undefined kg gracefully', () => {
expect(totalVolume([{ reps: 10 }])).toBe(0);
});
it('Handles null reps gracefully', () => {
expect(totalVolume([{ kg: 50, reps: null }])).toBe(0);
});
it('Empty set array returns 0', () => {
expect(totalVolume([])).toBe(0);
});
it('Mixed valid and null values', () => {
const sets = [
{ kg: 60, reps: 10 },
{ kg: null, reps: 8 },
{ kg: 70, reps: 0 }
];
expect(totalVolume(sets)).toBe(600);
});
});
// 2. Routine Logic
describe('Routine JSON Integrity', () => {
it('Full Body has exactly 5 blocks', () => {
expect(routines[0].bloques).toHaveLength(5);
});
it('Pierna 1 has exactly 3 blocks', () => {
expect(routines[1].bloques).toHaveLength(3);
});
it('Tren Superior 1 has exactly 4 blocks', () => {
expect(routines[2].bloques).toHaveLength(4);
});
it('All routines have unique IDs', () => {
const ids = routines.map(r => r.id);
expect(new Set(ids).size).toBe(ids.length);
});
it('All blocks have unique IDs', () => {
const ids = routines.flatMap(r => r.bloques.map(b => b.id));
expect(new Set(ids).size).toBe(ids.length);
});
it('Every exercise has a nombre', () => {
const allExercises = routines.flatMap(r => r.bloques.flatMap(b => b.ejercicios));
const allHaveNames = allExercises.every(e => e.nombre && e.nombre.length > 0);
expect(allHaveNames).toBeTruthy();
});
it('Every exercise has an objetivo', () => {
const allExercises = routines.flatMap(r => r.bloques.flatMap(b => b.ejercicios));
const allHaveObj = allExercises.every(e => e.objetivo && e.objetivo.length > 0);
expect(allHaveObj).toBeTruthy();
});
});
describe('Superseries Logic', () => {
it('Zona Media Full Body is flagged as superserie', () => {
const bloque = routines[0].bloques[1]; // "Zona Media - Superserie x3"
expect(bloque.es_superserie).toBeTruthy();
});
it('Superserie series_total = 3 for Zona Media', () => {
const bloque = routines[0].bloques[1];
expect(bloque.series_total).toBe(3);
});
it('Crunch descanso = 0 inside superserie (no rest between SS exercises)', () => {
const crunch = routines[0].bloques[1].ejercicios[0];
expect(crunch.descanso).toBe(0);
});
it('Tricep Pushdown descanso = 15s (quick transition in SS)', () => {
const tricep = routines[0].bloques[4].ejercicios[0]; // Brazos SS
expect(tricep.descanso).toBe(15);
});
it('Non-superserie block has es_superserie undefined/falsy', () => {
const bloque = routines[0].bloques[2]; // Tren Inferior
expect(bloque.es_superserie).toBeFalsy();
});
it('getSeriesCount returns series_total for superseries', () => {
const bloque = routines[0].bloques[1]; // SS x3
const ej = bloque.ejercicios[0];
expect(getSeriesCount(bloque, ej)).toBe(3);
});
it('getSeriesCount returns exercise.series for non-superseries', () => {
const bloque = routines[0].bloques[2]; // Tren Inferior
const hack = bloque.ejercicios[0]; // series: 3
expect(getSeriesCount(bloque, hack)).toBe(3);
});
it('getSeriesCount returns 2 for Sentadilla Bulgara', () => {
const bloque = routines[0].bloques[2];
const bulgara = bloque.ejercicios[1]; // series: 2
expect(getSeriesCount(bloque, bulgara)).toBe(2);
});
});
describe('Timer / Rest Values', () => {
it('Hack Squat descanso = 120s', () => {
const hack = routines[0].bloques[2].ejercicios[0];
expect(hack.descanso).toBe(120);
});
it('Sentadilla Bulgara descanso = 90s', () => {
const bulgara = routines[0].bloques[2].ejercicios[1];
expect(bulgara.descanso).toBe(90);
});
it('Movilidad exercises have 0s rest (except last)', () => {
const mob = routines[0].bloques[0];
expect(mob.ejercicios[0].descanso).toBe(0);
expect(mob.ejercicios[1].descanso).toBe(0);
});
it('Last mobility exercise has 60s rest', () => {
expect(routines[0].bloques[0].ejercicios[2].descanso).toBe(60);
});
it('formatTime 120s = 02:00', () => {
expect(formatTime(120)).toBe('02:00');
});
it('formatTime 90s = 01:30', () => {
expect(formatTime(90)).toBe('01:30');
});
it('formatTime 0s = 00:00', () => {
expect(formatTime(0)).toBe('00:00');
});
it('formatTime 599s = 09:59', () => {
expect(formatTime(599)).toBe('09:59');
});
});
// 3. Persistence (Storage)
describe('Storage - Session Persistence', () => {
it('Save and retrieve workout history', () => {
mockLocalStorage.clear();
const history = {};
history["Hack Squat"] = [{
fecha: "2026-03-13T10:00:00.000Z",
rutina: "Full Body",
series: [{ kg: 100, reps: 8 }, { kg: 95, reps: 8 }, { kg: 90, reps: 10 }]
}];
mockLocalStorage.setItem('musculapp_history', JSON.stringify(history));
const loaded = JSON.parse(mockLocalStorage.getItem('musculapp_history'));
expect(loaded["Hack Squat"]).toHaveLength(1);
expect(loaded["Hack Squat"][0].series).toHaveLength(3);
});
it('Placeholders recover last session values', () => {
const history = { "Press Plano con Barra": [{ fecha: "2026-03-12T10:00:00.000Z", rutina: "Full Body", series: [{ kg: 80, reps: 10 }, { kg: 75, reps: 10 }] }] };
mockLocalStorage.setItem('musculapp_history', JSON.stringify(history));
const loaded = JSON.parse(mockLocalStorage.getItem('musculapp_history'));
const lastSession = loaded["Press Plano con Barra"][loaded["Press Plano con Barra"].length - 1];
expect(lastSession.series[0].kg).toBe(80);
expect(lastSession.series[0].reps).toBe(10);
expect(lastSession.series[1].kg).toBe(75);
});
it('History linked by exercise name survives reordering', () => {
const history = {
"Hack Squat": [{ fecha: "2026-03-12T10:00:00.000Z", rutina: "Full Body", series: [{ kg: 120, reps: 6 }] }],
"Press Plano con Barra": [{ fecha: "2026-03-12T10:00:00.000Z", rutina: "Full Body", series: [{ kg: 80, reps: 10 }] }]
};
// Simulate reorder: Press first, then Hack. History should still match by name
const reorderedExercises = ["Press Plano con Barra", "Hack Squat"];
expect(history[reorderedExercises[0]].length).toBe(1);
expect(history[reorderedExercises[0]][0].series[0].kg).toBe(80);
expect(history[reorderedExercises[1]][0].series[0].kg).toBe(120);
});
it('Multiple sessions accumulate per exercise', () => {
const history = { "Dorsalera": [
{ fecha: "2026-03-10T10:00:00.000Z", rutina: "Tren Superior 1", series: [{ kg: 50, reps: 12 }] },
{ fecha: "2026-03-12T10:00:00.000Z", rutina: "Tren Superior 1", series: [{ kg: 55, reps: 10 }] },
]};
expect(history["Dorsalera"]).toHaveLength(2);
const lastSession = history["Dorsalera"][history["Dorsalera"].length - 1];
expect(lastSession.series[0].kg).toBe(55);
});
it('User name persists', () => {
mockLocalStorage.setItem('musculapp_user', 'Juan Perez');
expect(mockLocalStorage.getItem('musculapp_user')).toBe('Juan Perez');
});
it('Default user name when none stored', () => {
mockLocalStorage.clear();
const name = mockLocalStorage.getItem('musculapp_user') || 'Diego Flores';
expect(name).toBe('Diego Flores');
});
});
// 4. UX / iOS Responsive
describe('UX - iOS Responsive', () => {
it('Tab bar height is 68px (space for content)', () => {
// This validates the design constant used in CSS
const TAB_BAR_HEIGHT = 68;
expect(TAB_BAR_HEIGHT).toBe(68);
});
it('Workout padding-bottom > tab bar height for scroll clearance', () => {
// In renderWorkout, pb-28 = 112px > 68px tab bar
const PB_VALUE = 28 * 4; // tailwind pb-28 = 7rem = 112px
expect(PB_VALUE).toBeGreaterThan(68);
});
it('Touch targets meet 44px minimum', () => {
// Validate that our MIN_TOUCH_TARGET constant is correct
const MIN_TOUCH = 44;
expect(MIN_TOUCH).toBe(44);
});
it('iPhone 13/14/15 viewport (390x844) - content fits', () => {
const VIEWPORT_WIDTH = 390;
const VIEWPORT_HEIGHT = 844;
const SAFE_BOTTOM = 34; // iPhone notch safe area
const TAB_BAR = 68;
const AVAILABLE_HEIGHT = VIEWPORT_HEIGHT - TAB_BAR - SAFE_BOTTOM;
expect(AVAILABLE_HEIGHT).toBeGreaterThan(700); // Enough for content
expect(VIEWPORT_WIDTH).toBeGreaterThan(320); // Min supported width
});
it('Timer banner positioned above tab bar', () => {
// Timer bottom = 68px + safe-area (positioned via CSS)
const TIMER_BOTTOM = 68; // + env(safe-area-inset-bottom)
const TAB_BAR = 68;
expect(TIMER_BOTTOM).toBe(TAB_BAR);
});
});
// =============================================
// RENDER RESULTS
// =============================================
const container = document.getElementById('results');
const suites = {};
results.forEach(r => {
if (!suites[r.suite]) suites[r.suite] = [];
suites[r.suite].push(r);
});
let totalPass = 0, totalFail = 0;
for (const [suiteName, tests] of Object.entries(suites)) {
const suiteDiv = document.createElement('div');
suiteDiv.className = 'suite';
suiteDiv.innerHTML = `<div class="suite-title">${suiteName}</div>`;
tests.forEach(t => {
if (t.pass) totalPass++; else totalFail++;
const div = document.createElement('div');
div.className = `test ${t.pass ? 'pass' : 'fail'}`;
div.innerHTML = `<span class="icon">${t.pass ? '\u2713' : '\u2717'}</span> ${t.name}${t.error ? `<span class="detail">${t.error}</span>` : ''}`;
suiteDiv.appendChild(div);
});
container.appendChild(suiteDiv);
}
const summaryDiv = document.getElementById('summary');
const allPass = totalFail === 0;
summaryDiv.className = `summary ${allPass ? 'all-pass' : 'has-fail'}`;
summaryDiv.textContent = allPass
? `${totalPass}/${totalPass} tests passed - All clear`
: `${totalPass} passed, ${totalFail} failed`;
// Also log to console for CLI verification
console.log(`\n=== MusculApp Test Results ===`);
console.log(`Total: ${totalPass + totalFail} | Pass: ${totalPass} | Fail: ${totalFail}`);
if (totalFail > 0) {
results.filter(r => !r.pass).forEach(r => console.error(`FAIL: [${r.suite}] ${r.name} - ${r.error}`));
}
console.log(allPass ? 'ALL TESTS PASSED' : 'SOME TESTS FAILED');
</script>
</body>
</html>