App: filtr cwiczen w planie po sprzecie silowni na OR — cwiczenie z wieloma urzadzeniami (warianty typu guma lub TRX) widoczne, gdy silownia ma choc jedno z nich; pusta lista i BODYWEIGHT bez zmian, nowy test equipment.test.ts (app unit 259 przechodzi)
This commit is contained in:
@@ -132,14 +132,18 @@ export function formatGymEquipment(
|
||||
}
|
||||
|
||||
/**
|
||||
* Czy ćwiczenie można wykonać w danej siłowni: każde wymagane urządzenie
|
||||
* musi być w wyposażeniu siłowni. BODYWEIGHT (masa ciała) = bez sprzętu,
|
||||
* zawsze dostępne. Pusta lista urządzeń = ćwiczenie zawsze dostępne.
|
||||
* Czy ćwiczenie można wykonać w danej siłowni: wystarcza, że siłownia ma
|
||||
* choćby jedno z podłączonych urządzeń (wieloznaczność katalogu = warianty
|
||||
* typu „wyciąg lub brama"). BODYWEIGHT (masa ciała) = bez sprzętu, zawsze
|
||||
* dostępne. Pusta lista urządzeń = ćwiczenie zawsze dostępne.
|
||||
*/
|
||||
export function exerciseAvailableAtGym(
|
||||
exercise: { equipment?: Equipment[] },
|
||||
gym: { equipment?: GymEquipment[] },
|
||||
): boolean {
|
||||
const available = new Set((gym.equipment ?? []).map((ge) => ge.equipmentId));
|
||||
return (exercise.equipment ?? []).every((eq) => eq.kind === 'BODYWEIGHT' || available.has(eq.id));
|
||||
const required = exercise.equipment ?? [];
|
||||
return (
|
||||
required.length === 0 || required.some((eq) => eq.kind === 'BODYWEIGHT' || available.has(eq.id))
|
||||
);
|
||||
}
|
||||
|
||||
46
app/test/equipment.test.ts
Normal file
46
app/test/equipment.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { exerciseAvailableAtGym } from '../src/lib/equipment';
|
||||
import type { Equipment, EquipmentKind, GymEquipment } from '../src/api/types';
|
||||
|
||||
const eq = (id: string, kind: EquipmentKind = 'OTHER'): Equipment => ({
|
||||
id,
|
||||
name: id,
|
||||
kind,
|
||||
spec: null,
|
||||
description: null,
|
||||
});
|
||||
|
||||
const ge = (equipmentId: string): GymEquipment => ({
|
||||
id: `ge-${equipmentId}`,
|
||||
gymId: 'g1',
|
||||
equipmentId,
|
||||
quantity: 1,
|
||||
spec: null,
|
||||
equipment: eq(equipmentId),
|
||||
});
|
||||
|
||||
describe('exerciseAvailableAtGym', () => {
|
||||
it('is available when the exercise has no linked equipment', () => {
|
||||
expect(exerciseAvailableAtGym({ equipment: [] }, { equipment: [] })).toBe(true);
|
||||
expect(exerciseAvailableAtGym({}, { equipment: [ge('trx')] })).toBe(true);
|
||||
});
|
||||
|
||||
it('is available when the gym has at least one of the linked devices (variants)', () => {
|
||||
const facePull = { equipment: [eq('brama', 'CABLE'), eq('guma'), eq('trx')] };
|
||||
expect(exerciseAvailableAtGym(facePull, { equipment: [ge('guma')] })).toBe(true);
|
||||
expect(exerciseAvailableAtGym(facePull, { equipment: [ge('trx')] })).toBe(true);
|
||||
});
|
||||
|
||||
it('is unavailable when the gym has none of the linked devices', () => {
|
||||
const facePull = { equipment: [eq('brama', 'CABLE'), eq('guma'), eq('trx')] };
|
||||
expect(exerciseAvailableAtGym(facePull, { equipment: [ge('lawka'), ge('sztanga')] })).toBe(
|
||||
false,
|
||||
);
|
||||
expect(exerciseAvailableAtGym(facePull, { equipment: [] })).toBe(false);
|
||||
});
|
||||
|
||||
it('BODYWEIGHT device makes the exercise available regardless of gym equipment', () => {
|
||||
const dip = { equipment: [eq('pole', 'BODYWEIGHT'), eq('nieistnieje')] };
|
||||
expect(exerciseAvailableAtGym(dip, { equipment: [] })).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user