2026-10-28 23:33:07 +01:00
|
|
|
|
import 'package:flutter/widgets.dart';
|
2026-10-28 23:18:03 +01:00
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
import 'package:zenxercise/src/app.dart';
|
|
|
|
|
|
import 'package:zenxercise/src/exercises/exercise.dart';
|
|
|
|
|
|
import 'package:zenxercise/src/exercises/exercise_library.dart';
|
|
|
|
|
|
import 'package:zenxercise/src/modes/mode.dart';
|
2026-10-28 23:48:07 +01:00
|
|
|
|
import 'package:zenxercise/src/plans/plan_repository.dart';
|
2026-10-28 23:18:03 +01:00
|
|
|
|
import 'package:zenxercise/src/settings/settings_controller.dart';
|
|
|
|
|
|
|
2026-10-28 23:48:07 +01:00
|
|
|
|
import 'test_database.dart';
|
|
|
|
|
|
|
2026-10-28 23:33:07 +01:00
|
|
|
|
Exercise exercise(
|
|
|
|
|
|
String id,
|
|
|
|
|
|
Mode mode, {
|
|
|
|
|
|
String? name,
|
|
|
|
|
|
List<String> primary = const ['hamstrings'],
|
|
|
|
|
|
List<String> secondary = const [],
|
|
|
|
|
|
String? equipment = 'body only',
|
|
|
|
|
|
String level = 'beginner',
|
|
|
|
|
|
List<String> instructions = const ['Breathe.'],
|
|
|
|
|
|
int imageCount = 0,
|
|
|
|
|
|
}) => Exercise(
|
2026-10-28 23:18:03 +01:00
|
|
|
|
id: id,
|
|
|
|
|
|
name: name ?? id.replaceAll('_', ' '),
|
|
|
|
|
|
mode: mode,
|
|
|
|
|
|
category: mode == Mode.stretching ? 'stretching' : 'strength',
|
2026-10-28 23:33:07 +01:00
|
|
|
|
level: level,
|
|
|
|
|
|
equipment: equipment,
|
|
|
|
|
|
primaryMuscles: primary,
|
|
|
|
|
|
secondaryMuscles: secondary,
|
|
|
|
|
|
instructions: instructions,
|
2026-10-28 23:18:03 +01:00
|
|
|
|
imageCount: imageCount,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-10-28 23:33:07 +01:00
|
|
|
|
/// Two stretches and a squat. The 90/90 Hamstring's images exist in the real assets.
|
2026-10-28 23:18:03 +01:00
|
|
|
|
final sampleLibrary = ExerciseLibrary([
|
2026-10-28 23:33:07 +01:00
|
|
|
|
exercise(
|
|
|
|
|
|
'90_90_Hamstring',
|
|
|
|
|
|
Mode.stretching,
|
|
|
|
|
|
name: '90/90 Hamstring',
|
|
|
|
|
|
secondary: const ['calves'],
|
|
|
|
|
|
instructions: const ['Lie on your back.', 'Straighten one leg.'],
|
|
|
|
|
|
imageCount: 2,
|
|
|
|
|
|
),
|
|
|
|
|
|
exercise('Calf_Stretch', Mode.stretching, primary: const ['calves'], equipment: 'other', level: 'intermediate'),
|
|
|
|
|
|
exercise('Barbell_Squat', Mode.workout, primary: const ['quadriceps'], equipment: 'barbell'),
|
2026-10-28 23:18:03 +01:00
|
|
|
|
]);
|
|
|
|
|
|
|
2026-10-28 23:33:07 +01:00
|
|
|
|
/// A Pixel-sized screen instead of the default 800×600, so the floating
|
|
|
|
|
|
/// navigation bar does not cover what a test taps.
|
|
|
|
|
|
void usePhoneScreen(WidgetTester tester) {
|
|
|
|
|
|
tester.view.physicalSize = const Size(1080, 2400);
|
|
|
|
|
|
tester.view.devicePixelRatio = 2.75;
|
|
|
|
|
|
addTearDown(tester.view.reset);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-28 23:18:03 +01:00
|
|
|
|
/// The whole app over [library], with preferences starting from [prefs].
|
|
|
|
|
|
Future<SettingsController> pumpApp(
|
|
|
|
|
|
WidgetTester tester, {
|
|
|
|
|
|
ExerciseLibrary? library,
|
|
|
|
|
|
Map<String, Object> prefs = const {},
|
2026-10-28 23:48:07 +01:00
|
|
|
|
PlanRepository? plans,
|
2026-10-28 23:18:03 +01:00
|
|
|
|
}) async {
|
|
|
|
|
|
SharedPreferences.setMockInitialValues(prefs);
|
|
|
|
|
|
final settings = SettingsController(SettingsService());
|
|
|
|
|
|
await settings.loadSettings();
|
2026-10-28 23:48:07 +01:00
|
|
|
|
final db = testDatabase();
|
|
|
|
|
|
addTearDown(db.close);
|
2026-10-28 23:18:03 +01:00
|
|
|
|
await tester.pumpWidget(
|
|
|
|
|
|
MultiProvider(
|
|
|
|
|
|
providers: [
|
|
|
|
|
|
ChangeNotifierProvider.value(value: settings),
|
|
|
|
|
|
Provider.value(value: library ?? sampleLibrary),
|
2026-10-28 23:48:07 +01:00
|
|
|
|
Provider.value(value: plans ?? PlanRepository(db)),
|
2026-10-28 23:18:03 +01:00
|
|
|
|
],
|
|
|
|
|
|
child: const ZenXerciseApp(),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
return settings;
|
|
|
|
|
|
}
|