diff --git a/integration_test/2_workout.dart b/integration_test/2_workout.dart index fb58bb20..38281966 100644 --- a/integration_test/2_workout.dart +++ b/integration_test/2_workout.dart @@ -16,7 +16,7 @@ Widget createWorkoutDetailScreen({locale = 'en'}) { final mockWorkoutProvider = MockRoutinesProvider(); final workout = getWorkout(exercises: getScreenshotExercises()); when(mockWorkoutProvider.activePlan).thenReturn(workout); - when(mockWorkoutProvider.fetchAndSetWorkoutPlanFull(1)).thenAnswer((_) => Future.value(workout)); + when(mockWorkoutProvider.fetchAndSetRoutineFull(1)).thenAnswer((_) => Future.value(workout)); return MultiProvider( providers: [ diff --git a/lib/models/workouts/day.dart b/lib/models/workouts/day.dart index 53c8d9a2..1641d239 100644 --- a/lib/models/workouts/day.dart +++ b/lib/models/workouts/day.dart @@ -49,6 +49,9 @@ class Day { @JsonKey(required: true) late String type; + @JsonKey(required: true) + late num order; + @JsonKey(required: true) late Object? config; @@ -62,6 +65,17 @@ class Day { slots = []; } + Day.empty() { + name = 'new day'; + description = ''; + type = 'custom'; + isRest = false; + needLogsToAdvance = false; + order = 0; + config = {}; + slots = []; + } + // Boilerplate factory Day.fromJson(Map json) => _$DayFromJson(json); diff --git a/lib/models/workouts/day.g.dart b/lib/models/workouts/day.g.dart index 232f3dc5..e8e0f6ee 100644 --- a/lib/models/workouts/day.g.dart +++ b/lib/models/workouts/day.g.dart @@ -17,6 +17,7 @@ Day _$DayFromJson(Map json) { 'is_rest', 'need_logs_to_advance', 'type', + 'order', 'config' ], ); @@ -28,6 +29,7 @@ Day _$DayFromJson(Map json) { ..isRest = json['is_rest'] as bool ..needLogsToAdvance = json['need_logs_to_advance'] as bool ..type = json['type'] as String + ..order = json['order'] as num ..config = json['config']; } @@ -39,5 +41,6 @@ Map _$DayToJson(Day instance) => { 'is_rest': instance.isRest, 'need_logs_to_advance': instance.needLogsToAdvance, 'type': instance.type, + 'order': instance.order, 'config': instance.config, }; diff --git a/lib/providers/routines.dart b/lib/providers/routines.dart index cc520060..457cd6fe 100644 --- a/lib/providers/routines.dart +++ b/lib/providers/routines.dart @@ -24,7 +24,6 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:wger/exceptions/http_exception.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/models/exercises/exercise.dart'; -import 'package:wger/models/exercises/translation.dart'; import 'package:wger/models/workouts/day.dart'; import 'package:wger/models/workouts/day_data.dart'; import 'package:wger/models/workouts/log.dart'; @@ -54,7 +53,7 @@ class RoutinesProvider with ChangeNotifier { Routine? _currentPlan; final ExercisesProvider _exercises; final WgerBaseProvider baseProvider; - List _workoutPlans = []; + List _routines = []; List _weightUnits = []; List _repetitionUnit = []; @@ -63,10 +62,10 @@ class RoutinesProvider with ChangeNotifier { ExercisesProvider exercises, List entries, ) : _exercises = exercises, - _workoutPlans = entries; + _routines = entries; List get items { - return [..._workoutPlans]; + return [..._routines]; } List get weightUnits { @@ -76,7 +75,7 @@ class RoutinesProvider with ChangeNotifier { /// Clears all lists void clear() { _currentPlan = null; - _workoutPlans = []; + _routines = []; _weightUnits = []; _repetitionUnit = []; } @@ -96,15 +95,15 @@ class RoutinesProvider with ChangeNotifier { } List getPlans() { - return _workoutPlans; + return _routines; } Routine findById(int id) { - return _workoutPlans.firstWhere((workoutPlan) => workoutPlan.id == id); + return _routines.firstWhere((workoutPlan) => workoutPlan.id == id); } int findIndexById(int id) { - return _workoutPlans.indexWhere((workoutPlan) => workoutPlan.id == id); + return _routines.indexWhere((workoutPlan) => workoutPlan.id == id); } /// Set the currently "active" workout plan @@ -125,8 +124,8 @@ class RoutinesProvider with ChangeNotifier { /// Returns the current active workout plan. At the moment this is just /// the latest, but this might change in the future. Routine? get activePlan { - if (_workoutPlans.isNotEmpty) { - return _workoutPlans.first; + if (_routines.isNotEmpty) { + return _routines.first; } return null; } @@ -137,7 +136,7 @@ class RoutinesProvider with ChangeNotifier { /// Fetches and sets all workout plans fully, i.e. with all corresponding child /// attributes - Future fetchAndSetAllPlansFull() async { + Future fetchAndSetAllRoutinesFull() async { final data = await baseProvider.fetch( baseProvider.makeUrl( _routinesUrlPath, @@ -145,7 +144,7 @@ class RoutinesProvider with ChangeNotifier { ), ); for (final entry in data['results']) { - await fetchAndSetWorkoutPlanFull(entry['id']); + await fetchAndSetRoutineFull(entry['id']); } notifyListeners(); @@ -157,10 +156,10 @@ class RoutinesProvider with ChangeNotifier { final data = await baseProvider.fetch( baseProvider.makeUrl(_routinesUrlPath, query: {'limit': '1000'}), ); - _workoutPlans = []; + _routines = []; for (final workoutPlanData in data['results']) { final plan = Routine.fromJson(workoutPlanData); - _workoutPlans.add(plan); + _routines.add(plan); } // _workoutPlans.sort((a, b) => b.created.compareTo(a.created)); @@ -187,20 +186,20 @@ class RoutinesProvider with ChangeNotifier { /// Fetches a workout plan sparsely, i.e. only with the data on the plan /// object itself and no child attributes - Future fetchAndSetPlanSparse(int planId) async { + Future fetchAndSetRoutineSparse(int planId) async { final fullPlanData = await baseProvider.fetch( baseProvider.makeUrl(_routinesUrlPath, id: planId), ); final plan = Routine.fromJson(fullPlanData); - _workoutPlans.add(plan); - _workoutPlans.sort((a, b) => b.created.compareTo(a.created)); + _routines.add(plan); + _routines.sort((a, b) => b.created.compareTo(a.created)); notifyListeners(); return plan; } /// Fetches a workout plan fully, i.e. with all corresponding child attributes - Future fetchAndSetWorkoutPlanFull(int routineId) async { + Future fetchAndSetRoutineFull(int routineId) async { // Fetch structure and computed data final results = await Future.wait([ baseProvider.fetch( @@ -295,8 +294,8 @@ class RoutinesProvider with ChangeNotifier { } // ... and done - final routineIndex = _workoutPlans.indexWhere((r) => r.id == routineId); - _workoutPlans.replaceRange(routineIndex, routineIndex + 1, [routine]); + final routineIndex = _routines.indexWhere((r) => r.id == routineId); + _routines.replaceRange(routineIndex, routineIndex + 1, [routine]); notifyListeners(); return routine; @@ -308,7 +307,7 @@ class RoutinesProvider with ChangeNotifier { baseProvider.makeUrl(_routinesUrlPath), ); final plan = Routine.fromJson(data); - _workoutPlans.insert(0, plan); + _routines.insert(0, plan); notifyListeners(); return plan; } @@ -322,15 +321,15 @@ class RoutinesProvider with ChangeNotifier { } Future deleteRoutine(int id) async { - final existingWorkoutIndex = _workoutPlans.indexWhere((element) => element.id == id); - final existingWorkout = _workoutPlans[existingWorkoutIndex]; - _workoutPlans.removeAt(existingWorkoutIndex); + final existingWorkoutIndex = _routines.indexWhere((element) => element.id == id); + final existingWorkout = _routines[existingWorkoutIndex]; + _routines.removeAt(existingWorkoutIndex); notifyListeners(); final response = await baseProvider.deleteRequest(_routinesUrlPath, id); if (response.statusCode >= 400) { - _workoutPlans.insert(existingWorkoutIndex, existingWorkout); + _routines.insert(existingWorkoutIndex, existingWorkout); notifyListeners(); throw WgerHttpException(response.body); } @@ -405,18 +404,21 @@ class RoutinesProvider with ChangeNotifier { /* * Days */ - Future addDay(Day day, Routine workout) async { + Future addDay(Day day, {refresh = false}) async { /* * Saves a new day instance to the DB and adds it to the given workout */ - day.routineId = workout.id!; final data = await baseProvider.post( day.toJson(), baseProvider.makeUrl(_daysUrlPath), ); day = Day.fromJson(data); day.slots = []; - workout.days.insert(0, day); + final routine = findById(day.routineId); + routine.days.insert(0, day); + if (refresh) { + fetchAndSetRoutineFull(day.routineId); + } notifyListeners(); return day; } @@ -429,9 +431,19 @@ class RoutinesProvider with ChangeNotifier { notifyListeners(); } + Future editDays(List days) async { + for (final day in days) { + await baseProvider.patch( + day.toJson(), + baseProvider.makeUrl(_daysUrlPath, id: day.id), + ); + } + notifyListeners(); + } + Future deleteDay(Day day) async { await baseProvider.deleteRequest(_daysUrlPath, day.id!); - for (final workout in _workoutPlans) { + for (final workout in _routines) { workout.days.removeWhere((element) => element.id == day.id); } notifyListeners(); @@ -496,23 +508,10 @@ class RoutinesProvider with ChangeNotifier { notifyListeners(); } - Future fetchSmartText(Slot workoutSet, Translation exercise) async { - final data = await baseProvider.fetch( - baseProvider.makeUrl( - _slotsUrlPath, - id: workoutSet.id, - objectMethod: 'smart_text', - query: {'exercise': exercise.id.toString()}, - ), - ); - - return data['results']; - } - Future deleteSet(int setId) async { await baseProvider.deleteRequest(_slotsUrlPath, setId); - for (final workout in _workoutPlans) { + for (final workout in _routines) { for (final day in workout.days) { day.slots.removeWhere((element) => element.id == setId); } @@ -581,7 +580,7 @@ class RoutinesProvider with ChangeNotifier { Future deleteLog(Log log) async { await baseProvider.deleteRequest(_logsUrlPath, log.id!); - for (final workout in _workoutPlans) { + for (final workout in _routines) { workout.logs.removeWhere((element) => element.id == log.id); } notifyListeners(); diff --git a/lib/screens/home_tabs_screen.dart b/lib/screens/home_tabs_screen.dart index 5e791d80..0eb900a4 100644 --- a/lib/screens/home_tabs_screen.dart +++ b/lib/screens/home_tabs_screen.dart @@ -131,7 +131,7 @@ class _HomeTabsScreenState extends State with SingleTickerProvid log('Loading current workout plan'); if (workoutPlansProvider.activePlan != null) { final planId = workoutPlansProvider.activePlan!.id!; - await workoutPlansProvider.fetchAndSetWorkoutPlanFull(planId); + await workoutPlansProvider.fetchAndSetRoutineFull(planId); workoutPlansProvider.setCurrentPlan(planId); } } diff --git a/lib/screens/routine_edit_screen.dart b/lib/screens/routine_edit_screen.dart index 988b36c4..b6c995e4 100644 --- a/lib/screens/routine_edit_screen.dart +++ b/lib/screens/routine_edit_screen.dart @@ -17,7 +17,8 @@ */ import 'package:flutter/material.dart'; -import 'package:wger/models/workouts/routine.dart'; +import 'package:provider/provider.dart'; +import 'package:wger/providers/routines.dart'; import 'package:wger/widgets/routines/app_bar.dart'; import 'package:wger/widgets/routines/routine_edit.dart'; @@ -28,7 +29,9 @@ class RoutineEditScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final routine = ModalRoute.of(context)!.settings.arguments as Routine; + final routineId = ModalRoute.of(context)!.settings.arguments as int; + + final routine = Provider.of(context).findById(routineId); return Scaffold( appBar: RoutineDetailAppBar(routine), diff --git a/lib/screens/routine_logs_screen.dart b/lib/screens/routine_logs_screen.dart index 08e7750f..8d2dde2c 100644 --- a/lib/screens/routine_logs_screen.dart +++ b/lib/screens/routine_logs_screen.dart @@ -29,8 +29,7 @@ class WorkoutLogsScreen extends StatelessWidget { static const routeName = '/workout-logs'; Future _loadFullWorkout(BuildContext context, int routineId) { - return Provider.of(context, listen: false) - .fetchAndSetWorkoutPlanFull(routineId); + return Provider.of(context, listen: false).fetchAndSetRoutineFull(routineId); } @override diff --git a/lib/screens/routine_screen.dart b/lib/screens/routine_screen.dart index 08275a1d..eba313de 100644 --- a/lib/screens/routine_screen.dart +++ b/lib/screens/routine_screen.dart @@ -30,8 +30,7 @@ class RoutineScreen extends StatelessWidget { static const routeName = '/routine-detail'; Future _loadFullWorkout(BuildContext context, int routineId) { - return Provider.of(context, listen: false) - .fetchAndSetWorkoutPlanFull(routineId); + return Provider.of(context, listen: false).fetchAndSetRoutineFull(routineId); } @override diff --git a/lib/widgets/routines/app_bar.dart b/lib/widgets/routines/app_bar.dart index 78d1d165..d372508f 100644 --- a/lib/widgets/routines/app_bar.dart +++ b/lib/widgets/routines/app_bar.dart @@ -35,6 +35,7 @@ enum _RoutineDetailBarOptions { edit, delete, logs, + reload, } class RoutineListAppBar extends StatelessWidget implements PreferredSizeWidget { @@ -90,6 +91,10 @@ class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget PopupMenuButton( itemBuilder: (context) { return [ + PopupMenuItem<_RoutineDetailBarOptions>( + value: _RoutineDetailBarOptions.reload, + child: Text('debug / reload'), + ), PopupMenuItem<_RoutineDetailBarOptions>( value: _RoutineDetailBarOptions.logs, child: Text(AppLocalizations.of(context).labelWorkoutLogs), @@ -110,7 +115,7 @@ class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget Navigator.pushNamed( context, RoutineEditScreen.routeName, - arguments: routine, + arguments: routine.id, ); case _RoutineDetailBarOptions.logs: @@ -123,6 +128,10 @@ class RoutineDetailAppBar extends StatelessWidget implements PreferredSizeWidget case _RoutineDetailBarOptions.delete: Provider.of(context, listen: false).deleteRoutine(routine.id!); Navigator.of(context).pop(); + + case _RoutineDetailBarOptions.reload: + Provider.of(context, listen: false) + .fetchAndSetRoutineFull(routine.id!); } }, ), diff --git a/lib/widgets/routines/forms/day.dart b/lib/widgets/routines/forms/day.dart index b6d25cd2..72377b63 100644 --- a/lib/widgets/routines/forms/day.dart +++ b/lib/widgets/routines/forms/day.dart @@ -6,6 +6,83 @@ import 'package:wger/models/workouts/day.dart'; import 'package:wger/models/workouts/routine.dart'; import 'package:wger/providers/routines.dart'; +class ReorderableDaysList extends StatefulWidget { + int routineId; + List days; + + ReorderableDaysList(this.days, this.routineId, {super.key}); + + @override + State createState() => _ReorderableDaysListState(); +} + +class _ReorderableDaysListState extends State { + int? selectedDayId; + + @override + Widget build(BuildContext context) { + return ReorderableListView.builder( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: widget.days.length + 1, + itemBuilder: (context, index) { + // "add day" button always at the end + if (index == widget.days.length) { + return ListTile( + key: const ValueKey('add-day'), + // tileColor: Theme.of(context).highlightColor, + leading: const Icon(Icons.add), + title: Text( + AppLocalizations.of(context).newDay, + style: Theme.of(context).textTheme.titleMedium, + ), + onTap: () { + final newDay = Day.empty(); + newDay.routineId = widget.routineId; + Provider.of(context, listen: false).addDay(newDay, refresh: true); + }, + ); + } + + final day = widget.days[index]; + + return ListTile( + tileColor: day.id == selectedDayId ? Theme.of(context).highlightColor : null, + key: ValueKey(day), + title: Text(day.isRest ? 'REST DAY!' : day.name), + leading: ReorderableDragStartListener( + index: index, + child: const Icon(Icons.drag_handle), + ), + trailing: IconButton( + onPressed: () { + setState(() { + selectedDayId = day.id; + }); + }, + icon: const Icon(Icons.edit), + ), + ); + }, + onReorder: (int oldIndex, int newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final Day item = widget.days.removeAt(oldIndex); + widget.days.insert(newIndex, item); + + for (int i = 0; i < widget.days.length; i++) { + widget.days[i].order = i + 1; + } + }); + + Provider.of(context, listen: false).editDays(widget.days); + }, + ); + } +} + class DayFormWidget extends StatefulWidget { final Routine routine; final dayController = TextEditingController(); @@ -53,8 +130,6 @@ class _DayFormWidgetState extends State { return null; }, ), - // const SizedBox(height: 10), - // ...Day.weekdays.keys.map((dayNr) => DayCheckbox(dayNr, widget._day)), ElevatedButton( key: const Key(SUBMIT_BUTTON_KEY_NAME), child: Text(AppLocalizations.of(context).save), @@ -66,10 +141,10 @@ class _DayFormWidgetState extends State { try { if (widget._day.id == null) { - Provider.of(context, listen: false).addDay( - widget._day, - widget.routine, - ); + // Provider.of(context, listen: false).addDay( + // widget._day, + // widget.routine, + // ); } else { Provider.of(context, listen: false).editDay( widget._day, diff --git a/lib/widgets/routines/forms/routine.dart b/lib/widgets/routines/forms/routine.dart index ce26ef57..86438a59 100644 --- a/lib/widgets/routines/forms/routine.dart +++ b/lib/widgets/routines/forms/routine.dart @@ -5,7 +5,6 @@ import 'package:provider/provider.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/models/workouts/routine.dart'; import 'package:wger/providers/routines.dart'; -import 'package:wger/screens/routine_screen.dart'; class RoutineForm extends StatefulWidget { final Routine _routine; @@ -203,20 +202,11 @@ class _RoutineFormState extends State { if (widget._routine.id != null) { await Provider.of(context, listen: false) .editRoutine(widget._routine); - if (context.mounted) { - Navigator.of(context).pop(); - } } else { final Routine newPlan = await Provider.of( context, listen: false, ).addRoutine(widget._routine); - if (context.mounted) { - Navigator.of(context).pushReplacementNamed( - RoutineScreen.routeName, - arguments: newPlan, - ); - } } }, ), diff --git a/lib/widgets/routines/routine_edit.dart b/lib/widgets/routines/routine_edit.dart index a45384dd..c7635175 100644 --- a/lib/widgets/routines/routine_edit.dart +++ b/lib/widgets/routines/routine_edit.dart @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'; import 'package:wger/models/workouts/routine.dart'; +import 'package:wger/widgets/routines/forms/day.dart'; import 'package:wger/widgets/routines/forms/routine.dart'; class RoutineEdit extends StatelessWidget { @@ -29,7 +30,13 @@ class RoutineEdit extends StatelessWidget { Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(8), - child: Column(children: [RoutineForm(_routine)]), + child: ListView( + children: [ + RoutineForm(_routine), + Container(height: 10), + ReorderableDaysList(_routine.days, _routine.id!), + ], + ), ); } } diff --git a/lib/widgets/routines/workout_plans_list.dart b/lib/widgets/routines/workout_plans_list.dart index faadbe6a..34e7d199 100644 --- a/lib/widgets/routines/workout_plans_list.dart +++ b/lib/widgets/routines/workout_plans_list.dart @@ -32,7 +32,7 @@ class WorkoutPlansList extends StatelessWidget { @override Widget build(BuildContext context) { return RefreshIndicator( - onRefresh: () => _workoutProvider.fetchAndSetAllPlansFull(), + onRefresh: () => _workoutProvider.fetchAndSetAllRoutinesFull(), // onRefresh: () => _workoutProvider.fetchAndSetAllPlansSparse(), child: _workoutProvider.items.isEmpty ? const TextPrompt() diff --git a/test/workout/repetition_unit_form_widget_test.mocks.dart b/test/workout/repetition_unit_form_widget_test.mocks.dart index 42d90426..66377cd5 100644 --- a/test/workout/repetition_unit_form_widget_test.mocks.dart +++ b/test/workout/repetition_unit_form_widget_test.mocks.dart @@ -4,12 +4,10 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i12; -import 'dart:ui' as _i17; +import 'dart:ui' as _i15; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i16; import 'package:wger/models/exercises/exercise.dart' as _i14; -import 'package:wger/models/exercises/translation.dart' as _i15; import 'package:wger/models/workouts/day.dart' as _i6; import 'package:wger/models/workouts/day_data.dart' as _i13; import 'package:wger/models/workouts/log.dart' as _i10; @@ -245,9 +243,9 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i12.Future fetchAndSetAllRoutinesFull() => (super.noSuchMethod( Invocation.method( - #fetchAndSetAllPlansFull, + #fetchAndSetAllRoutinesFull, [], ), returnValue: _i12.Future.value(), @@ -274,30 +272,30 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future<_i5.Routine> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineSparse(int? planId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), )), ) as _i12.Future<_i5.Routine>); @override - _i12.Future<_i5.Routine> fetchAndSetWorkoutPlanFull(int? routineId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineFull(int? routineId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), )), @@ -386,25 +384,21 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { @override _i12.Future<_i6.Day> addDay( - _i6.Day? day, - _i5.Routine? workout, - ) => + _i6.Day? day, { + dynamic refresh = false, + }) => (super.noSuchMethod( Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), returnValue: _i12.Future<_i6.Day>.value(_FakeDay_4( this, Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), )), ) as _i12.Future<_i6.Day>); @@ -419,6 +413,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); + @override + _i12.Future editDays(List<_i6.Day>? days) => (super.noSuchMethod( + Invocation.method( + #editDays, + [days], + ), + returnValue: _i12.Future.value(), + returnValueForMissingStub: _i12.Future.value(), + ) as _i12.Future); + @override _i12.Future deleteDay(_i6.Day? day) => (super.noSuchMethod( Invocation.method( @@ -480,31 +484,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); - @override - _i12.Future fetchSmartText( - _i7.Slot? workoutSet, - _i15.Translation? exercise, - ) => - (super.noSuchMethod( - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - returnValue: _i12.Future.value(_i16.dummyValue( - this, - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - )), - ) as _i12.Future); - @override _i12.Future deleteSet(int? setId) => (super.noSuchMethod( Invocation.method( @@ -580,7 +559,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ) as _i12.Future); @override - void addListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -589,7 +568,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - void removeListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], diff --git a/test/workout/workout_day_form_test.mocks.dart b/test/workout/workout_day_form_test.mocks.dart index c1684877..8c767507 100644 --- a/test/workout/workout_day_form_test.mocks.dart +++ b/test/workout/workout_day_form_test.mocks.dart @@ -4,12 +4,10 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i12; -import 'dart:ui' as _i17; +import 'dart:ui' as _i15; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i16; import 'package:wger/models/exercises/exercise.dart' as _i14; -import 'package:wger/models/exercises/translation.dart' as _i15; import 'package:wger/models/workouts/day.dart' as _i6; import 'package:wger/models/workouts/day_data.dart' as _i13; import 'package:wger/models/workouts/log.dart' as _i10; @@ -245,9 +243,9 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i12.Future fetchAndSetAllRoutinesFull() => (super.noSuchMethod( Invocation.method( - #fetchAndSetAllPlansFull, + #fetchAndSetAllRoutinesFull, [], ), returnValue: _i12.Future.value(), @@ -274,30 +272,30 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future<_i5.Routine> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineSparse(int? planId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), )), ) as _i12.Future<_i5.Routine>); @override - _i12.Future<_i5.Routine> fetchAndSetWorkoutPlanFull(int? routineId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineFull(int? routineId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), )), @@ -386,25 +384,21 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { @override _i12.Future<_i6.Day> addDay( - _i6.Day? day, - _i5.Routine? workout, - ) => + _i6.Day? day, { + dynamic refresh = false, + }) => (super.noSuchMethod( Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), returnValue: _i12.Future<_i6.Day>.value(_FakeDay_4( this, Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), )), ) as _i12.Future<_i6.Day>); @@ -419,6 +413,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); + @override + _i12.Future editDays(List<_i6.Day>? days) => (super.noSuchMethod( + Invocation.method( + #editDays, + [days], + ), + returnValue: _i12.Future.value(), + returnValueForMissingStub: _i12.Future.value(), + ) as _i12.Future); + @override _i12.Future deleteDay(_i6.Day? day) => (super.noSuchMethod( Invocation.method( @@ -480,31 +484,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); - @override - _i12.Future fetchSmartText( - _i7.Slot? workoutSet, - _i15.Translation? exercise, - ) => - (super.noSuchMethod( - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - returnValue: _i12.Future.value(_i16.dummyValue( - this, - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - )), - ) as _i12.Future); - @override _i12.Future deleteSet(int? setId) => (super.noSuchMethod( Invocation.method( @@ -580,7 +559,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ) as _i12.Future); @override - void addListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -589,7 +568,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - void removeListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], diff --git a/test/workout/workout_form_test.dart b/test/workout/workout_form_test.dart index ab65d2be..39a9de14 100644 --- a/test/workout/workout_form_test.dart +++ b/test/workout/workout_form_test.dart @@ -47,7 +47,7 @@ void main() { setUp(() { mockWorkoutPlans = MockRoutinesProvider(); when(mockWorkoutPlans.editRoutine(any)).thenAnswer((_) => Future.value(existingPlan)); - when(mockWorkoutPlans.fetchAndSetWorkoutPlanFull(any)) + when(mockWorkoutPlans.fetchAndSetRoutineFull(any)) .thenAnswer((_) => Future.value(existingPlan)); }); diff --git a/test/workout/workout_form_test.mocks.dart b/test/workout/workout_form_test.mocks.dart index e24e3823..decae660 100644 --- a/test/workout/workout_form_test.mocks.dart +++ b/test/workout/workout_form_test.mocks.dart @@ -4,12 +4,10 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i12; -import 'dart:ui' as _i17; +import 'dart:ui' as _i15; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i16; import 'package:wger/models/exercises/exercise.dart' as _i14; -import 'package:wger/models/exercises/translation.dart' as _i15; import 'package:wger/models/workouts/day.dart' as _i6; import 'package:wger/models/workouts/day_data.dart' as _i13; import 'package:wger/models/workouts/log.dart' as _i10; @@ -245,9 +243,9 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i12.Future fetchAndSetAllRoutinesFull() => (super.noSuchMethod( Invocation.method( - #fetchAndSetAllPlansFull, + #fetchAndSetAllRoutinesFull, [], ), returnValue: _i12.Future.value(), @@ -274,30 +272,30 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - _i12.Future<_i5.Routine> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineSparse(int? planId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), )), ) as _i12.Future<_i5.Routine>); @override - _i12.Future<_i5.Routine> fetchAndSetWorkoutPlanFull(int? routineId) => (super.noSuchMethod( + _i12.Future<_i5.Routine> fetchAndSetRoutineFull(int? routineId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), returnValue: _i12.Future<_i5.Routine>.value(_FakeRoutine_3( this, Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), )), @@ -386,25 +384,21 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { @override _i12.Future<_i6.Day> addDay( - _i6.Day? day, - _i5.Routine? workout, - ) => + _i6.Day? day, { + dynamic refresh = false, + }) => (super.noSuchMethod( Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), returnValue: _i12.Future<_i6.Day>.value(_FakeDay_4( this, Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), )), ) as _i12.Future<_i6.Day>); @@ -419,6 +413,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); + @override + _i12.Future editDays(List<_i6.Day>? days) => (super.noSuchMethod( + Invocation.method( + #editDays, + [days], + ), + returnValue: _i12.Future.value(), + returnValueForMissingStub: _i12.Future.value(), + ) as _i12.Future); + @override _i12.Future deleteDay(_i6.Day? day) => (super.noSuchMethod( Invocation.method( @@ -480,31 +484,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { returnValueForMissingStub: _i12.Future.value(), ) as _i12.Future); - @override - _i12.Future fetchSmartText( - _i7.Slot? workoutSet, - _i15.Translation? exercise, - ) => - (super.noSuchMethod( - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - returnValue: _i12.Future.value(_i16.dummyValue( - this, - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - )), - ) as _i12.Future); - @override _i12.Future deleteSet(int? setId) => (super.noSuchMethod( Invocation.method( @@ -580,7 +559,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ) as _i12.Future); @override - void addListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -589,7 +568,7 @@ class MockRoutinesProvider extends _i1.Mock implements _i11.RoutinesProvider { ); @override - void removeListener(_i17.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], diff --git a/test/workout/workout_provider_test.dart b/test/workout/workout_provider_test.dart index ff4995a5..da259776 100644 --- a/test/workout/workout_provider_test.dart +++ b/test/workout/workout_provider_test.dart @@ -65,7 +65,7 @@ void main() { // Load the entries final provider = RoutinesProvider(mockBaseProvider, exercisesProvider, []); - final plan = await provider.fetchAndSetPlanSparse(325397); + final plan = await provider.fetchAndSetRoutineSparse(325397); final plans = provider.getPlans(); // Check that everything is ok @@ -94,7 +94,7 @@ void main() { // Load the entries final provider = RoutinesProvider(mockBaseProvider, exercisesProvider, []); - await provider.fetchAndSetPlanSparse(325397); + await provider.fetchAndSetRoutineSparse(325397); await provider.deleteRoutine(325397); final plans = provider.getPlans(); expect(plans.length, 0); diff --git a/test/workout/workout_set_form_test.dart b/test/workout/workout_set_form_test.dart index a0a721a2..da5a5466 100644 --- a/test/workout/workout_set_form_test.dart +++ b/test/workout/workout_set_form_test.dart @@ -83,7 +83,6 @@ void main() { testWidgets('Test creating a new set', (WidgetTester tester) async { when(mockWorkoutPlans.addSet(any)).thenAnswer((_) => Future.value(Slot.empty())); when(mockWorkoutPlans.addSetting(any)).thenAnswer((_) => Future.value(SlotEntry.empty())); - when(mockWorkoutPlans.fetchSmartText(any, any)).thenAnswer((_) => Future.value('2 x 10')); when(mockExerciseProvider.searchExercise( any, languageCode: anyNamed('languageCode'), diff --git a/test/workout/workout_set_form_test.mocks.dart b/test/workout/workout_set_form_test.mocks.dart index 56287284..c150fef5 100644 --- a/test/workout/workout_set_form_test.mocks.dart +++ b/test/workout/workout_set_form_test.mocks.dart @@ -8,14 +8,12 @@ import 'dart:ui' as _i21; import 'package:http/http.dart' as _i10; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i25; import 'package:wger/database/exercises/exercise_database.dart' as _i3; import 'package:wger/models/exercises/category.dart' as _i5; import 'package:wger/models/exercises/equipment.dart' as _i6; import 'package:wger/models/exercises/exercise.dart' as _i4; import 'package:wger/models/exercises/language.dart' as _i8; import 'package:wger/models/exercises/muscle.dart' as _i7; -import 'package:wger/models/exercises/translation.dart' as _i24; import 'package:wger/models/workouts/day.dart' as _i14; import 'package:wger/models/workouts/day_data.dart' as _i23; import 'package:wger/models/workouts/log.dart' as _i18; @@ -976,9 +974,9 @@ class MockRoutinesProvider extends _i1.Mock implements _i22.RoutinesProvider { ); @override - _i20.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i20.Future fetchAndSetAllRoutinesFull() => (super.noSuchMethod( Invocation.method( - #fetchAndSetAllPlansFull, + #fetchAndSetAllRoutinesFull, [], ), returnValue: _i20.Future.value(), @@ -1005,30 +1003,30 @@ class MockRoutinesProvider extends _i1.Mock implements _i22.RoutinesProvider { ); @override - _i20.Future<_i13.Routine> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i20.Future<_i13.Routine> fetchAndSetRoutineSparse(int? planId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), returnValue: _i20.Future<_i13.Routine>.value(_FakeRoutine_13( this, Invocation.method( - #fetchAndSetPlanSparse, + #fetchAndSetRoutineSparse, [planId], ), )), ) as _i20.Future<_i13.Routine>); @override - _i20.Future<_i13.Routine> fetchAndSetWorkoutPlanFull(int? routineId) => (super.noSuchMethod( + _i20.Future<_i13.Routine> fetchAndSetRoutineFull(int? routineId) => (super.noSuchMethod( Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), returnValue: _i20.Future<_i13.Routine>.value(_FakeRoutine_13( this, Invocation.method( - #fetchAndSetWorkoutPlanFull, + #fetchAndSetRoutineFull, [routineId], ), )), @@ -1117,25 +1115,21 @@ class MockRoutinesProvider extends _i1.Mock implements _i22.RoutinesProvider { @override _i20.Future<_i14.Day> addDay( - _i14.Day? day, - _i13.Routine? workout, - ) => + _i14.Day? day, { + dynamic refresh = false, + }) => (super.noSuchMethod( Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), returnValue: _i20.Future<_i14.Day>.value(_FakeDay_14( this, Invocation.method( #addDay, - [ - day, - workout, - ], + [day], + {#refresh: refresh}, ), )), ) as _i20.Future<_i14.Day>); @@ -1150,6 +1144,16 @@ class MockRoutinesProvider extends _i1.Mock implements _i22.RoutinesProvider { returnValueForMissingStub: _i20.Future.value(), ) as _i20.Future); + @override + _i20.Future editDays(List<_i14.Day>? days) => (super.noSuchMethod( + Invocation.method( + #editDays, + [days], + ), + returnValue: _i20.Future.value(), + returnValueForMissingStub: _i20.Future.value(), + ) as _i20.Future); + @override _i20.Future deleteDay(_i14.Day? day) => (super.noSuchMethod( Invocation.method( @@ -1211,31 +1215,6 @@ class MockRoutinesProvider extends _i1.Mock implements _i22.RoutinesProvider { returnValueForMissingStub: _i20.Future.value(), ) as _i20.Future); - @override - _i20.Future fetchSmartText( - _i15.Slot? workoutSet, - _i24.Translation? exercise, - ) => - (super.noSuchMethod( - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - returnValue: _i20.Future.value(_i25.dummyValue( - this, - Invocation.method( - #fetchSmartText, - [ - workoutSet, - exercise, - ], - ), - )), - ) as _i20.Future); - @override _i20.Future deleteSet(int? setId) => (super.noSuchMethod( Invocation.method(