41 lines
2.0 KiB
Dart
41 lines
2.0 KiB
Dart
import 'package:flutter/services.dart';
|
|||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:zenxercise/src/exercises/exercise_library.dart';
|
||
|
|
import 'package:zenxercise/src/modes/mode.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||
|
|
|
||
|
|
const json = '''[
|
||
|
|
{"id":"Calf_Stretch","name":"Calf Stretch","mode":"stretching","category":"stretching","level":"beginner",
|
||
|
|
"equipment":null,"force":"static","mechanic":null,"primaryMuscles":["calves"],"secondaryMuscles":[],
|
||
|
|
"instructions":["Lean forward."],"imageCount":2},
|
||
|
|
{"id":"Barbell_Squat","name":"Barbell Squat","mode":"workout","category":"strength","level":"intermediate",
|
||
|
|
"equipment":"barbell","force":"push","mechanic":"compound","primaryMuscles":["quadriceps"],
|
||
|
|
"secondaryMuscles":["glutes","hamstrings"],"instructions":["Squat."],"imageCount":0}
|
||
|
|
]''';
|
||
|
|
|
||
|
|
test('splits Exercises by Mode and finds them by id', () {
|
||
|
|
final library = ExerciseLibrary.fromJson(json);
|
||
|
|
|
||
|
|
expect(library.forMode(Mode.stretching).map((e) => e.id), ['Calf_Stretch']);
|
||
|
|
expect(library.forMode(Mode.workout).map((e) => e.id), ['Barbell_Squat']);
|
||
|
|
expect(library.byId('Barbell_Squat')!.secondaryMuscles, ['glutes', 'hamstrings']);
|
||
|
|
expect(library.byId('Missing'), isNull);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('an Exercise points at its flattened WebP images', () {
|
||
|
|
final calf = ExerciseLibrary.fromJson(json).byId('Calf_Stretch')!;
|
||
|
|
|
||
|
|
expect(calf.images, ['assets/exercises/images/Calf_Stretch_0.webp', 'assets/exercises/images/Calf_Stretch_1.webp']);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the bundled library holds 123 stretches and 753 workout Exercises whose images exist', () async {
|
||
|
|
final library = await ExerciseLibrary.load(rootBundle);
|
||
|
|
|
||
|
|
expect(library.forMode(Mode.stretching), hasLength(123));
|
||
|
|
expect(library.forMode(Mode.workout), hasLength(753));
|
||
|
|
final anyImage = library.forMode(Mode.stretching).firstWhere((e) => e.imageCount == 2).images.last;
|
||
|
|
expect((await rootBundle.load(anyImage)).lengthInBytes, greaterThan(0));
|
||
|
|
});
|
||
|
|
}
|