From c397e10e3f01a9ae9e002c717ccda8607c96b644 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 18 Jan 2025 14:40:13 +0100 Subject: [PATCH] Fix tests --- test/workout/gym_mode_screen_test.dart | 64 +++++++++++++++++----- test/workout/workout_plan_screen_test.dart | 10 ++-- test_data/routines.dart | 10 ++-- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/test/workout/gym_mode_screen_test.dart b/test/workout/gym_mode_screen_test.dart index e4fa9658..d8c355f6 100644 --- a/test/workout/gym_mode_screen_test.dart +++ b/test/workout/gym_mode_screen_test.dart @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -56,21 +57,23 @@ void main() { ), child: ChangeNotifierProvider( create: (context) => mockExerciseProvider, - child: MaterialApp( - locale: Locale(locale), - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - navigatorKey: key, - home: TextButton( - onPressed: () => key.currentState!.push( - MaterialPageRoute( - settings: const RouteSettings(arguments: GymModeArguments(1, 1, 1)), - builder: (_) => const GymModeScreen(), + child: riverpod.ProviderScope( + child: MaterialApp( + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: key, + home: TextButton( + onPressed: () => key.currentState!.push( + MaterialPageRoute( + settings: const RouteSettings(arguments: GymModeArguments(1, 1, 1)), + builder: (_) => const GymModeScreen(), + ), ), + child: const SizedBox(), ), - child: const SizedBox(), + routes: {RoutineScreen.routeName: (ctx) => const RoutineScreen()}, ), - routes: {RoutineScreen.routeName: (ctx) => const RoutineScreen()}, ), ), ); @@ -174,9 +177,25 @@ void main() { await tester.pumpAndSettle(); // - // Side raises - exercise overview page + // Bench press - log + // + expect(find.text('Bench press'), findsOneWidget); + expect(find.byType(LogPage), findsOneWidget); + expect(find.byType(Form), findsOneWidget); + await tester.tap(find.byIcon(Icons.chevron_right)); + await tester.pumpAndSettle(); + + // + // Pause + // + expect(find.text('Pause'), findsOneWidget); + expect(find.byType(TimerWidget), findsOneWidget); + await tester.tap(find.byIcon(Icons.chevron_right)); + await tester.pumpAndSettle(); + + // + // Side raises - overview // - debugDumpApp(); expect(find.text('Side raises'), findsOneWidget); expect(find.byType(ExerciseOverview), findsOneWidget); await tester.tap(find.byIcon(Icons.chevron_right)); @@ -185,6 +204,7 @@ void main() { // // Side raises - log // + expect(find.text('Side raises'), findsOneWidget); expect(find.byType(LogPage), findsOneWidget); await tester.tap(find.byIcon(Icons.chevron_right)); await tester.pumpAndSettle(); @@ -199,6 +219,22 @@ void main() { // // Side raises - log // + expect(find.text('Side raises'), findsOneWidget); + expect(find.byType(LogPage), findsOneWidget); + await tester.tap(find.byIcon(Icons.chevron_right)); + await tester.pumpAndSettle(); + + // + // Side raises - timer + // + expect(find.byType(TimerWidget), findsOneWidget); + await tester.tap(find.byIcon(Icons.chevron_right)); + await tester.pumpAndSettle(); + + // + // Side raises - log + // + expect(find.text('Side raises'), findsOneWidget); expect(find.byType(LogPage), findsOneWidget); await tester.tap(find.byIcon(Icons.chevron_right)); await tester.pumpAndSettle(); diff --git a/test/workout/workout_plan_screen_test.dart b/test/workout/workout_plan_screen_test.dart index 7cce3eb1..52f65ceb 100644 --- a/test/workout/workout_plan_screen_test.dart +++ b/test/workout/workout_plan_screen_test.dart @@ -65,7 +65,7 @@ void main() { ); } - testWidgets('Test the widgets on the nutritional plan screen', (WidgetTester tester) async { + testWidgets('Test the widgets on the routine screen', (WidgetTester tester) async { await tester.pumpWidget(renderWidget()); await tester.tap(find.byType(TextButton)); await tester.pumpAndSettle(); @@ -75,8 +75,10 @@ void main() { expect(find.text('first day'), findsOneWidget); expect(find.text('chest, shoulders'), findsOneWidget); - expect(find.text('second day'), findsOneWidget); - expect(find.text('legs'), findsOneWidget); - expect(find.byType(Card), findsNWidgets(2)); + // The second day is repeated + expect(find.text('second day'), findsNWidgets(2)); + expect(find.text('legs'), findsNWidgets(2)); + + expect(find.byType(Card), findsNWidgets(3)); }); } diff --git a/test_data/routines.dart b/test_data/routines.dart index bd254a78..15d9670e 100644 --- a/test_data/routines.dart +++ b/test_data/routines.dart @@ -240,7 +240,7 @@ Routine getTestRoutine({List? exercises}) { textRepr: '4 sets 12x10kg', ), ], - ) + ), ], ), DayData( @@ -269,7 +269,7 @@ Routine getTestRoutine({List? exercises}) { textRepr: '4 sets 3x100kg', ), ], - ) + ), ], ), DayData( @@ -325,7 +325,7 @@ Routine getTestRoutine({List? exercises}) { textRepr: '5 sets 8x105kg', ), ], - ) + ), ], ), ], @@ -433,7 +433,7 @@ Routine getTestRoutine({List? exercises}) { textRepr: '12x10kg', ), ], - ) + ), ], ), DayData( @@ -490,7 +490,7 @@ Routine getTestRoutine({List? exercises}) { textRepr: '3x100kg', ), ], - ) + ), ], ), ],