mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Create the gym mode and log screen mocks per test
This commit is contained in:
@@ -31,10 +31,12 @@ import 'package:wger/core/network/network_provider.dart';
|
||||
import 'package:wger/core/shared_preferences.dart';
|
||||
import 'package:wger/core/widgets/error.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/exercises/providers/exercise_repository.dart';
|
||||
import 'package:wger/features/exercises/providers/exercises_notifier.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/repetition_unit.dart';
|
||||
import 'package:wger/features/routines/models/routine.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
import 'package:wger/features/routines/models/weight_unit.dart';
|
||||
import 'package:wger/features/routines/notifications/workout_notification_controller.dart';
|
||||
@@ -76,18 +78,27 @@ void main() {
|
||||
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
|
||||
final testRoutine = getTestRoutine();
|
||||
final testExercises = getTestExercises();
|
||||
// Fresh per test: gym mode mutates the routine it runs, and a shared mock
|
||||
// carries stubs and recorded calls into whichever test runs next
|
||||
late Routine testRoutine;
|
||||
late List<Exercise> testExercises;
|
||||
|
||||
final mockSessionRepo = MockWorkoutSessionRepository();
|
||||
final mockExerciseRepo = MockExerciseRepository();
|
||||
final mockRoutinesRepo = MockRoutinesRepository();
|
||||
final mockLogRepo = MockWorkoutLogRepository();
|
||||
final mockUserProfileRepo = MockUserProfileRepository();
|
||||
late MockWorkoutSessionRepository mockSessionRepo;
|
||||
late MockExerciseRepository mockExerciseRepo;
|
||||
late MockRoutinesRepository mockRoutinesRepo;
|
||||
late MockWorkoutLogRepository mockLogRepo;
|
||||
late MockUserProfileRepository mockUserProfileRepo;
|
||||
late MockWorkoutNotificationService mockNotificationService;
|
||||
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty();
|
||||
testRoutine = getTestRoutine();
|
||||
testExercises = getTestExercises();
|
||||
mockSessionRepo = MockWorkoutSessionRepository();
|
||||
mockExerciseRepo = MockExerciseRepository();
|
||||
mockRoutinesRepo = MockRoutinesRepository();
|
||||
mockLogRepo = MockWorkoutLogRepository();
|
||||
mockUserProfileRepo = MockUserProfileRepository();
|
||||
mockNotificationService = MockWorkoutNotificationService();
|
||||
when(mockNotificationService.supportsControls).thenReturn(true);
|
||||
when(mockNotificationService.requestPermissions(any)).thenAnswer((_) async {});
|
||||
@@ -393,10 +404,6 @@ void main() {
|
||||
container.listen(routinesRiverpodProvider, (_, _) {});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The mock is shared across tests; only the gym-mode open below must
|
||||
// stay clear of server calls.
|
||||
clearInteractions(mockRoutinesRepo);
|
||||
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -658,7 +665,6 @@ void main() {
|
||||
(invocation.positionalArguments.first as Log).id = 'saved-${++writes}';
|
||||
});
|
||||
when(mockLogRepo.updateLocalDrift(any)).thenAnswer((_) async {});
|
||||
clearInteractions(mockLogRepo);
|
||||
markDone(notifier, a);
|
||||
markDone(notifier, b);
|
||||
final lastLog = a.slotPages.lastWhere((p) => p.type == SlotPageType.log);
|
||||
|
||||
@@ -54,9 +54,11 @@ class _StubRoutinesRiverpod extends RoutinesRiverpod {
|
||||
@GenerateMocks([TrophyRepository, WorkoutLogRepository, UserProfileRepository])
|
||||
void main() {
|
||||
late Routine routine;
|
||||
final mockWorkoutLogRepository = MockWorkoutLogRepository();
|
||||
// Fresh per test, so `verifyNever` and `.called(1)` only see this test's calls
|
||||
late MockWorkoutLogRepository mockWorkoutLogRepository;
|
||||
|
||||
setUp(() {
|
||||
mockWorkoutLogRepository = MockWorkoutLogRepository();
|
||||
routine = getTestRoutine();
|
||||
routine.sessions[0] = routine.sessions[0].copyWith(datetimeStart: DateTime(2025, 3, 29));
|
||||
// Pin every log to a known session id so we can verify the edit
|
||||
|
||||
Reference in New Issue
Block a user