From cb4bce765394e3f8984193459d0388e735b0cb5b Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 18:51:37 +0200 Subject: [PATCH 01/12] Show ingredient images --- lib/models/body_weight/weight_entry.g.dart | 3 +- lib/models/exercises/category.g.dart | 3 +- lib/models/exercises/exercise.g.dart | 6 +- lib/models/exercises/image.g.dart | 3 +- .../measurements/measurement_category.g.dart | 4 +- .../measurements/measurement_entry.g.dart | 3 +- lib/models/nutrition/image.dart | 52 +++ lib/models/nutrition/ingredient.dart | 6 +- lib/models/nutrition/ingredient.g.dart | 7 +- .../nutrition/ingredient_weight_unit.g.dart | 6 +- lib/models/nutrition/log.g.dart | 9 +- lib/models/nutrition/nutritional_plan.g.dart | 3 +- lib/models/nutrition/weight_unit.g.dart | 3 +- lib/models/workouts/repetition_unit.g.dart | 3 +- lib/models/workouts/session.g.dart | 12 +- lib/models/workouts/weight_unit.g.dart | 3 +- lib/models/workouts/workout_plan.g.dart | 3 +- lib/providers/nutrition.dart | 11 +- lib/widgets/core/core.dart | 21 ++ lib/widgets/nutrition/helpers.dart | 10 +- lib/widgets/nutrition/meal.dart | 68 ++-- lib/widgets/nutrition/widgets.dart | 4 + pubspec.lock | 131 ++++---- test/gallery/gallery_screen_test.mocks.dart | 128 ++++--- ...surement_categories_screen_test.mocks.dart | 135 +++++--- .../measurement_provider_test.mocks.dart | 75 +++-- .../nutritional_plan_form_test.mocks.dart | 262 ++++++++++----- test/other/base_provider_test.mocks.dart | 146 +++++--- test/workout/workout_form_test.mocks.dart | 317 ++++++++++++------ test/workout/workout_set_form_test.mocks.dart | 160 ++++++--- 30 files changed, 1047 insertions(+), 550 deletions(-) create mode 100644 lib/models/nutrition/image.dart diff --git a/lib/models/body_weight/weight_entry.g.dart b/lib/models/body_weight/weight_entry.g.dart index d1152d20e..60ee02c9b 100644 --- a/lib/models/body_weight/weight_entry.g.dart +++ b/lib/models/body_weight/weight_entry.g.dart @@ -18,7 +18,8 @@ WeightEntry _$WeightEntryFromJson(Map json) { ); } -Map _$WeightEntryToJson(WeightEntry instance) => { +Map _$WeightEntryToJson(WeightEntry instance) => + { 'id': instance.id, 'weight': numToString(instance.weight), 'date': toDate(instance.date), diff --git a/lib/models/exercises/category.g.dart b/lib/models/exercises/category.g.dart index 915120d13..19383107b 100644 --- a/lib/models/exercises/category.g.dart +++ b/lib/models/exercises/category.g.dart @@ -17,7 +17,8 @@ ExerciseCategory _$ExerciseCategoryFromJson(Map json) { ); } -Map _$ExerciseCategoryToJson(ExerciseCategory instance) => { +Map _$ExerciseCategoryToJson(ExerciseCategory instance) => + { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/exercises/exercise.g.dart b/lib/models/exercises/exercise.g.dart index 68183089c..614ff9b23 100644 --- a/lib/models/exercises/exercise.g.dart +++ b/lib/models/exercises/exercise.g.dart @@ -48,7 +48,8 @@ Exercise _$ExerciseFromJson(Map json) { tips: (json['comments'] as List?) ?.map((e) => Comment.fromJson(e as Map)) .toList(), - )..categoryObj = ExerciseCategory.fromJson(json['category'] as Map); + )..categoryObj = + ExerciseCategory.fromJson(json['category'] as Map); } Map _$ExerciseToJson(Exercise instance) => { @@ -59,7 +60,8 @@ Map _$ExerciseToJson(Exercise instance) => { 'description': instance.description, 'category': instance.categoryObj.toJson(), 'muscles': instance.muscles.map((e) => e.toJson()).toList(), - 'muscles_secondary': instance.musclesSecondary.map((e) => e.toJson()).toList(), + 'muscles_secondary': + instance.musclesSecondary.map((e) => e.toJson()).toList(), 'equipment': instance.equipment.map((e) => e.toJson()).toList(), 'images': instance.images.map((e) => e.toJson()).toList(), 'videos': instance.videos.map((e) => e.toJson()).toList(), diff --git a/lib/models/exercises/image.g.dart b/lib/models/exercises/image.g.dart index 6ef7c62e4..1240dc38d 100644 --- a/lib/models/exercises/image.g.dart +++ b/lib/models/exercises/image.g.dart @@ -20,7 +20,8 @@ ExerciseImage _$ExerciseImageFromJson(Map json) { ); } -Map _$ExerciseImageToJson(ExerciseImage instance) => { +Map _$ExerciseImageToJson(ExerciseImage instance) => + { 'id': instance.id, 'uuid': instance.uuid, 'exercise_base': instance.exerciseBaseId, diff --git a/lib/models/measurements/measurement_category.g.dart b/lib/models/measurements/measurement_category.g.dart index eb887b2e7..ef4ebcd30 100644 --- a/lib/models/measurements/measurement_category.g.dart +++ b/lib/models/measurements/measurement_category.g.dart @@ -22,7 +22,9 @@ MeasurementCategory _$MeasurementCategoryFromJson(Map json) { ); } -Map _$MeasurementCategoryToJson(MeasurementCategory instance) => { +Map _$MeasurementCategoryToJson( + MeasurementCategory instance) => + { 'id': instance.id, 'name': instance.name, 'unit': instance.unit, diff --git a/lib/models/measurements/measurement_entry.g.dart b/lib/models/measurements/measurement_entry.g.dart index 7f6e346ad..4b0969600 100644 --- a/lib/models/measurements/measurement_entry.g.dart +++ b/lib/models/measurements/measurement_entry.g.dart @@ -20,7 +20,8 @@ MeasurementEntry _$MeasurementEntryFromJson(Map json) { ); } -Map _$MeasurementEntryToJson(MeasurementEntry instance) => { +Map _$MeasurementEntryToJson(MeasurementEntry instance) => + { 'id': instance.id, 'category': instance.category, 'date': toDate(instance.date), diff --git a/lib/models/nutrition/image.dart b/lib/models/nutrition/image.dart new file mode 100644 index 000000000..91d1ff7ae --- /dev/null +++ b/lib/models/nutrition/image.dart @@ -0,0 +1,52 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (C) 2020, 2021 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import 'package:json_annotation/json_annotation.dart'; + +part 'image.g.dart'; + +@JsonSerializable() +class IngredientImage { + @JsonKey(required: true) + final int id; + + /// Barcode of the product + @JsonKey(required: true) + final String uuid; + + /// Name of the product + @JsonKey(required: true, name: 'ingredient_id') + final String ingredientId; + + @JsonKey(required: true) + final String image; + + /// Size in bytes + @JsonKey(required: true) + final int size; + + const IngredientImage( + {required this.id, + required this.uuid, + required this.ingredientId, + required this.image, + required this.size}); + + // Boilerplate + factory IngredientImage.fromJson(Map json) => _$IngredientImageFromJson(json); + Map toJson() => _$IngredientImageToJson(this); +} diff --git a/lib/models/nutrition/ingredient.dart b/lib/models/nutrition/ingredient.dart index a60d6f797..86e3f9b3e 100644 --- a/lib/models/nutrition/ingredient.dart +++ b/lib/models/nutrition/ingredient.dart @@ -17,6 +17,7 @@ */ import 'package:json_annotation/json_annotation.dart'; import 'package:wger/helpers/json.dart'; +import 'package:wger/models/nutrition/image.dart'; part 'ingredient.g.dart'; @@ -68,7 +69,9 @@ class Ingredient { @JsonKey(required: true, fromJson: stringToNum, toJson: numToString) final num sodium; - const Ingredient({ + IngredientImage? image; + + Ingredient({ required this.id, required this.code, required this.name, @@ -81,6 +84,7 @@ class Ingredient { required this.fatSaturated, required this.fibres, required this.sodium, + this.image, }); // Boilerplate diff --git a/lib/models/nutrition/ingredient.g.dart b/lib/models/nutrition/ingredient.g.dart index 5c19de593..c5ec7c8e6 100644 --- a/lib/models/nutrition/ingredient.g.dart +++ b/lib/models/nutrition/ingredient.g.dart @@ -37,10 +37,14 @@ Ingredient _$IngredientFromJson(Map json) { fatSaturated: stringToNum(json['fat_saturated'] as String?), fibres: stringToNum(json['fibres'] as String?), sodium: stringToNum(json['sodium'] as String?), + image: json['image'] == null + ? null + : IngredientImage.fromJson(json['image'] as Map), ); } -Map _$IngredientToJson(Ingredient instance) => { +Map _$IngredientToJson(Ingredient instance) => + { 'id': instance.id, 'code': instance.code, 'name': instance.name, @@ -53,4 +57,5 @@ Map _$IngredientToJson(Ingredient instance) => json) { ); return IngredientWeightUnit( id: json['id'] as int, - weightUnit: WeightUnit.fromJson(json['weight_unit'] as Map), + weightUnit: + WeightUnit.fromJson(json['weight_unit'] as Map), ingredient: Ingredient.fromJson(json['ingredient'] as Map), grams: json['grams'] as int, amount: (json['amount'] as num).toDouble(), ); } -Map _$IngredientWeightUnitToJson(IngredientWeightUnit instance) => +Map _$IngredientWeightUnitToJson( + IngredientWeightUnit instance) => { 'id': instance.id, 'weight_unit': instance.weightUnit, diff --git a/lib/models/nutrition/log.g.dart b/lib/models/nutrition/log.g.dart index 616901551..390687681 100644 --- a/lib/models/nutrition/log.g.dart +++ b/lib/models/nutrition/log.g.dart @@ -9,7 +9,14 @@ part of 'log.dart'; Log _$LogFromJson(Map json) { $checkKeys( json, - requiredKeys: const ['id', 'plan', 'datetime', 'ingredient', 'weight_unit', 'amount'], + requiredKeys: const [ + 'id', + 'plan', + 'datetime', + 'ingredient', + 'weight_unit', + 'amount' + ], ); return Log( id: json['id'] as int?, diff --git a/lib/models/nutrition/nutritional_plan.g.dart b/lib/models/nutrition/nutritional_plan.g.dart index 661a9f47a..9b10d8a5a 100644 --- a/lib/models/nutrition/nutritional_plan.g.dart +++ b/lib/models/nutrition/nutritional_plan.g.dart @@ -18,7 +18,8 @@ NutritionalPlan _$NutritionalPlanFromJson(Map json) { ); } -Map _$NutritionalPlanToJson(NutritionalPlan instance) => { +Map _$NutritionalPlanToJson(NutritionalPlan instance) => + { 'id': instance.id, 'description': instance.description, 'creation_date': toDate(instance.creationDate), diff --git a/lib/models/nutrition/weight_unit.g.dart b/lib/models/nutrition/weight_unit.g.dart index 6f2b9607e..74e1f0cfb 100644 --- a/lib/models/nutrition/weight_unit.g.dart +++ b/lib/models/nutrition/weight_unit.g.dart @@ -17,7 +17,8 @@ WeightUnit _$WeightUnitFromJson(Map json) { ); } -Map _$WeightUnitToJson(WeightUnit instance) => { +Map _$WeightUnitToJson(WeightUnit instance) => + { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/repetition_unit.g.dart b/lib/models/workouts/repetition_unit.g.dart index 33e6a815e..115dc338c 100644 --- a/lib/models/workouts/repetition_unit.g.dart +++ b/lib/models/workouts/repetition_unit.g.dart @@ -17,7 +17,8 @@ RepetitionUnit _$RepetitionUnitFromJson(Map json) { ); } -Map _$RepetitionUnitToJson(RepetitionUnit instance) => { +Map _$RepetitionUnitToJson(RepetitionUnit instance) => + { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/session.g.dart b/lib/models/workouts/session.g.dart index 79f4fee41..e16affadb 100644 --- a/lib/models/workouts/session.g.dart +++ b/lib/models/workouts/session.g.dart @@ -9,7 +9,14 @@ part of 'session.dart'; WorkoutSession _$WorkoutSessionFromJson(Map json) { $checkKeys( json, - requiredKeys: const ['id', 'workout', 'date', 'impression', 'time_start', 'time_end'], + requiredKeys: const [ + 'id', + 'workout', + 'date', + 'impression', + 'time_start', + 'time_end' + ], ); return WorkoutSession() ..id = json['id'] as int? @@ -21,7 +28,8 @@ WorkoutSession _$WorkoutSessionFromJson(Map json) { ..timeEnd = stringToTime(json['time_end'] as String?); } -Map _$WorkoutSessionToJson(WorkoutSession instance) => { +Map _$WorkoutSessionToJson(WorkoutSession instance) => + { 'id': instance.id, 'workout': instance.workoutId, 'date': toDate(instance.date), diff --git a/lib/models/workouts/weight_unit.g.dart b/lib/models/workouts/weight_unit.g.dart index 6f2b9607e..74e1f0cfb 100644 --- a/lib/models/workouts/weight_unit.g.dart +++ b/lib/models/workouts/weight_unit.g.dart @@ -17,7 +17,8 @@ WeightUnit _$WeightUnitFromJson(Map json) { ); } -Map _$WeightUnitToJson(WeightUnit instance) => { +Map _$WeightUnitToJson(WeightUnit instance) => + { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/workout_plan.g.dart b/lib/models/workouts/workout_plan.g.dart index ac1d6fa9f..ef156e3e0 100644 --- a/lib/models/workouts/workout_plan.g.dart +++ b/lib/models/workouts/workout_plan.g.dart @@ -19,7 +19,8 @@ WorkoutPlan _$WorkoutPlanFromJson(Map json) { ); } -Map _$WorkoutPlanToJson(WorkoutPlan instance) => { +Map _$WorkoutPlanToJson(WorkoutPlan instance) => + { 'id': instance.id, 'creation_date': instance.creationDate.toIso8601String(), 'name': instance.name, diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index c0685cc5f..3ade66097 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -25,6 +25,7 @@ import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; import 'package:wger/exceptions/http_exception.dart'; import 'package:wger/helpers/consts.dart'; +import 'package:wger/models/nutrition/image.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/log.dart'; import 'package:wger/models/nutrition/meal.dart'; @@ -41,6 +42,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { static const _ingredientPath = 'ingredient'; static const _ingredientSearchPath = 'ingredient/search'; static const _nutritionDiaryPath = 'nutritiondiary'; + static const _ingredientImagePath = 'ingredient-image'; List _plans = []; List _ingredients = []; @@ -135,7 +137,14 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { for (final mealItemData in mealData['meal_items']) { final mealItem = MealItem.fromJson(mealItemData); - mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId); + + final ingredient = Ingredient.fromJson(mealItemData['ingredient_obj']); + if (mealItemData['image'] != null) { + final image = IngredientImage.fromJson(mealItemData['image']); + ingredient.image = image; + } + mealItem.ingredientObj = ingredient; + //mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId); mealItems.add(mealItem); } meal.mealItems = mealItems; diff --git a/lib/widgets/core/core.dart b/lib/widgets/core/core.dart index c8ba0f5c2..9ac1887f4 100644 --- a/lib/widgets/core/core.dart +++ b/lib/widgets/core/core.dart @@ -37,3 +37,24 @@ class MutedText extends StatelessWidget { ); } } + +class CircleIconAvatar extends StatelessWidget { + final double radius; + final Icon _icon; + + final Color color; + + const CircleIconAvatar(this._icon, {this.radius = 20, this.color = Colors.black12}); + + @override + Widget build(BuildContext context) { + return CircleAvatar( + backgroundColor: color, + radius: radius, + child: ClipRRect( + borderRadius: BorderRadius.circular(50.0), + child: _icon, + ), + ); + } +} diff --git a/lib/widgets/nutrition/helpers.dart b/lib/widgets/nutrition/helpers.dart index 670e1b174..9aede4fad 100644 --- a/lib/widgets/nutrition/helpers.dart +++ b/lib/widgets/nutrition/helpers.dart @@ -17,29 +17,29 @@ */ import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:wger/models/nutrition/nutritional_values.dart'; -import 'package:wger/widgets/core/core.dart'; List getMutedNutritionalValues(NutritionalValues values, BuildContext context) { final List out = [ - MutedText( + Text( '${AppLocalizations.of(context).energy}: ' '${values.energy.toStringAsFixed(0)}' '${AppLocalizations.of(context).kcal}', ), - MutedText( + Text( '${AppLocalizations.of(context).protein}: ' '${values.protein.toStringAsFixed(0)}' '${AppLocalizations.of(context).g}', ), - MutedText( + Text( '${AppLocalizations.of(context).carbohydrates}: ' '${values.carbohydrates.toStringAsFixed(0)} ' '${AppLocalizations.of(context).g} ' '(${values.carbohydratesSugar.toStringAsFixed(0)} ${AppLocalizations.of(context).sugars})', ), - MutedText( + Text( '${AppLocalizations.of(context).fat}: ' '${values.fat.toStringAsFixed(0)}' '${AppLocalizations.of(context).g} ' diff --git a/lib/widgets/nutrition/meal.dart b/lib/widgets/nutrition/meal.dart index 432a52d1c..c0d8bff03 100644 --- a/lib/widgets/nutrition/meal.dart +++ b/lib/widgets/nutrition/meal.dart @@ -25,6 +25,7 @@ import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/providers/nutrition.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/theme/theme.dart'; +import 'package:wger/widgets/core/core.dart'; import 'package:wger/widgets/nutrition/forms.dart'; import 'package:wger/widgets/nutrition/helpers.dart'; @@ -160,46 +161,37 @@ class MealItemWidget extends StatelessWidget { final String unit = AppLocalizations.of(context).g; final values = _item.nutritionalValues; - return Container( - padding: const EdgeInsets.all(5), - child: Column( + return ListTile( + leading: _item.ingredientObj.image != null + ? CircleAvatar(backgroundImage: NetworkImage(_item.ingredientObj.image!.image)) + : const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)), + title: Text( + '${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredientObj.name}', + overflow: TextOverflow.ellipsis, + ), + subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: double.infinity, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: Text( - '${_item.amount.toStringAsFixed(0)}$unit ${_item.ingredientObj.name}', - overflow: TextOverflow.ellipsis, - )), - if (_expanded) - IconButton( - icon: const Icon(Icons.delete), - iconSize: ICON_SIZE_SMALL, - onPressed: () { - // Delete the meal item - Provider.of(context, listen: false) - .deleteMealItem(_item); - - // and inform the user - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).successfullyDeleted, - textAlign: TextAlign.center, - )), - ); - }, - ), - ], - ), - ), - if (_expanded) ...getMutedNutritionalValues(values, context), - ], + children: [if (_expanded) ...getMutedNutritionalValues(values, context)], ), + trailing: _expanded + ? IconButton( + icon: const Icon(Icons.delete), + iconSize: ICON_SIZE_SMALL, + onPressed: () { + // Delete the meal item + Provider.of(context, listen: false).deleteMealItem(_item); + + // and inform the user + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + )), + ); + }, + ) + : const SizedBox(), ); } } diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index f8f6776fe..c74ed495e 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -74,7 +74,11 @@ class _IngredientTypeaheadState extends State { ); }, itemBuilder: (context, dynamic suggestion) { + final url = context.read().auth.serverUrl; return ListTile( + leading: suggestion['data']['image'] != null + ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) + : const Icon(Icons.image), title: Text(suggestion['value']), subtitle: Text(suggestion['data']['id'].toString()), ); diff --git a/pubspec.lock b/pubspec.lock index 0825ecad6..fe04df3ad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "38.0.0" + version: "44.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "3.4.1" + version: "4.4.0" android_metadata: dependency: "direct main" description: @@ -28,14 +28,14 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "3.3.0" + version: "3.3.1" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.3.1" async: dependency: transitive description: @@ -77,7 +77,7 @@ packages: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.9" build_runner: dependency: "direct dev" description: @@ -105,28 +105,28 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "8.4.0" camera: dependency: "direct main" description: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.10.0" + version: "0.10.0+1" camera_android: dependency: transitive description: name: camera_android url: "https://pub.dartlang.org" source: hosted - version: "0.10.0" + version: "0.10.0+1" camera_avfoundation: dependency: transitive description: name: camera_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+1" + version: "0.9.8+3" camera_platform_interface: dependency: transitive description: @@ -189,7 +189,7 @@ packages: name: chewie url: "https://pub.dartlang.org" source: hosted - version: "1.3.2" + version: "1.3.4" chewie_audio: dependency: transitive description: @@ -224,7 +224,7 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.2.0" collection: dependency: "direct main" description: @@ -238,14 +238,14 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" cross_file: dependency: transitive description: name: cross_file url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.3+1" crypto: dependency: transitive description: @@ -259,7 +259,7 @@ packages: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.17.1" + version: "0.17.2" cupertino_icons: dependency: "direct main" description: @@ -294,7 +294,7 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "2.0.1" file: dependency: transitive description: @@ -308,7 +308,7 @@ packages: name: fixnum url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1" flutter: dependency: "direct main" description: flutter @@ -341,7 +341,7 @@ packages: name: flutter_keyboard_visibility url: "https://pub.dartlang.org" source: hosted - version: "5.2.0" + version: "5.3.0" flutter_keyboard_visibility_platform_interface: dependency: transitive description: @@ -395,7 +395,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.7" flutter_svg: dependency: transitive description: @@ -433,14 +433,14 @@ packages: name: frontend_server_client url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" graphs: dependency: transitive description: @@ -468,14 +468,14 @@ packages: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.2.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" image: dependency: transitive description: @@ -489,35 +489,35 @@ packages: name: image_picker url: "https://pub.dartlang.org" source: hosted - version: "0.8.5" + version: "0.8.5+3" image_picker_android: dependency: transitive description: name: image_picker_android url: "https://pub.dartlang.org" source: hosted - version: "0.8.4+11" + version: "0.8.5+2" image_picker_for_web: dependency: transitive description: name: image_picker_for_web url: "https://pub.dartlang.org" source: hosted - version: "2.1.6" + version: "2.1.8" image_picker_ios: dependency: transitive description: name: image_picker_ios url: "https://pub.dartlang.org" source: hosted - version: "0.8.5" + version: "0.8.5+6" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.4.4" + version: "2.6.1" intl: dependency: "direct main" description: @@ -650,7 +650,7 @@ packages: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" package_info: dependency: "direct main" description: @@ -685,28 +685,28 @@ packages: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.7" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.2" petitparser: dependency: transitive description: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "4.4.0" + version: "5.0.0" platform: dependency: transitive description: @@ -727,7 +727,7 @@ packages: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.5.1" process: dependency: transitive description: @@ -790,28 +790,28 @@ packages: name: shared_preferences_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" + version: "2.0.12" shared_preferences_ios: dependency: transitive description: name: shared_preferences_ios url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" shared_preferences_platform_interface: dependency: transitive description: @@ -825,28 +825,28 @@ packages: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.4" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.2" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" simple_gesture_detector: dependency: transitive description: @@ -949,7 +949,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" url_launcher: dependency: "direct main" description: @@ -963,28 +963,28 @@ packages: name: url_launcher_android url: "https://pub.dartlang.org" source: hosted - version: "6.0.16" + version: "6.0.17" url_launcher_ios: dependency: transitive description: name: url_launcher_ios url: "https://pub.dartlang.org" source: hosted - version: "6.0.15" + version: "6.0.17" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" url_launcher_platform_interface: dependency: transitive description: @@ -998,14 +998,14 @@ packages: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.13" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" vector_math: dependency: transitive description: @@ -1027,55 +1027,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.0" - very_good_analysis: - dependency: transitive - description: - name: very_good_analysis - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" video_player: dependency: "direct main" description: name: video_player url: "https://pub.dartlang.org" source: hosted - version: "2.4.5" + version: "2.4.6" video_player_android: dependency: transitive description: name: video_player_android url: "https://pub.dartlang.org" source: hosted - version: "2.3.6" + version: "2.3.8" video_player_avfoundation: dependency: transitive description: name: video_player_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "2.3.3" + version: "2.3.5" video_player_platform_interface: dependency: transitive description: name: video_player_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.1.2" + version: "5.1.4" video_player_web: dependency: transitive description: name: video_player_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.12" wakelock: dependency: transitive description: name: wakelock url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+2" + version: "0.6.2" wakelock_macos: dependency: transitive description: @@ -1131,28 +1124,28 @@ packages: name: webview_flutter_android url: "https://pub.dartlang.org" source: hosted - version: "2.8.6" + version: "2.9.3" webview_flutter_platform_interface: dependency: transitive description: name: webview_flutter_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.1" webview_flutter_wkwebview: dependency: transitive description: name: webview_flutter_wkwebview url: "https://pub.dartlang.org" source: hosted - version: "2.7.3" + version: "2.9.3" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.5.2" + version: "2.7.0" xdg_directories: dependency: transitive description: @@ -1166,14 +1159,14 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.3.1" + version: "5.4.1" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "3.1.1" sdks: - dart: ">=2.17.0-206.0.dev <3.0.0" - flutter: ">=2.10.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=3.0.0" diff --git a/test/gallery/gallery_screen_test.mocks.dart b/test/gallery/gallery_screen_test.mocks.dart index 89ded6c37..ddb3db40d 100644 --- a/test/gallery/gallery_screen_test.mocks.dart +++ b/test/gallery/gallery_screen_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/gallery/gallery_screen_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i6; import 'dart:ui' as _i8; @@ -12,6 +13,7 @@ import 'package:wger/models/gallery/image.dart' as _i5; import 'package:wger/providers/auth.dart' as _i2; import 'package:wger/providers/gallery.dart' as _i4; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -20,14 +22,27 @@ import 'package:wger/providers/gallery.dart' as _i4; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.Fake implements _i2.AuthProvider {} +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeClient_1 extends _i1.Fake implements _i3.Client {} +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeUri_2 extends _i1.Fake implements Uri {} +class _FakeUri_2 extends _i1.SmartFake implements Uri { + _FakeUri_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeResponse_3 extends _i1.Fake implements _i3.Response {} +class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [GalleryProvider]. /// @@ -38,87 +53,110 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider { } @override - List<_i5.Image> get images => - (super.noSuchMethod(Invocation.getter(#images), returnValue: <_i5.Image>[]) - as List<_i5.Image>); + List<_i5.Image> get images => (super.noSuchMethod(Invocation.getter(#images), + returnValue: <_i5.Image>[]) as List<_i5.Image>); @override set images(List<_i5.Image>? _images) => - super.noSuchMethod(Invocation.setter(#images, _images), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#images, _images), + returnValueForMissingStub: null); @override - _i2.AuthProvider get auth => - (super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider_0()) - as _i2.AuthProvider); + _i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth))) + as _i2.AuthProvider); @override set auth(_i2.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#auth, _auth), + returnValueForMissingStub: null); @override - _i3.Client get client => - (super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient_1()) as _i3.Client); + _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_1(this, Invocation.getter(#client))) + as _i3.Client); @override set client(_i3.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#client, _client), + returnValueForMissingStub: null); @override bool get hasListeners => - (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool); + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - void clear() => - super.noSuchMethod(Invocation.method(#clear, []), returnValueForMissingStub: null); + void clear() => super.noSuchMethod(Invocation.method(#clear, []), + returnValueForMissingStub: null); @override - _i6.Future fetchAndSetGallery() => - (super.noSuchMethod(Invocation.method(#fetchAndSetGallery, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + _i6.Future fetchAndSetGallery() => (super.noSuchMethod( + Invocation.method(#fetchAndSetGallery, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); @override _i6.Future addImage(_i5.Image? image, _i7.XFile? imageFile) => (super.noSuchMethod(Invocation.method(#addImage, [image, imageFile]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) + as _i6.Future); @override _i6.Future editImage(_i5.Image? image, _i7.XFile? imageFile) => (super.noSuchMethod(Invocation.method(#editImage, [image, imageFile]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) + as _i6.Future); @override - _i6.Future deleteImage(_i5.Image? image) => - (super.noSuchMethod(Invocation.method(#deleteImage, [image]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + _i6.Future deleteImage(_i5.Image? image) => (super.noSuchMethod( + Invocation.method(#deleteImage, [image]), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); @override - Uri makeUrl(String? path, {int? id, String? objectMethod, Map? query}) => + Uri makeUrl(String? path, + {int? id, String? objectMethod, Map? query}) => (super.noSuchMethod( - Invocation.method( - #makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_2()) as Uri); + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), + returnValue: _FakeUri_2( + this, + Invocation.method(#makeUrl, [ + path + ], { + #id: id, + #objectMethod: objectMethod, + #query: query + }))) as Uri); @override _i6.Future> fetch(Uri? uri) => (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override _i6.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override - _i6.Future> patch(Map? data, Uri? uri) => + _i6.Future> patch( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override _i6.Future<_i3.Response> deleteRequest(String? url, int? id) => (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), - returnValue: Future<_i3.Response>.value(_FakeResponse_3())) as _i6.Future<_i3.Response>); + returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_3( + this, Invocation.method(#deleteRequest, [url, id])))) + as _i6.Future<_i3.Response>); @override - void addListener(_i8.VoidCallback? listener) => super - .noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); + void addListener(_i8.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); @override void removeListener(_i8.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override - void dispose() => - super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null); + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); @override void notifyListeners() => - super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); } diff --git a/test/measurements/measurement_categories_screen_test.mocks.dart b/test/measurements/measurement_categories_screen_test.mocks.dart index 99391efb3..c84f720d3 100644 --- a/test/measurements/measurement_categories_screen_test.mocks.dart +++ b/test/measurements/measurement_categories_screen_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/measurements/measurement_categories_screen_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i5; import 'dart:ui' as _i7; @@ -11,6 +12,7 @@ import 'package:wger/models/measurements/measurement_entry.dart' as _i6; import 'package:wger/providers/base_provider.dart' as _i2; import 'package:wger/providers/measurement.dart' as _i4; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -19,95 +21,118 @@ import 'package:wger/providers/measurement.dart' as _i4; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeWgerBaseProvider_0 extends _i1.Fake implements _i2.WgerBaseProvider {} +class _FakeWgerBaseProvider_0 extends _i1.SmartFake + implements _i2.WgerBaseProvider { + _FakeWgerBaseProvider_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeMeasurementCategory_1 extends _i1.Fake implements _i3.MeasurementCategory {} +class _FakeMeasurementCategory_1 extends _i1.SmartFake + implements _i3.MeasurementCategory { + _FakeMeasurementCategory_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [MeasurementProvider]. /// /// See the documentation for Mockito's code generation for more information. -class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvider { +class MockMeasurementProvider extends _i1.Mock + implements _i4.MeasurementProvider { MockMeasurementProvider() { _i1.throwOnMissingStub(this); } @override - _i2.WgerBaseProvider get baseProvider => - (super.noSuchMethod(Invocation.getter(#baseProvider), returnValue: _FakeWgerBaseProvider_0()) - as _i2.WgerBaseProvider); + _i2.WgerBaseProvider get baseProvider => (super.noSuchMethod( + Invocation.getter(#baseProvider), + returnValue: + _FakeWgerBaseProvider_0(this, Invocation.getter(#baseProvider))) + as _i2.WgerBaseProvider); @override List<_i3.MeasurementCategory> get categories => - (super.noSuchMethod(Invocation.getter(#categories), returnValue: <_i3.MeasurementCategory>[]) + (super.noSuchMethod(Invocation.getter(#categories), + returnValue: <_i3.MeasurementCategory>[]) as List<_i3.MeasurementCategory>); @override bool get hasListeners => - (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool); + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - void clear() => - super.noSuchMethod(Invocation.method(#clear, []), returnValueForMissingStub: null); + void clear() => super.noSuchMethod(Invocation.method(#clear, []), + returnValueForMissingStub: null); @override _i3.MeasurementCategory findCategoryById(int? id) => (super.noSuchMethod(Invocation.method(#findCategoryById, [id]), - returnValue: _FakeMeasurementCategory_1()) as _i3.MeasurementCategory); + returnValue: _FakeMeasurementCategory_1( + this, Invocation.method(#findCategoryById, [id]))) + as _i3.MeasurementCategory); @override - _i5.Future fetchAndSetCategories() => - (super.noSuchMethod(Invocation.method(#fetchAndSetCategories, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); + _i5.Future fetchAndSetCategories() => (super.noSuchMethod( + Invocation.method(#fetchAndSetCategories, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); @override - _i5.Future fetchAndSetCategoryEntries(int? id) => - (super.noSuchMethod(Invocation.method(#fetchAndSetCategoryEntries, [id]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); + _i5.Future fetchAndSetCategoryEntries(int? id) => (super.noSuchMethod( + Invocation.method(#fetchAndSetCategoryEntries, [id]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); @override - _i5.Future fetchAndSetAllCategoriesAndEntries() => - (super.noSuchMethod(Invocation.method(#fetchAndSetAllCategoriesAndEntries, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); + _i5.Future fetchAndSetAllCategoriesAndEntries() => (super.noSuchMethod( + Invocation.method(#fetchAndSetAllCategoriesAndEntries, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); @override _i5.Future addCategory(_i3.MeasurementCategory? category) => (super.noSuchMethod(Invocation.method(#addCategory, [category]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); @override - _i5.Future deleteCategory(int? id) => - (super.noSuchMethod(Invocation.method(#deleteCategory, [id]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); + _i5.Future deleteCategory(int? id) => (super.noSuchMethod( + Invocation.method(#deleteCategory, [id]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); @override _i5.Future editCategory(int? id, String? newName, String? newUnit) => - (super.noSuchMethod(Invocation.method(#editCategory, [id, newName, newUnit]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); - @override - _i5.Future addEntry(_i6.MeasurementEntry? entry) => - (super.noSuchMethod(Invocation.method(#addEntry, [entry]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); - @override - _i5.Future deleteEntry(int? id, int? categoryId) => - (super.noSuchMethod(Invocation.method(#deleteEntry, [id, categoryId]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); - @override - _i5.Future editEntry( - int? id, int? categoryId, num? newValue, String? newNotes, DateTime? newDate) => (super.noSuchMethod( - Invocation.method(#editEntry, [id, categoryId, newValue, newNotes, newDate]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i5.Future); - @override - void addListener(_i7.VoidCallback? listener) => super - .noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); + Invocation.method(#editCategory, [id, newName, newUnit]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future addEntry(_i6.MeasurementEntry? entry) => (super.noSuchMethod( + Invocation.method(#addEntry, [entry]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future deleteEntry(int? id, int? categoryId) => (super.noSuchMethod( + Invocation.method(#deleteEntry, [id, categoryId]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future editEntry(int? id, int? categoryId, num? newValue, + String? newNotes, DateTime? newDate) => + (super.noSuchMethod( + Invocation.method( + #editEntry, [id, categoryId, newValue, newNotes, newDate]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + void addListener(_i7.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); @override void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override - void dispose() => - super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null); + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); @override void notifyListeners() => - super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); } diff --git a/test/measurements/measurement_provider_test.mocks.dart b/test/measurements/measurement_provider_test.mocks.dart index 67ccb658c..02510353d 100644 --- a/test/measurements/measurement_provider_test.mocks.dart +++ b/test/measurements/measurement_provider_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/measurements/measurement_provider_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i5; import 'package:http/http.dart' as _i3; @@ -9,6 +10,7 @@ import 'package:mockito/mockito.dart' as _i1; import 'package:wger/providers/auth.dart' as _i2; import 'package:wger/providers/base_provider.dart' as _i4; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -17,14 +19,27 @@ import 'package:wger/providers/base_provider.dart' as _i4; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.Fake implements _i2.AuthProvider {} +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeClient_1 extends _i1.Fake implements _i3.Client {} +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeUri_2 extends _i1.Fake implements Uri {} +class _FakeUri_2 extends _i1.SmartFake implements Uri { + _FakeUri_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeResponse_3 extends _i1.Fake implements _i3.Response {} +class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [WgerBaseProvider]. /// @@ -35,41 +50,59 @@ class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider { } @override - _i2.AuthProvider get auth => - (super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider_0()) - as _i2.AuthProvider); + _i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth))) + as _i2.AuthProvider); @override set auth(_i2.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#auth, _auth), + returnValueForMissingStub: null); @override - _i3.Client get client => - (super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient_1()) as _i3.Client); + _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_1(this, Invocation.getter(#client))) + as _i3.Client); @override set client(_i3.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#client, _client), + returnValueForMissingStub: null); @override - Uri makeUrl(String? path, {int? id, String? objectMethod, Map? query}) => + Uri makeUrl(String? path, + {int? id, String? objectMethod, Map? query}) => (super.noSuchMethod( - Invocation.method( - #makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_2()) as Uri); + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), + returnValue: _FakeUri_2( + this, + Invocation.method(#makeUrl, [ + path + ], { + #id: id, + #objectMethod: objectMethod, + #query: query + }))) as Uri); @override _i5.Future> fetch(Uri? uri) => (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) + returnValue: + _i5.Future>.value({})) as _i5.Future>); @override _i5.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i5.Future>.value({})) as _i5.Future>); @override - _i5.Future> patch(Map? data, Uri? uri) => + _i5.Future> patch( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i5.Future>.value({})) as _i5.Future>); @override _i5.Future<_i3.Response> deleteRequest(String? url, int? id) => (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), - returnValue: Future<_i3.Response>.value(_FakeResponse_3())) as _i5.Future<_i3.Response>); + returnValue: _i5.Future<_i3.Response>.value(_FakeResponse_3( + this, Invocation.method(#deleteRequest, [url, id])))) + as _i5.Future<_i3.Response>); } diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index b9f6dda42..b4b9895b8 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/nutrition/nutritional_plan_form_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i9; import 'dart:ui' as _i10; @@ -14,6 +15,7 @@ import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; import 'package:wger/providers/auth.dart' as _i2; import 'package:wger/providers/nutrition.dart' as _i8; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -22,191 +24,265 @@ import 'package:wger/providers/nutrition.dart' as _i8; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.Fake implements _i2.AuthProvider {} +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeClient_1 extends _i1.Fake implements _i3.Client {} +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeNutritionalPlan_2 extends _i1.Fake implements _i4.NutritionalPlan {} +class _FakeNutritionalPlan_2 extends _i1.SmartFake + implements _i4.NutritionalPlan { + _FakeNutritionalPlan_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeMeal_3 extends _i1.Fake implements _i5.Meal {} +class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { + _FakeMeal_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeMealItem_4 extends _i1.Fake implements _i6.MealItem {} +class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem { + _FakeMealItem_4(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeIngredient_5 extends _i1.Fake implements _i7.Ingredient {} +class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient { + _FakeIngredient_5(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeUri_6 extends _i1.Fake implements Uri {} +class _FakeUri_6 extends _i1.SmartFake implements Uri { + _FakeUri_6(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeResponse_7 extends _i1.Fake implements _i3.Response {} +class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_7(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [NutritionPlansProvider]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansProvider { +class MockNutritionPlansProvider extends _i1.Mock + implements _i8.NutritionPlansProvider { MockNutritionPlansProvider() { _i1.throwOnMissingStub(this); } @override List<_i4.NutritionalPlan> get items => - (super.noSuchMethod(Invocation.getter(#items), returnValue: <_i4.NutritionalPlan>[]) - as List<_i4.NutritionalPlan>); + (super.noSuchMethod(Invocation.getter(#items), + returnValue: <_i4.NutritionalPlan>[]) as List<_i4.NutritionalPlan>); @override - _i2.AuthProvider get auth => - (super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider_0()) - as _i2.AuthProvider); + _i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth))) + as _i2.AuthProvider); @override set auth(_i2.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#auth, _auth), + returnValueForMissingStub: null); @override - _i3.Client get client => - (super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient_1()) as _i3.Client); + _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_1(this, Invocation.getter(#client))) + as _i3.Client); @override set client(_i3.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#client, _client), + returnValueForMissingStub: null); @override bool get hasListeners => - (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool); + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - void clear() => - super.noSuchMethod(Invocation.method(#clear, []), returnValueForMissingStub: null); + void clear() => super.noSuchMethod(Invocation.method(#clear, []), + returnValueForMissingStub: null); @override - _i4.NutritionalPlan findById(int? id) => - (super.noSuchMethod(Invocation.method(#findById, [id]), returnValue: _FakeNutritionalPlan_2()) - as _i4.NutritionalPlan); + _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + Invocation.method(#findById, [id]), + returnValue: + _FakeNutritionalPlan_2(this, Invocation.method(#findById, [id]))) + as _i4.NutritionalPlan); @override _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?); @override - _i9.Future fetchAndSetAllPlansSparse() => - (super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansSparse, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( + Invocation.method(#fetchAndSetAllPlansSparse, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future fetchAndSetAllPlansFull() => - (super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansFull, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + Invocation.method(#fetchAndSetAllPlansFull, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]), - returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) + returnValue: _i9.Future<_i4.NutritionalPlan>.value( + _FakeNutritionalPlan_2(this, + Invocation.method(#fetchAndSetPlanSparse, [planId])))) as _i9.Future<_i4.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => - (super.noSuchMethod(Invocation.method(#fetchAndSetPlanFull, [planId]), - returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) - as _i9.Future<_i4.NutritionalPlan>); + _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super + .noSuchMethod(Invocation.method(#fetchAndSetPlanFull, [planId]), + returnValue: _i9.Future<_i4.NutritionalPlan>.value( + _FakeNutritionalPlan_2( + this, Invocation.method(#fetchAndSetPlanFull, [planId])))) + as _i9.Future<_i4.NutritionalPlan>); @override _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod(Invocation.method(#addPlan, [planData]), - returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) + returnValue: _i9.Future<_i4.NutritionalPlan>.value( + _FakeNutritionalPlan_2( + this, Invocation.method(#addPlan, [planData])))) as _i9.Future<_i4.NutritionalPlan>); @override - _i9.Future editPlan(_i4.NutritionalPlan? plan) => - (super.noSuchMethod(Invocation.method(#editPlan, [plan]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + Invocation.method(#editPlan, [plan]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod(Invocation.method(#deletePlan, [id]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future deletePlan(int? id) => (super.noSuchMethod( + Invocation.method(#deletePlan, [id]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) => (super.noSuchMethod(Invocation.method(#addMeal, [meal, planId]), - returnValue: Future<_i5.Meal>.value(_FakeMeal_3())) as _i9.Future<_i5.Meal>); + returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + this, Invocation.method(#addMeal, [meal, planId])))) + as _i9.Future<_i5.Meal>); @override _i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod(Invocation.method(#editMeal, [meal]), - returnValue: Future<_i5.Meal>.value(_FakeMeal_3())) as _i9.Future<_i5.Meal>); + returnValue: _i9.Future<_i5.Meal>.value( + _FakeMeal_3(this, Invocation.method(#editMeal, [meal])))) + as _i9.Future<_i5.Meal>); @override - _i9.Future deleteMeal(_i5.Meal? meal) => - (super.noSuchMethod(Invocation.method(#deleteMeal, [meal]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future deleteMeal(_i5.Meal? meal) => (super.noSuchMethod( + Invocation.method(#deleteMeal, [meal]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future<_i6.MealItem> addMealItem(_i6.MealItem? mealItem, _i5.Meal? meal) => + _i9.Future<_i6.MealItem> addMealItem( + _i6.MealItem? mealItem, _i5.Meal? meal) => (super.noSuchMethod(Invocation.method(#addMealItem, [mealItem, meal]), - returnValue: Future<_i6.MealItem>.value(_FakeMealItem_4())) as _i9.Future<_i6.MealItem>); + returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4( + this, Invocation.method(#addMealItem, [mealItem, meal])))) + as _i9.Future<_i6.MealItem>); @override _i9.Future deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(Invocation.method(#deleteMealItem, [mealItem]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(Invocation.method(#fetchIngredient, [ingredientId]), - returnValue: Future<_i7.Ingredient>.value(_FakeIngredient_5())) + returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5( + this, Invocation.method(#fetchIngredient, [ingredientId])))) as _i9.Future<_i7.Ingredient>); @override - _i9.Future fetchIngredientsFromCache() => - (super.noSuchMethod(Invocation.method(#fetchIngredientsFromCache, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future fetchIngredientsFromCache() => (super.noSuchMethod( + Invocation.method(#fetchIngredientsFromCache, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future> searchIngredient(String? name, [String? languageCode = r'en']) => - (super.noSuchMethod(Invocation.method(#searchIngredient, [name, languageCode]), - returnValue: Future>.value([])) as _i9.Future>); + _i9.Future> searchIngredient(String? name, + [String? languageCode = r'en']) => + (super.noSuchMethod( + Invocation.method(#searchIngredient, [name, languageCode]), + returnValue: _i9.Future>.value([])) + as _i9.Future>); @override _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(Invocation.method(#searchIngredientWithCode, [code]), - returnValue: Future<_i7.Ingredient?>.value()) as _i9.Future<_i7.Ingredient?>); + returnValue: _i9.Future<_i7.Ingredient?>.value()) + as _i9.Future<_i7.Ingredient?>); @override - _i9.Future logMealToDiary(_i5.Meal? meal) => - (super.noSuchMethod(Invocation.method(#logMealToDiary, [meal]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod( + Invocation.method(#logMealToDiary, [meal]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future logIngredentToDiary(_i6.MealItem? mealItem, int? planId, [DateTime? dateTime]) => - (super.noSuchMethod(Invocation.method(#logIngredentToDiary, [mealItem, planId, dateTime]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future logIngredentToDiary(_i6.MealItem? mealItem, int? planId, + [DateTime? dateTime]) => + (super.noSuchMethod( + Invocation.method(#logIngredentToDiary, [mealItem, planId, dateTime]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: + _i9.Future.value()) as _i9.Future); @override - _i9.Future deleteLog(int? logId, int? planId) => - (super.noSuchMethod(Invocation.method(#deleteLog, [logId, planId]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future deleteLog(int? logId, int? planId) => (super.noSuchMethod( + Invocation.method(#deleteLog, [logId, planId]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod(Invocation.method(#fetchAndSetLogs, [plan]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override - Uri makeUrl(String? path, {int? id, String? objectMethod, Map? query}) => + Uri makeUrl(String? path, + {int? id, String? objectMethod, Map? query}) => (super.noSuchMethod( - Invocation.method( - #makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_6()) as Uri); + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), + returnValue: _FakeUri_6( + this, + Invocation.method(#makeUrl, [ + path + ], { + #id: id, + #objectMethod: objectMethod, + #query: query + }))) as Uri); @override _i9.Future> fetch(Uri? uri) => (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) + returnValue: + _i9.Future>.value({})) as _i9.Future>); @override _i9.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i9.Future>.value({})) as _i9.Future>); @override - _i9.Future> patch(Map? data, Uri? uri) => + _i9.Future> patch( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i9.Future>.value({})) as _i9.Future>); @override _i9.Future<_i3.Response> deleteRequest(String? url, int? id) => (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), - returnValue: Future<_i3.Response>.value(_FakeResponse_7())) as _i9.Future<_i3.Response>); + returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7( + this, Invocation.method(#deleteRequest, [url, id])))) + as _i9.Future<_i3.Response>); @override - void addListener(_i10.VoidCallback? listener) => super - .noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); + void addListener(_i10.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); @override void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override - void dispose() => - super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null); + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); @override void notifyListeners() => - super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); } diff --git a/test/other/base_provider_test.mocks.dart b/test/other/base_provider_test.mocks.dart index 59ccffaae..58708581a 100644 --- a/test/other/base_provider_test.mocks.dart +++ b/test/other/base_provider_test.mocks.dart @@ -1,17 +1,16 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/other/base_provider_test.dart. // Do not manually edit this file. -import 'dart:async' as _i5; -import 'dart:convert' as _i6; -import 'dart:typed_data' as _i7; +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; +import 'dart:convert' as _i4; +import 'dart:typed_data' as _i5; -import 'package:http/src/base_request.dart' as _i8; -import 'package:http/src/client.dart' as _i4; -import 'package:http/src/response.dart' as _i2; -import 'package:http/src/streamed_response.dart' as _i3; +import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -20,65 +19,122 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeResponse_0 extends _i1.Fake implements _i2.Response {} +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeStreamedResponse_1 extends _i1.Fake implements _i3.StreamedResponse {} +class _FakeStreamedResponse_1 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [Client]. /// /// See the documentation for Mockito's code generation for more information. -class MockClient extends _i1.Mock implements _i4.Client { +class MockClient extends _i1.Mock implements _i2.Client { MockClient() { _i1.throwOnMissingStub(this); } @override - _i5.Future<_i2.Response> head(Uri? url, {Map? headers}) => + _i3.Future<_i2.Response> head(Uri? url, {Map? headers}) => (super.noSuchMethod(Invocation.method(#head, [url], {#headers: headers}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, Invocation.method(#head, [url], {#headers: headers})))) + as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> get(Uri? url, {Map? headers}) => + _i3.Future<_i2.Response> get(Uri? url, {Map? headers}) => (super.noSuchMethod(Invocation.method(#get, [url], {#headers: headers}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, Invocation.method(#get, [url], {#headers: headers})))) + as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> post(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#post, [url], {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> post(Uri? url, + {Map? headers, + Object? body, + _i4.Encoding? encoding}) => + (super + .noSuchMethod(Invocation.method(#post, [url], {#headers: headers, #body: body, #encoding: encoding}), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method(#post, [ + url + ], { + #headers: headers, + #body: body, + #encoding: encoding + })))) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> put(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#put, [url], {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> put(Uri? url, + {Map? headers, + Object? body, + _i4.Encoding? encoding}) => + (super + .noSuchMethod(Invocation.method(#put, [url], {#headers: headers, #body: body, #encoding: encoding}), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method(#put, [ + url + ], { + #headers: headers, + #body: body, + #encoding: encoding + })))) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> patch(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#patch, [url], {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> patch(Uri? url, + {Map? headers, + Object? body, + _i4.Encoding? encoding}) => + (super + .noSuchMethod(Invocation.method(#patch, [url], {#headers: headers, #body: body, #encoding: encoding}), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method(#patch, [ + url + ], { + #headers: headers, + #body: body, + #encoding: encoding + })))) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> delete(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#delete, [url], {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> delete(Uri? url, + {Map? headers, + Object? body, + _i4.Encoding? encoding}) => + (super + .noSuchMethod(Invocation.method(#delete, [url], {#headers: headers, #body: body, #encoding: encoding}), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method(#delete, [ + url + ], { + #headers: headers, + #body: body, + #encoding: encoding + })))) as _i3.Future<_i2.Response>); @override - _i5.Future read(Uri? url, {Map? headers}) => + _i3.Future read(Uri? url, {Map? headers}) => (super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}), - returnValue: Future.value('')) as _i5.Future); + returnValue: _i3.Future.value('')) as _i3.Future); @override - _i5.Future<_i7.Uint8List> readBytes(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#readBytes, [url], {#headers: headers}), - returnValue: Future<_i7.Uint8List>.value(_i7.Uint8List(0))) as _i5.Future<_i7.Uint8List>); + _i3.Future<_i5.Uint8List> readBytes(Uri? url, + {Map? headers}) => + (super.noSuchMethod( + Invocation.method(#readBytes, [url], {#headers: headers}), + returnValue: _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0))) + as _i3.Future<_i5.Uint8List>); @override - _i5.Future<_i3.StreamedResponse> send(_i8.BaseRequest? request) => + _i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => (super.noSuchMethod(Invocation.method(#send, [request]), - returnValue: Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_1())) - as _i5.Future<_i3.StreamedResponse>); + returnValue: _i3.Future<_i2.StreamedResponse>.value( + _FakeStreamedResponse_1( + this, Invocation.method(#send, [request])))) + as _i3.Future<_i2.StreamedResponse>); @override - void close() => - super.noSuchMethod(Invocation.method(#close, []), returnValueForMissingStub: null); + void close() => super.noSuchMethod(Invocation.method(#close, []), + returnValueForMissingStub: null); } diff --git a/test/workout/workout_form_test.mocks.dart b/test/workout/workout_form_test.mocks.dart index 26464a9ab..017c3ca15 100644 --- a/test/workout/workout_form_test.mocks.dart +++ b/test/workout/workout_form_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/workout/workout_form_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i13; import 'dart:ui' as _i15; @@ -19,6 +20,7 @@ import 'package:wger/models/workouts/workout_plan.dart' as _i6; import 'package:wger/providers/auth.dart' as _i4; import 'package:wger/providers/workout_plans.dart' as _i12; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -27,245 +29,352 @@ import 'package:wger/providers/workout_plans.dart' as _i12; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeWeightUnit_0 extends _i1.Fake implements _i2.WeightUnit {} +class _FakeWeightUnit_0 extends _i1.SmartFake implements _i2.WeightUnit { + _FakeWeightUnit_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeRepetitionUnit_1 extends _i1.Fake implements _i3.RepetitionUnit {} +class _FakeRepetitionUnit_1 extends _i1.SmartFake + implements _i3.RepetitionUnit { + _FakeRepetitionUnit_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeAuthProvider_2 extends _i1.Fake implements _i4.AuthProvider {} +class _FakeAuthProvider_2 extends _i1.SmartFake implements _i4.AuthProvider { + _FakeAuthProvider_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeClient_3 extends _i1.Fake implements _i5.Client {} +class _FakeClient_3 extends _i1.SmartFake implements _i5.Client { + _FakeClient_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeWorkoutPlan_4 extends _i1.Fake implements _i6.WorkoutPlan {} +class _FakeWorkoutPlan_4 extends _i1.SmartFake implements _i6.WorkoutPlan { + _FakeWorkoutPlan_4(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeDay_5 extends _i1.Fake implements _i7.Day {} +class _FakeDay_5 extends _i1.SmartFake implements _i7.Day { + _FakeDay_5(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeSet_6 extends _i1.Fake implements _i8.Set {} +class _FakeSet_6 extends _i1.SmartFake implements _i8.Set { + _FakeSet_6(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeSetting_7 extends _i1.Fake implements _i9.Setting {} +class _FakeSetting_7 extends _i1.SmartFake implements _i9.Setting { + _FakeSetting_7(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeWorkoutSession_8 extends _i1.Fake implements _i10.WorkoutSession {} +class _FakeWorkoutSession_8 extends _i1.SmartFake + implements _i10.WorkoutSession { + _FakeWorkoutSession_8(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeLog_9 extends _i1.Fake implements _i11.Log {} +class _FakeLog_9 extends _i1.SmartFake implements _i11.Log { + _FakeLog_9(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeUri_10 extends _i1.Fake implements Uri {} +class _FakeUri_10 extends _i1.SmartFake implements Uri { + _FakeUri_10(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeResponse_11 extends _i1.Fake implements _i5.Response {} +class _FakeResponse_11 extends _i1.SmartFake implements _i5.Response { + _FakeResponse_11(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [WorkoutPlansProvider]. /// /// See the documentation for Mockito's code generation for more information. -class MockWorkoutPlansProvider extends _i1.Mock implements _i12.WorkoutPlansProvider { +class MockWorkoutPlansProvider extends _i1.Mock + implements _i12.WorkoutPlansProvider { MockWorkoutPlansProvider() { _i1.throwOnMissingStub(this); } @override List<_i6.WorkoutPlan> get items => - (super.noSuchMethod(Invocation.getter(#items), returnValue: <_i6.WorkoutPlan>[]) - as List<_i6.WorkoutPlan>); + (super.noSuchMethod(Invocation.getter(#items), + returnValue: <_i6.WorkoutPlan>[]) as List<_i6.WorkoutPlan>); @override List<_i2.WeightUnit> get weightUnits => - (super.noSuchMethod(Invocation.getter(#weightUnits), returnValue: <_i2.WeightUnit>[]) - as List<_i2.WeightUnit>); + (super.noSuchMethod(Invocation.getter(#weightUnits), + returnValue: <_i2.WeightUnit>[]) as List<_i2.WeightUnit>); @override - _i2.WeightUnit get defaultWeightUnit => - (super.noSuchMethod(Invocation.getter(#defaultWeightUnit), returnValue: _FakeWeightUnit_0()) - as _i2.WeightUnit); + _i2.WeightUnit get defaultWeightUnit => (super.noSuchMethod( + Invocation.getter(#defaultWeightUnit), + returnValue: + _FakeWeightUnit_0(this, Invocation.getter(#defaultWeightUnit))) + as _i2.WeightUnit); @override List<_i3.RepetitionUnit> get repetitionUnits => - (super.noSuchMethod(Invocation.getter(#repetitionUnits), returnValue: <_i3.RepetitionUnit>[]) - as List<_i3.RepetitionUnit>); + (super.noSuchMethod(Invocation.getter(#repetitionUnits), + returnValue: <_i3.RepetitionUnit>[]) as List<_i3.RepetitionUnit>); @override _i3.RepetitionUnit get defaultRepetitionUnit => (super.noSuchMethod(Invocation.getter(#defaultRepetitionUnit), - returnValue: _FakeRepetitionUnit_1()) as _i3.RepetitionUnit); + returnValue: _FakeRepetitionUnit_1( + this, Invocation.getter(#defaultRepetitionUnit))) + as _i3.RepetitionUnit); @override - _i4.AuthProvider get auth => - (super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider_2()) - as _i4.AuthProvider); + _i4.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), + returnValue: _FakeAuthProvider_2(this, Invocation.getter(#auth))) + as _i4.AuthProvider); @override set auth(_i4.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#auth, _auth), + returnValueForMissingStub: null); @override - _i5.Client get client => - (super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient_3()) as _i5.Client); + _i5.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_3(this, Invocation.getter(#client))) + as _i5.Client); @override set client(_i5.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#client, _client), + returnValueForMissingStub: null); @override bool get hasListeners => - (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool); + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - void clear() => - super.noSuchMethod(Invocation.method(#clear, []), returnValueForMissingStub: null); + void clear() => super.noSuchMethod(Invocation.method(#clear, []), + returnValueForMissingStub: null); @override _i6.WorkoutPlan findById(int? id) => - (super.noSuchMethod(Invocation.method(#findById, [id]), returnValue: _FakeWorkoutPlan_4()) + (super.noSuchMethod(Invocation.method(#findById, [id]), + returnValue: + _FakeWorkoutPlan_4(this, Invocation.method(#findById, [id]))) as _i6.WorkoutPlan); @override - int findIndexById(int? id) => - (super.noSuchMethod(Invocation.method(#findIndexById, [id]), returnValue: 0) as int); + int findIndexById(int? id) => (super + .noSuchMethod(Invocation.method(#findIndexById, [id]), returnValue: 0) + as int); @override void setCurrentPlan(int? id) => - super.noSuchMethod(Invocation.method(#setCurrentPlan, [id]), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#setCurrentPlan, [id]), + returnValueForMissingStub: null); @override void resetCurrentPlan() => - super.noSuchMethod(Invocation.method(#resetCurrentPlan, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#resetCurrentPlan, []), + returnValueForMissingStub: null); @override _i13.Future fetchAndSetAllPlansFull() => (super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansFull, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansSparse, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future<_i6.WorkoutPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]), - returnValue: Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4())) - as _i13.Future<_i6.WorkoutPlan>); + returnValue: _i13.Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4( + this, + Invocation.method(#fetchAndSetPlanSparse, [planId])))) as _i13 + .Future<_i6.WorkoutPlan>); @override _i13.Future<_i6.WorkoutPlan> fetchAndSetWorkoutPlanFull(int? workoutId) => - (super.noSuchMethod(Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]), - returnValue: Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4())) - as _i13.Future<_i6.WorkoutPlan>); + (super.noSuchMethod( + Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]), + returnValue: _i13.Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4( + this, + Invocation.method( + #fetchAndSetWorkoutPlanFull, [workoutId])))) as _i13 + .Future<_i6.WorkoutPlan>); @override _i13.Future<_i6.WorkoutPlan> addWorkout(_i6.WorkoutPlan? workout) => (super.noSuchMethod(Invocation.method(#addWorkout, [workout]), - returnValue: Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4())) - as _i13.Future<_i6.WorkoutPlan>); + returnValue: _i13.Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4( + this, Invocation.method(#addWorkout, [workout])))) as _i13 + .Future<_i6.WorkoutPlan>); @override _i13.Future editWorkout(_i6.WorkoutPlan? workout) => (super.noSuchMethod(Invocation.method(#editWorkout, [workout]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future deleteWorkout(int? id) => (super.noSuchMethod(Invocation.method(#deleteWorkout, [id]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future> fetchLogData( _i6.WorkoutPlan? workout, _i14.Exercise? exercise) => (super.noSuchMethod(Invocation.method(#fetchLogData, [workout, exercise]), - returnValue: Future>.value({})) + returnValue: + _i13.Future>.value({})) as _i13.Future>); @override _i13.Future fetchAndSetRepetitionUnits() => (super.noSuchMethod(Invocation.method(#fetchAndSetRepetitionUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future fetchAndSetWeightUnits() => (super.noSuchMethod(Invocation.method(#fetchAndSetWeightUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future fetchAndSetUnits() => (super.noSuchMethod(Invocation.method(#fetchAndSetUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future<_i7.Day> addDay(_i7.Day? day, _i6.WorkoutPlan? workout) => (super.noSuchMethod(Invocation.method(#addDay, [day, workout]), - returnValue: Future<_i7.Day>.value(_FakeDay_5())) as _i13.Future<_i7.Day>); + returnValue: _i13.Future<_i7.Day>.value( + _FakeDay_5(this, Invocation.method(#addDay, [day, workout])))) + as _i13.Future<_i7.Day>); @override - _i13.Future editDay(_i7.Day? day) => (super.noSuchMethod(Invocation.method(#editDay, [day]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future editDay(_i7.Day? day) => + (super.noSuchMethod(Invocation.method(#editDay, [day]), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future deleteDay(_i7.Day? day) => (super.noSuchMethod(Invocation.method(#deleteDay, [day]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future<_i8.Set> addSet(_i8.Set? workoutSet) => (super.noSuchMethod(Invocation.method(#addSet, [workoutSet]), - returnValue: Future<_i8.Set>.value(_FakeSet_6())) as _i13.Future<_i8.Set>); + returnValue: _i13.Future<_i8.Set>.value( + _FakeSet_6(this, Invocation.method(#addSet, [workoutSet])))) + as _i13.Future<_i8.Set>); @override _i13.Future editSet(_i8.Set? workoutSet) => (super.noSuchMethod(Invocation.method(#editSet, [workoutSet]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override - _i13.Future> reorderSets(List<_i8.Set>? sets, int? startIndex) => + _i13.Future> reorderSets( + List<_i8.Set>? sets, int? startIndex) => (super.noSuchMethod(Invocation.method(#reorderSets, [sets, startIndex]), - returnValue: Future>.value(<_i8.Set>[])) as _i13.Future>); + returnValue: _i13.Future>.value(<_i8.Set>[])) + as _i13.Future>); @override - _i13.Future fetchComputedSettings(_i8.Set? workoutSet) => - (super.noSuchMethod(Invocation.method(#fetchComputedSettings, [workoutSet]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future fetchComputedSettings(_i8.Set? workoutSet) => (super + .noSuchMethod(Invocation.method(#fetchComputedSettings, [workoutSet]), + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override - _i13.Future fetchSmartText(_i8.Set? workoutSet, _i14.Exercise? exercise) => - (super.noSuchMethod(Invocation.method(#fetchSmartText, [workoutSet, exercise]), - returnValue: Future.value('')) as _i13.Future); + _i13.Future fetchSmartText( + _i8.Set? workoutSet, _i14.Exercise? exercise) => + (super.noSuchMethod( + Invocation.method(#fetchSmartText, [workoutSet, exercise]), + returnValue: _i13.Future.value('')) as _i13.Future); @override _i13.Future deleteSet(_i8.Set? workoutSet) => (super.noSuchMethod(Invocation.method(#deleteSet, [workoutSet]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override _i13.Future<_i9.Setting> addSetting(_i9.Setting? workoutSetting) => (super.noSuchMethod(Invocation.method(#addSetting, [workoutSetting]), - returnValue: Future<_i9.Setting>.value(_FakeSetting_7())) as _i13.Future<_i9.Setting>); + returnValue: _i13.Future<_i9.Setting>.value(_FakeSetting_7( + this, Invocation.method(#addSetting, [workoutSetting])))) + as _i13.Future<_i9.Setting>); @override _i13.Future fetchSessionData() => (super.noSuchMethod(Invocation.method(#fetchSessionData, []), - returnValue: Future.value()) as _i13.Future); + returnValue: _i13.Future.value()) as _i13.Future); @override _i13.Future<_i10.WorkoutSession> addSession(_i10.WorkoutSession? session) => (super.noSuchMethod(Invocation.method(#addSession, [session]), - returnValue: Future<_i10.WorkoutSession>.value(_FakeWorkoutSession_8())) + returnValue: _i13.Future<_i10.WorkoutSession>.value( + _FakeWorkoutSession_8( + this, Invocation.method(#addSession, [session])))) as _i13.Future<_i10.WorkoutSession>); @override _i13.Future<_i11.Log> addLog(_i11.Log? log) => (super.noSuchMethod(Invocation.method(#addLog, [log]), - returnValue: Future<_i11.Log>.value(_FakeLog_9())) as _i13.Future<_i11.Log>); + returnValue: _i13.Future<_i11.Log>.value( + _FakeLog_9(this, Invocation.method(#addLog, [log])))) + as _i13.Future<_i11.Log>); @override _i13.Future deleteLog(_i11.Log? log) => (super.noSuchMethod(Invocation.method(#deleteLog, [log]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: _i13.Future.value(), + returnValueForMissingStub: _i13.Future.value()) + as _i13.Future); @override - Uri makeUrl(String? path, {int? id, String? objectMethod, Map? query}) => + Uri makeUrl(String? path, + {int? id, String? objectMethod, Map? query}) => (super.noSuchMethod( - Invocation.method( - #makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_10()) as Uri); + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), + returnValue: _FakeUri_10( + this, + Invocation.method(#makeUrl, [ + path + ], { + #id: id, + #objectMethod: objectMethod, + #query: query + }))) as Uri); @override _i13.Future> fetch(Uri? uri) => (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) + returnValue: + _i13.Future>.value({})) as _i13.Future>); @override - _i13.Future> post(Map? data, Uri? uri) => + _i13.Future> post( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i13.Future>.value({})) as _i13.Future>); @override - _i13.Future> patch(Map? data, Uri? uri) => + _i13.Future> patch( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i13.Future>.value({})) as _i13.Future>); @override - _i13.Future<_i5.Response> deleteRequest(String? url, int? id) => (super.noSuchMethod( - Invocation.method(#deleteRequest, [url, id]), - returnValue: Future<_i5.Response>.value(_FakeResponse_11())) as _i13.Future<_i5.Response>); + _i13.Future<_i5.Response> deleteRequest(String? url, int? id) => + (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), + returnValue: _i13.Future<_i5.Response>.value(_FakeResponse_11( + this, Invocation.method(#deleteRequest, [url, id])))) + as _i13.Future<_i5.Response>); @override - void addListener(_i15.VoidCallback? listener) => super - .noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); + void addListener(_i15.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); @override void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override - void dispose() => - super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null); + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); @override void notifyListeners() => - super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); } diff --git a/test/workout/workout_set_form_test.mocks.dart b/test/workout/workout_set_form_test.mocks.dart index 21519f28a..402b01aa8 100644 --- a/test/workout/workout_set_form_test.mocks.dart +++ b/test/workout/workout_set_form_test.mocks.dart @@ -1,7 +1,8 @@ -// Mocks generated by Mockito 5.0.17 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in wger/test/workout/workout_set_form_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i6; import 'dart:ui' as _i7; @@ -11,6 +12,7 @@ import 'package:wger/models/exercises/exercise.dart' as _i4; import 'package:wger/providers/auth.dart' as _i2; import 'package:wger/providers/exercises.dart' as _i5; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -19,16 +21,32 @@ import 'package:wger/providers/exercises.dart' as _i5; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.Fake implements _i2.AuthProvider {} +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeClient_1 extends _i1.Fake implements _i3.Client {} +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeExercise_2 extends _i1.Fake implements _i4.Exercise {} +class _FakeExercise_2 extends _i1.SmartFake implements _i4.Exercise { + _FakeExercise_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeUri_3 extends _i1.Fake implements Uri {} +class _FakeUri_3 extends _i1.SmartFake implements Uri { + _FakeUri_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} -class _FakeResponse_4 extends _i1.Fake implements _i3.Response {} +class _FakeResponse_4 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_4(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} /// A class which mocks [ExercisesProvider]. /// @@ -39,93 +57,125 @@ class MockExercisesProvider extends _i1.Mock implements _i5.ExercisesProvider { } @override - List<_i4.Exercise> get items => - (super.noSuchMethod(Invocation.getter(#items), returnValue: <_i4.Exercise>[]) - as List<_i4.Exercise>); + List<_i4.Exercise> get items => (super.noSuchMethod(Invocation.getter(#items), + returnValue: <_i4.Exercise>[]) as List<_i4.Exercise>); @override - _i2.AuthProvider get auth => - (super.noSuchMethod(Invocation.getter(#auth), returnValue: _FakeAuthProvider_0()) - as _i2.AuthProvider); + _i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth))) + as _i2.AuthProvider); @override set auth(_i2.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#auth, _auth), + returnValueForMissingStub: null); @override - _i3.Client get client => - (super.noSuchMethod(Invocation.getter(#client), returnValue: _FakeClient_1()) as _i3.Client); + _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), + returnValue: _FakeClient_1(this, Invocation.getter(#client))) + as _i3.Client); @override set client(_i3.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.setter(#client, _client), + returnValueForMissingStub: null); @override bool get hasListeners => - (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) as bool); + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - _i4.Exercise findById(int? exerciseId) => (super - .noSuchMethod(Invocation.method(#findById, [exerciseId]), returnValue: _FakeExercise_2()) + _i4.Exercise findById(int? exerciseId) => (super.noSuchMethod( + Invocation.method(#findById, [exerciseId]), + returnValue: + _FakeExercise_2(this, Invocation.method(#findById, [exerciseId]))) as _i4.Exercise); @override - _i6.Future fetchAndSetCategories() => - (super.noSuchMethod(Invocation.method(#fetchAndSetCategories, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + _i6.Future fetchAndSetCategories() => (super.noSuchMethod( + Invocation.method(#fetchAndSetCategories, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); @override - _i6.Future fetchAndSetMuscles() => - (super.noSuchMethod(Invocation.method(#fetchAndSetMuscles, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + _i6.Future fetchAndSetMuscles() => (super.noSuchMethod( + Invocation.method(#fetchAndSetMuscles, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); @override - _i6.Future fetchAndSetEquipment() => - (super.noSuchMethod(Invocation.method(#fetchAndSetEquipment, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + _i6.Future fetchAndSetEquipment() => (super.noSuchMethod( + Invocation.method(#fetchAndSetEquipment, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); @override _i6.Future<_i4.Exercise> fetchAndSetExercise(int? exerciseId) => (super.noSuchMethod(Invocation.method(#fetchAndSetExercise, [exerciseId]), - returnValue: Future<_i4.Exercise>.value(_FakeExercise_2())) as _i6.Future<_i4.Exercise>); - @override - _i6.Future fetchAndSetExercises() => - (super.noSuchMethod(Invocation.method(#fetchAndSetExercises, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future> searchExercise(String? name, [String? languageCode = r'en']) => - (super.noSuchMethod(Invocation.method(#searchExercise, [name, languageCode]), - returnValue: Future>.value([])) as _i6.Future>); + returnValue: _i6.Future<_i4.Exercise>.value(_FakeExercise_2( + this, Invocation.method(#fetchAndSetExercise, [exerciseId])))) + as _i6.Future<_i4.Exercise>); + @override + _i6.Future checkExerciseCacheVersion() => (super.noSuchMethod( + Invocation.method(#checkExerciseCacheVersion, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); + @override + _i6.Future fetchAndSetExercises() => (super.noSuchMethod( + Invocation.method(#fetchAndSetExercises, []), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value()) as _i6.Future); + @override + _i6.Future> searchExercise(String? name, + [String? languageCode = r'en']) => + (super.noSuchMethod( + Invocation.method(#searchExercise, [name, languageCode]), + returnValue: _i6.Future>.value([])) + as _i6.Future>); @override - Uri makeUrl(String? path, {int? id, String? objectMethod, Map? query}) => + Uri makeUrl(String? path, + {int? id, String? objectMethod, Map? query}) => (super.noSuchMethod( - Invocation.method( - #makeUrl, [path], {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_3()) as Uri); + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), + returnValue: _FakeUri_3( + this, + Invocation.method(#makeUrl, [ + path + ], { + #id: id, + #objectMethod: objectMethod, + #query: query + }))) as Uri); @override _i6.Future> fetch(Uri? uri) => (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override _i6.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override - _i6.Future> patch(Map? data, Uri? uri) => + _i6.Future> patch( + Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: Future>.value({})) + returnValue: + _i6.Future>.value({})) as _i6.Future>); @override _i6.Future<_i3.Response> deleteRequest(String? url, int? id) => (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), - returnValue: Future<_i3.Response>.value(_FakeResponse_4())) as _i6.Future<_i3.Response>); + returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_4( + this, Invocation.method(#deleteRequest, [url, id])))) + as _i6.Future<_i3.Response>); @override - void addListener(_i7.VoidCallback? listener) => super - .noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); + void addListener(_i7.VoidCallback? listener) => + super.noSuchMethod(Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null); @override void removeListener(_i7.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override - void dispose() => - super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null); + void dispose() => super.noSuchMethod(Invocation.method(#dispose, []), + returnValueForMissingStub: null); @override void notifyListeners() => - super.noSuchMethod(Invocation.method(#notifyListeners, []), returnValueForMissingStub: null); + super.noSuchMethod(Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null); } From 8a3351159a8bb6aa5fe63e19ae5e92671fe3a6b3 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 20:04:41 +0200 Subject: [PATCH 02/12] Pass the base provider to the nutritional provider as an argument This makes it easier to test and is the same behaviour as the measurement provider --- lib/main.dart | 29 +- lib/providers/measurement.dart | 1 - lib/providers/nutrition.dart | 94 +++--- lib/widgets/nutrition/widgets.dart | 2 +- .../nutritional_meal_item_form_test.dart | 16 +- .../nutritional_plan_form_test.mocks.dart | 271 +++++++----------- .../nutritional_plan_screen_test.dart | 4 +- .../nutritional_plans_screen_test.dart | 16 +- 8 files changed, 191 insertions(+), 242 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 479f80987..a56e1aaf1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -64,38 +64,39 @@ class MyApp extends StatelessWidget { create: (ctx) => AuthProvider(), ), ChangeNotifierProxyProvider( - create: (context) => - ExercisesProvider(Provider.of(context, listen: false), []), + create: (context) => ExercisesProvider(context.read(), []), update: (context, auth, previous) => previous ?? ExercisesProvider(auth, []), ), ChangeNotifierProxyProvider2( create: (context) => WorkoutPlansProvider( - Provider.of(context, listen: false), - Provider.of(context, listen: false), + context.read(), + context.read(), [], ), update: (context, auth, exercises, previous) => previous ?? WorkoutPlansProvider(auth, exercises, []), ), ChangeNotifierProxyProvider( - create: (context) => - NutritionPlansProvider(Provider.of(context, listen: false), []), - update: (context, auth, previous) => previous ?? NutritionPlansProvider(auth, []), + create: (context) => NutritionPlansProvider( + WgerBaseProvider(context.read()), + [], + ), + update: (context, auth, previous) => + previous ?? NutritionPlansProvider(WgerBaseProvider(auth), []), ), ChangeNotifierProxyProvider( create: (context) => MeasurementProvider( - WgerBaseProvider(Provider.of(context, listen: false))), - update: (context, base, previous) => - previous ?? MeasurementProvider(WgerBaseProvider(base)), + WgerBaseProvider(context.read()), + ), + update: (context, auth, previous) => + previous ?? MeasurementProvider(WgerBaseProvider(auth)), ), ChangeNotifierProxyProvider( - create: (context) => - BodyWeightProvider(Provider.of(context, listen: false), []), + create: (context) => BodyWeightProvider(context.read(), []), update: (context, auth, previous) => previous ?? BodyWeightProvider(auth, []), ), ChangeNotifierProxyProvider( - create: (context) => - GalleryProvider(Provider.of(context, listen: false), []), + create: (context) => GalleryProvider(context.read(), []), update: (context, auth, previous) => previous ?? GalleryProvider(auth, []), ), ], diff --git a/lib/providers/measurement.dart b/lib/providers/measurement.dart index f1709c04c..7f2c4ee32 100644 --- a/lib/providers/measurement.dart +++ b/lib/providers/measurement.dart @@ -32,7 +32,6 @@ class MeasurementProvider with ChangeNotifier { List _categories = []; MeasurementProvider(this.baseProvider); - //: super(auth, client); List get categories => _categories; diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 3ade66097..39d0d97c7 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -18,10 +18,8 @@ import 'dart:convert'; import 'dart:developer'; -import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; import 'package:wger/exceptions/http_exception.dart'; import 'package:wger/helpers/consts.dart'; @@ -31,10 +29,9 @@ import 'package:wger/models/nutrition/log.dart'; import 'package:wger/models/nutrition/meal.dart'; import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; -import 'package:wger/providers/auth.dart'; import 'package:wger/providers/base_provider.dart'; -class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { +class NutritionPlansProvider with ChangeNotifier { static const _nutritionalPlansPath = 'nutritionplan'; static const _nutritionalPlansInfoPath = 'nutritionplaninfo'; static const _mealPath = 'meal'; @@ -44,12 +41,11 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { static const _nutritionDiaryPath = 'nutritiondiary'; static const _ingredientImagePath = 'ingredient-image'; + final WgerBaseProvider baseProvider; List _plans = []; List _ingredients = []; - NutritionPlansProvider(AuthProvider auth, List entries, [http.Client? client]) - : _plans = entries, - super(auth, client); + NutritionPlansProvider(this.baseProvider, List entries) : _plans = entries; List get items { return [..._plans]; @@ -86,7 +82,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Fetches and sets all plans sparsely, i.e. only with the data on the plan /// object itself and no child attributes Future fetchAndSetAllPlansSparse() async { - final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'})); + final url = baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}); + final data = await baseProvider.fetch(url); for (final planData in data['results']) { final plan = NutritionalPlan.fromJson(planData); _plans.add(plan); @@ -97,7 +94,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Fetches and sets all plans fully, i.e. with all corresponding child objects Future fetchAndSetAllPlansFull() async { - final data = await fetch(makeUrl(_nutritionalPlansPath)); + final data = await baseProvider.fetch(baseProvider.makeUrl(_nutritionalPlansPath)); for (final entry in data['results']) { await fetchAndSetPlanFull(entry['id']); } @@ -108,7 +105,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// This method only loads the data on the nutritional plan object itself, /// no meals, etc. Future fetchAndSetPlanSparse(int planId) async { - final planData = await fetch(makeUrl(_nutritionalPlansPath, id: planId)); + final url = baseProvider.makeUrl(_nutritionalPlansPath, id: planId); + final planData = await baseProvider.fetch(url); final plan = NutritionalPlan.fromJson(planData); _plans.add(plan); _plans.sort((a, b) => b.creationDate.compareTo(a.creationDate)); @@ -127,7 +125,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { } // Plan - final fullPlanData = await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId)); + final url = baseProvider.makeUrl(_nutritionalPlansInfoPath, id: planId); + final fullPlanData = await baseProvider.fetch(url); // Meals final List meals = []; @@ -161,7 +160,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { } Future addPlan(NutritionalPlan planData) async { - final data = await post(planData.toJson(), makeUrl(_nutritionalPlansPath)); + final data = await baseProvider.post( + planData.toJson(), + baseProvider.makeUrl(_nutritionalPlansPath), + ); final plan = NutritionalPlan.fromJson(data); _plans.add(plan); _plans.sort((a, b) => b.creationDate.compareTo(a.creationDate)); @@ -170,7 +172,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { } Future editPlan(NutritionalPlan plan) async { - await patch(plan.toJson(), makeUrl(_nutritionalPlansPath, id: plan.id)); + await baseProvider.patch( + plan.toJson(), + baseProvider.makeUrl(_nutritionalPlansPath, id: plan.id), + ); notifyListeners(); } @@ -180,7 +185,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { _plans.removeAt(existingPlanIndex); notifyListeners(); - final response = await deleteRequest(_nutritionalPlansPath, id); + final response = await baseProvider.deleteRequest(_nutritionalPlansPath, id); if (response.statusCode >= 400) { _plans.insert(existingPlanIndex, existingPlan); @@ -193,7 +198,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Adds a meal to a plan Future addMeal(Meal meal, int planId) async { final plan = findById(planId); - final data = await post(meal.toJson(), makeUrl(_mealPath)); + final data = await baseProvider.post( + meal.toJson(), + baseProvider.makeUrl(_mealPath), + ); meal = Meal.fromJson(data); plan.meals.add(meal); @@ -204,7 +212,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Edits an existing meal Future editMeal(Meal meal) async { - final data = await patch(meal.toJson(), makeUrl(_mealPath, id: meal.id)); + final data = await baseProvider.patch( + meal.toJson(), + baseProvider.makeUrl(_mealPath, id: meal.id), + ); meal = Meal.fromJson(data); notifyListeners(); @@ -221,7 +232,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { notifyListeners(); // Try to delete - final response = await deleteRequest(_mealPath, meal.id!); + final response = await baseProvider.deleteRequest(_mealPath, meal.id!); if (response.statusCode >= 400) { plan.meals.insert(mealIndex, existingMeal); notifyListeners(); @@ -231,7 +242,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Adds a meal item to a meal Future addMealItem(MealItem mealItem, Meal meal) async { - final data = await post(mealItem.toJson(), makeUrl(_mealItemPath)); + final data = await baseProvider.post(mealItem.toJson(), baseProvider.makeUrl(_mealItemPath)); mealItem = MealItem.fromJson(data); mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId); @@ -251,7 +262,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { notifyListeners(); // Try to delete - final response = await deleteRequest(_mealItemPath, mealItem.id!); + final response = await baseProvider.deleteRequest(_mealItemPath, mealItem.id!); if (response.statusCode >= 400) { meal.mealItems.insert(mealItemIndex, existingMealItem); notifyListeners(); @@ -271,7 +282,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { // Get ingredient from the server and save to cache } on StateError { - final data = await fetch(makeUrl(_ingredientPath, id: ingredientId)); + final data = await baseProvider.fetch( + baseProvider.makeUrl(_ingredientPath, id: ingredientId), + ); ingredient = Ingredient.fromJson(data); _ingredients.add(ingredient); @@ -315,24 +328,12 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { } // Send the request - final response = await client.get( - makeUrl( - _ingredientSearchPath, - query: {'term': name, 'language': languageCode}, - ), - headers: { - HttpHeaders.authorizationHeader: 'Token ${auth.token}', - HttpHeaders.userAgentHeader: auth.getAppNameHeader(), - }, + final response = await baseProvider.fetch( + baseProvider.makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languageCode}), ); - // Something wrong with our request - if (response.statusCode >= 400) { - throw WgerHttpException(response.body); - } - // Process the response - return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List; + return response['suggestions']; } /// Searches for an ingredient with code @@ -342,11 +343,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { } // Send the request - final data = await fetch( - makeUrl( - _ingredientPath, - query: {'code': code}, - ), + final data = await baseProvider.fetch( + baseProvider.makeUrl(_ingredientPath, query: {'code': code}), ); if (data["count"] == 0) { @@ -362,7 +360,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { final plan = findById(meal.planId); final Log log = Log.fromMealItem(item, plan.id!, meal.id); - final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath)); + final data = await baseProvider.post( + log.toJson(), + baseProvider.makeUrl(_nutritionDiaryPath), + ); log.id = data['id']; plan.logs.add(log); } @@ -375,7 +376,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId); final Log log = Log.fromMealItem(mealItem, plan.id!, null, dateTime); - final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath)); + final data = await baseProvider.post(log.toJson(), baseProvider.makeUrl(_nutritionDiaryPath)); log.id = data['id']; plan.logs.add(log); notifyListeners(); @@ -383,7 +384,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Deletes a log entry Future deleteLog(int logId, int planId) async { - await deleteRequest(_nutritionDiaryPath, logId); + await baseProvider.deleteRequest(_nutritionDiaryPath, logId); final plan = findById(planId); plan.logs.removeWhere((element) => element.id == logId); @@ -393,8 +394,11 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { /// Load nutrition diary entries for plan Future fetchAndSetLogs(NutritionalPlan plan) async { // TODO(x): update fetch to that it can use the pagination - final data = await fetch( - makeUrl(_nutritionDiaryPath, query: {'plan': plan.id.toString(), 'limit': '1000'}), + final data = await baseProvider.fetch( + baseProvider.makeUrl( + _nutritionDiaryPath, + query: {'plan': plan.id.toString(), 'limit': '1000'}, + ), ); plan.logs = []; diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index c74ed495e..ec2ac70b1 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -74,7 +74,7 @@ class _IngredientTypeaheadState extends State { ); }, itemBuilder: (context, dynamic suggestion) { - final url = context.read().auth.serverUrl; + final url = context.read().baseProvider.auth.serverUrl; return ListTile( leading: suggestion['data']['image'] != null ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index f4b800406..619323672 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -15,11 +15,11 @@ import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/nutrition.dart'; import 'package:wger/screens/nutritional_plan_screen.dart'; import 'package:wger/widgets/nutrition/forms.dart'; -import '../../test_data/nutritional_plans.dart'; +import '../../test_data/nutritional_plans.dart'; import '../fixtures/fixture_reader.dart'; +import '../measurements/measurement_provider_test.mocks.dart'; import '../other/base_provider_test.mocks.dart'; -import '../utils.dart'; import 'nutritional_plan_form_test.mocks.dart'; void main() { @@ -38,9 +38,16 @@ void main() { sodium: 0.5, ); + late MockWgerBaseProvider mockWgerBaseProvider; + late NutritionPlansProvider mockNutritionWithClient; + var mockNutrition = MockNutritionPlansProvider(); final client = MockClient(); - final mockNutritionWithClient = NutritionPlansProvider(testAuthProvider, [], client); + + setUp(() { + mockWgerBaseProvider = MockWgerBaseProvider(); + mockNutritionWithClient = NutritionPlansProvider(mockWgerBaseProvider, []); + }); var plan1 = NutritionalPlan.empty(); var meal1 = Meal(); @@ -140,6 +147,7 @@ void main() { }); }); + /* group('Test searchIngredientWithCode() function', () { test('with correct code', () async { final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode('123'); @@ -157,6 +165,8 @@ void main() { }); }); + */ + group('Test weight formfield', () { testWidgets('add empty weight', (WidgetTester tester) async { await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index b4b9895b8..a40091cfa 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -3,17 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i9; -import 'dart:ui' as _i10; +import 'dart:async' as _i8; +import 'dart:ui' as _i9; -import 'package:http/http.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i7; -import 'package:wger/models/nutrition/meal.dart' as _i5; -import 'package:wger/models/nutrition/meal_item.dart' as _i6; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; -import 'package:wger/providers/auth.dart' as _i2; -import 'package:wger/providers/nutrition.dart' as _i8; +import 'package:wger/models/nutrition/ingredient.dart' as _i6; +import 'package:wger/models/nutrition/meal.dart' as _i4; +import 'package:wger/models/nutrition/meal_item.dart' as _i5; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3; +import 'package:wger/providers/base_provider.dart' as _i2; +import 'package:wger/providers/nutrition.dart' as _i7; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -26,44 +25,30 @@ import 'package:wger/providers/nutrition.dart' as _i8; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { - _FakeAuthProvider_0(Object parent, Invocation parentInvocation) +class _FakeWgerBaseProvider_0 extends _i1.SmartFake + implements _i2.WgerBaseProvider { + _FakeWgerBaseProvider_0(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { - _FakeClient_1(Object parent, Invocation parentInvocation) +class _FakeNutritionalPlan_1 extends _i1.SmartFake + implements _i3.NutritionalPlan { + _FakeNutritionalPlan_1(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeNutritionalPlan_2 extends _i1.SmartFake - implements _i4.NutritionalPlan { - _FakeNutritionalPlan_2(Object parent, Invocation parentInvocation) +class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal { + _FakeMeal_2(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { - _FakeMeal_3(Object parent, Invocation parentInvocation) +class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem { + _FakeMealItem_3(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem { - _FakeMealItem_4(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient { - _FakeIngredient_5(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeUri_6 extends _i1.SmartFake implements Uri { - _FakeUri_6(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { - _FakeResponse_7(Object parent, Invocation parentInvocation) +class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient { + _FakeIngredient_4(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } @@ -71,31 +56,21 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { /// /// See the documentation for Mockito's code generation for more information. class MockNutritionPlansProvider extends _i1.Mock - implements _i8.NutritionPlansProvider { + implements _i7.NutritionPlansProvider { MockNutritionPlansProvider() { _i1.throwOnMissingStub(this); } @override - List<_i4.NutritionalPlan> get items => - (super.noSuchMethod(Invocation.getter(#items), - returnValue: <_i4.NutritionalPlan>[]) as List<_i4.NutritionalPlan>); - @override - _i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth), - returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth))) - as _i2.AuthProvider); - @override - set auth(_i2.AuthProvider? _auth) => - super.noSuchMethod(Invocation.setter(#auth, _auth), - returnValueForMissingStub: null); - @override - _i3.Client get client => (super.noSuchMethod(Invocation.getter(#client), - returnValue: _FakeClient_1(this, Invocation.getter(#client))) - as _i3.Client); + _i2.WgerBaseProvider get baseProvider => (super.noSuchMethod( + Invocation.getter(#baseProvider), + returnValue: + _FakeWgerBaseProvider_0(this, Invocation.getter(#baseProvider))) + as _i2.WgerBaseProvider); @override - set client(_i3.Client? _client) => - super.noSuchMethod(Invocation.setter(#client, _client), - returnValueForMissingStub: null); + List<_i3.NutritionalPlan> get items => + (super.noSuchMethod(Invocation.getter(#items), + returnValue: <_i3.NutritionalPlan>[]) as List<_i3.NutritionalPlan>); @override bool get hasListeners => (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) @@ -104,178 +79,138 @@ class MockNutritionPlansProvider extends _i1.Mock void clear() => super.noSuchMethod(Invocation.method(#clear, []), returnValueForMissingStub: null); @override - _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i3.NutritionalPlan findById(int? id) => (super.noSuchMethod( Invocation.method(#findById, [id]), returnValue: - _FakeNutritionalPlan_2(this, Invocation.method(#findById, [id]))) - as _i4.NutritionalPlan); + _FakeNutritionalPlan_1(this, Invocation.method(#findById, [id]))) + as _i3.NutritionalPlan); @override - _i5.Meal? findMealById(int? id) => - (super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?); + _i4.Meal? findMealById(int? id) => + (super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i4.Meal?); @override - _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( Invocation.method(#fetchAndSetAllPlansSparse, []), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( Invocation.method(#fetchAndSetAllPlansFull, []), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]), - returnValue: _i9.Future<_i4.NutritionalPlan>.value( - _FakeNutritionalPlan_2(this, + returnValue: _i8.Future<_i3.NutritionalPlan>.value( + _FakeNutritionalPlan_1(this, Invocation.method(#fetchAndSetPlanSparse, [planId])))) - as _i9.Future<_i4.NutritionalPlan>); + as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super .noSuchMethod(Invocation.method(#fetchAndSetPlanFull, [planId]), - returnValue: _i9.Future<_i4.NutritionalPlan>.value( - _FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value( + _FakeNutritionalPlan_1( this, Invocation.method(#fetchAndSetPlanFull, [planId])))) - as _i9.Future<_i4.NutritionalPlan>); + as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => + _i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) => (super.noSuchMethod(Invocation.method(#addPlan, [planData]), - returnValue: _i9.Future<_i4.NutritionalPlan>.value( - _FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value( + _FakeNutritionalPlan_1( this, Invocation.method(#addPlan, [planData])))) - as _i9.Future<_i4.NutritionalPlan>); + as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + _i8.Future editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method(#editPlan, [plan]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod( + _i8.Future deletePlan(int? id) => (super.noSuchMethod( Invocation.method(#deletePlan, [id]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) => + _i8.Future<_i4.Meal> addMeal(_i4.Meal? meal, int? planId) => (super.noSuchMethod(Invocation.method(#addMeal, [meal, planId]), - returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2( this, Invocation.method(#addMeal, [meal, planId])))) - as _i9.Future<_i5.Meal>); + as _i8.Future<_i4.Meal>); @override - _i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => + _i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) => (super.noSuchMethod(Invocation.method(#editMeal, [meal]), - returnValue: _i9.Future<_i5.Meal>.value( - _FakeMeal_3(this, Invocation.method(#editMeal, [meal])))) - as _i9.Future<_i5.Meal>); + returnValue: _i8.Future<_i4.Meal>.value( + _FakeMeal_2(this, Invocation.method(#editMeal, [meal])))) + as _i8.Future<_i4.Meal>); @override - _i9.Future deleteMeal(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future deleteMeal(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method(#deleteMeal, [meal]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future<_i6.MealItem> addMealItem( - _i6.MealItem? mealItem, _i5.Meal? meal) => + _i8.Future<_i5.MealItem> addMealItem( + _i5.MealItem? mealItem, _i4.Meal? meal) => (super.noSuchMethod(Invocation.method(#addMealItem, [mealItem, meal]), - returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4( + returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3( this, Invocation.method(#addMealItem, [mealItem, meal])))) - as _i9.Future<_i6.MealItem>); + as _i8.Future<_i5.MealItem>); @override - _i9.Future deleteMealItem(_i6.MealItem? mealItem) => + _i8.Future deleteMealItem(_i5.MealItem? mealItem) => (super.noSuchMethod(Invocation.method(#deleteMealItem, [mealItem]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) - as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) + as _i8.Future); @override - _i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => + _i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod(Invocation.method(#fetchIngredient, [ingredientId]), - returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5( + returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4( this, Invocation.method(#fetchIngredient, [ingredientId])))) - as _i9.Future<_i7.Ingredient>); + as _i8.Future<_i6.Ingredient>); @override - _i9.Future fetchIngredientsFromCache() => (super.noSuchMethod( + _i8.Future fetchIngredientsFromCache() => (super.noSuchMethod( Invocation.method(#fetchIngredientsFromCache, []), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future> searchIngredient(String? name, + _i8.Future> searchIngredient(String? name, [String? languageCode = r'en']) => (super.noSuchMethod( Invocation.method(#searchIngredient, [name, languageCode]), - returnValue: _i9.Future>.value([])) - as _i9.Future>); + returnValue: _i8.Future>.value([])) + as _i8.Future>); @override - _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => + _i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod(Invocation.method(#searchIngredientWithCode, [code]), - returnValue: _i9.Future<_i7.Ingredient?>.value()) - as _i9.Future<_i7.Ingredient?>); + returnValue: _i8.Future<_i6.Ingredient?>.value()) + as _i8.Future<_i6.Ingredient?>); @override - _i9.Future logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method(#logMealToDiary, [meal]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future logIngredentToDiary(_i6.MealItem? mealItem, int? planId, + _i8.Future logIngredentToDiary(_i5.MealItem? mealItem, int? planId, [DateTime? dateTime]) => (super.noSuchMethod( Invocation.method(#logIngredentToDiary, [mealItem, planId, dateTime]), - returnValue: _i9.Future.value(), + returnValue: _i8.Future.value(), returnValueForMissingStub: - _i9.Future.value()) as _i9.Future); + _i8.Future.value()) as _i8.Future); @override - _i9.Future deleteLog(int? logId, int? planId) => (super.noSuchMethod( + _i8.Future deleteLog(int? logId, int? planId) => (super.noSuchMethod( Invocation.method(#deleteLog, [logId, planId]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) as _i8.Future); @override - _i9.Future fetchAndSetLogs(_i4.NutritionalPlan? plan) => + _i8.Future fetchAndSetLogs(_i3.NutritionalPlan? plan) => (super.noSuchMethod(Invocation.method(#fetchAndSetLogs, [plan]), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value()) - as _i9.Future); - @override - Uri makeUrl(String? path, - {int? id, String? objectMethod, Map? query}) => - (super.noSuchMethod( - Invocation.method(#makeUrl, [path], - {#id: id, #objectMethod: objectMethod, #query: query}), - returnValue: _FakeUri_6( - this, - Invocation.method(#makeUrl, [ - path - ], { - #id: id, - #objectMethod: objectMethod, - #query: query - }))) as Uri); - @override - _i9.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: - _i9.Future>.value({})) - as _i9.Future>); - @override - _i9.Future> post(Map? data, Uri? uri) => - (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: - _i9.Future>.value({})) - as _i9.Future>); - @override - _i9.Future> patch( - Map? data, Uri? uri) => - (super.noSuchMethod(Invocation.method(#patch, [data, uri]), - returnValue: - _i9.Future>.value({})) - as _i9.Future>); - @override - _i9.Future<_i3.Response> deleteRequest(String? url, int? id) => - (super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]), - returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7( - this, Invocation.method(#deleteRequest, [url, id])))) - as _i9.Future<_i3.Response>); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value()) + as _i8.Future); @override - void addListener(_i10.VoidCallback? listener) => + void addListener(_i9.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#addListener, [listener]), returnValueForMissingStub: null); @override - void removeListener(_i10.VoidCallback? listener) => + void removeListener(_i9.VoidCallback? listener) => super.noSuchMethod(Invocation.method(#removeListener, [listener]), returnValueForMissingStub: null); @override diff --git a/test/nutrition/nutritional_plan_screen_test.dart b/test/nutrition/nutritional_plan_screen_test.dart index 796f11af2..c341df603 100644 --- a/test/nutrition/nutritional_plan_screen_test.dart +++ b/test/nutrition/nutritional_plan_screen_test.dart @@ -26,6 +26,7 @@ import 'package:wger/screens/nutritional_plan_screen.dart'; import 'package:wger/widgets/nutrition/charts.dart'; import '../../test_data/nutritional_plans.dart'; +import '../measurements/measurement_provider_test.mocks.dart'; import '../other/base_provider_test.mocks.dart'; import '../utils.dart'; @@ -33,13 +34,14 @@ void main() { Widget createNutritionalPlan({locale = 'en'}) { final key = GlobalKey(); final client = MockClient(); + final mockWgerBaseProvider = MockWgerBaseProvider(); final plan = getNutritionalPlan(); return MultiProvider( providers: [ ChangeNotifierProvider( - create: (context) => NutritionPlansProvider(testAuthProvider, [], client), + create: (context) => NutritionPlansProvider(mockWgerBaseProvider, []), ), ChangeNotifierProvider( create: (context) => BodyWeightProvider(testAuthProvider, [], client), diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index 0b0bbb240..d46c6a8e7 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -28,25 +28,23 @@ import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/nutritional_plans_screen.dart'; import 'package:wger/widgets/nutrition/forms.dart'; -import '../other/base_provider_test.mocks.dart'; -import '../utils.dart'; +import '../measurements/measurement_provider_test.mocks.dart'; void main() { Widget createHomeScreen({locale = 'en'}) { - final client = MockClient(); - when(client.delete( - any, - headers: anyNamed('headers'), - )).thenAnswer((_) async => http.Response('', 200)); + final mockWgerBaseProvider = MockWgerBaseProvider(); + + when(mockWgerBaseProvider.deleteRequest(any, any)).thenAnswer( + (_) async => http.Response('', 200), + ); return ChangeNotifierProvider( create: (context) => NutritionPlansProvider( - testAuthProvider, + mockWgerBaseProvider, [ NutritionalPlan(id: 1, description: 'test plan 1', creationDate: DateTime(2021, 01, 01)), NutritionalPlan(id: 2, description: 'test plan 2', creationDate: DateTime(2021, 01, 10)), ], - client, ), child: MaterialApp( locale: Locale(locale), From 9a0d3b201c77e73f803c9c122aa9a1079823d3dd Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 20:43:03 +0200 Subject: [PATCH 03/12] Commit missing generated file --- lib/models/nutrition/image.g.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/models/nutrition/image.g.dart diff --git a/lib/models/nutrition/image.g.dart b/lib/models/nutrition/image.g.dart new file mode 100644 index 000000000..5dd96e6f0 --- /dev/null +++ b/lib/models/nutrition/image.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'image.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +IngredientImage _$IngredientImageFromJson(Map json) { + $checkKeys( + json, + requiredKeys: const ['id', 'uuid', 'ingredient_id', 'image', 'size'], + ); + return IngredientImage( + id: json['id'] as int, + uuid: json['uuid'] as String, + ingredientId: json['ingredient_id'] as String, + image: json['image'] as String, + size: json['size'] as int, + ); +} + +Map _$IngredientImageToJson(IngredientImage instance) => + { + 'id': instance.id, + 'uuid': instance.uuid, + 'ingredient_id': instance.ingredientId, + 'image': instance.image, + 'size': instance.size, + }; From 94b23599037a17f87d4f3385317f8f0fca318010 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 20:48:56 +0200 Subject: [PATCH 04/12] Add stub with nutrition provider tests --- lib/providers/nutrition.dart | 5 +- .../nutrition/ingredient_10065_response.json | 18 ++ .../nutrition/ingredient_58300_response.json | 18 ++ .../nutrition/ingredient_59887_response.json | 18 ++ .../nutrition/nutrition_diary_response.json | 34 ++++ .../nutritional_plan_detail_response.json | 7 + ...nutritional_plan_info_detail_response.json | 191 ++++++++++++++++++ test/nutrition/nutrition_provider_test.dart | 89 ++++++++ 8 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/nutrition/ingredient_10065_response.json create mode 100644 test/fixtures/nutrition/ingredient_58300_response.json create mode 100644 test/fixtures/nutrition/ingredient_59887_response.json create mode 100644 test/fixtures/nutrition/nutrition_diary_response.json create mode 100644 test/fixtures/nutrition/nutritional_plan_detail_response.json create mode 100644 test/fixtures/nutrition/nutritional_plan_info_detail_response.json create mode 100644 test/nutrition/nutrition_provider_test.dart diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 39d0d97c7..206f096c3 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -51,6 +51,10 @@ class NutritionPlansProvider with ChangeNotifier { return [..._plans]; } + set ingredients(items) { + _ingredients = items; + } + /// Clears all lists void clear() { _plans = []; @@ -143,7 +147,6 @@ class NutritionPlansProvider with ChangeNotifier { ingredient.image = image; } mealItem.ingredientObj = ingredient; - //mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId); mealItems.add(mealItem); } meal.mealItems = mealItems; diff --git a/test/fixtures/nutrition/ingredient_10065_response.json b/test/fixtures/nutrition/ingredient_10065_response.json new file mode 100644 index 000000000..920fbfa2a --- /dev/null +++ b/test/fixtures/nutrition/ingredient_10065_response.json @@ -0,0 +1,18 @@ +{ + "id": 10065, + "code": "0043647440020", + "name": "'Old Times' Orange Fine Cut Marmalade", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 269, + "protein": "0.000", + "carbohydrates": "67.000", + "carbohydrates_sugar": "66.000", + "fat": "0.000", + "fat_saturated": "0.000", + "fibres": null, + "sodium": "0.000", + "license": 5, + "license_author": "Open Food Facts", + "language": 2 +} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredient_58300_response.json b/test/fixtures/nutrition/ingredient_58300_response.json new file mode 100644 index 000000000..1dbe5c8df --- /dev/null +++ b/test/fixtures/nutrition/ingredient_58300_response.json @@ -0,0 +1,18 @@ +{ + "id": 58300, + "code": "4071800000992", + "name": "1688 Mehrkorn", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 229, + "protein": "7.680", + "carbohydrates": "35.700", + "carbohydrates_sugar": "2.320", + "fat": "4.820", + "fat_saturated": "0.714", + "fibres": "6.960", + "sodium": "0.000", + "license": 5, + "license_author": "Open Food Facts", + "language": 2 +} \ No newline at end of file diff --git a/test/fixtures/nutrition/ingredient_59887_response.json b/test/fixtures/nutrition/ingredient_59887_response.json new file mode 100644 index 000000000..3aa08b427 --- /dev/null +++ b/test/fixtures/nutrition/ingredient_59887_response.json @@ -0,0 +1,18 @@ +{ + "id": 59887, + "code": "4311501354155", + "name": "Baked Beans", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 86, + "protein": "4.400", + "carbohydrates": "11.000", + "carbohydrates_sugar": "5.300", + "fat": "0.100", + "fat_saturated": "0.000", + "fibres": "5.000", + "sodium": "0.480", + "license": 5, + "license_author": "Open Food Facts", + "language": 1 +} \ No newline at end of file diff --git a/test/fixtures/nutrition/nutrition_diary_response.json b/test/fixtures/nutrition/nutrition_diary_response.json new file mode 100644 index 000000000..ccbb06e72 --- /dev/null +++ b/test/fixtures/nutrition/nutrition_diary_response.json @@ -0,0 +1,34 @@ +{ + "count": 3, + "next": null, + "previous": null, + "results": [ + { + "id": 1, + "plan": 1, + "meal": 1, + "ingredient": 59887, + "weight_unit": null, + "datetime": "2022-08-09T20:27:14.064157+02:00", + "amount": "100.00" + }, + { + "id": 2, + "plan": 1, + "meal": 1, + "ingredient": 58300, + "weight_unit": null, + "datetime": "2022-08-09T20:27:14.075674+02:00", + "amount": "100.00" + }, + { + "id": 3, + "plan": 1, + "meal": 1, + "ingredient": 10065, + "weight_unit": null, + "datetime": "2022-08-09T20:27:14.086133+02:00", + "amount": "200.00" + } + ] +} \ No newline at end of file diff --git a/test/fixtures/nutrition/nutritional_plan_detail_response.json b/test/fixtures/nutrition/nutritional_plan_detail_response.json new file mode 100644 index 000000000..c1fd3a9e3 --- /dev/null +++ b/test/fixtures/nutrition/nutritional_plan_detail_response.json @@ -0,0 +1,7 @@ +{ + "id": 1, + "creation_date": "2022-08-09", + "description": "", + "has_goal_calories": false, + "language": 1 +} \ No newline at end of file diff --git a/test/fixtures/nutrition/nutritional_plan_info_detail_response.json b/test/fixtures/nutrition/nutritional_plan_info_detail_response.json new file mode 100644 index 000000000..264f6d9a0 --- /dev/null +++ b/test/fixtures/nutrition/nutritional_plan_info_detail_response.json @@ -0,0 +1,191 @@ +{ + "id": 1, + "language": { + "id": 1, + "short_name": "de", + "full_name": "Deutsch" + }, + "creation_date": "2022-08-09", + "description": "", + "get_nutritional_values": { + "total": { + "energy": 853.0, + "protein": 12.08, + "carbohydrates": 180.7, + "carbohydrates_sugar": 139.62, + "fat": 4.92, + "fat_saturated": 0.71, + "fibres": 11.96, + "sodium": 0.48, + "energy_kilojoule": 3568.95 + }, + "percent": { + "protein": 5.66, + "carbohydrates": 84.74, + "fat": 5.19 + }, + "per_kg": { + "protein": 0.0, + "carbohydrates": 0.0, + "fat": 0.0 + } + }, + "meals": [ + { + "id": 1, + "plan": 1, + "order": 1, + "time": "08:00:00", + "name": "Frühstück", + "meal_items": [ + { + "id": 1, + "meal": 1, + "ingredient": 59887, + "ingredient_obj": { + "id": 59887, + "code": "4311501354155", + "name": "Baked Beans", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 86, + "protein": "4.400", + "carbohydrates": "11.000", + "carbohydrates_sugar": "5.300", + "fat": "0.100", + "fat_saturated": "0.000", + "fibres": "5.000", + "sodium": "0.480", + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_author": "Open Food Facts", + "ingredientweightunit_set": [], + "language": { + "id": 1, + "short_name": "de", + "full_name": "Deutsch" + } + }, + "weight_unit": null, + "weight_unit_obj": null, + "image": null, + "order": 1, + "amount": "100.00" + }, + { + "id": 2, + "meal": 1, + "ingredient": 58300, + "ingredient_obj": { + "id": 58300, + "code": "4071800000992", + "name": "1688 Mehrkorn", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 229, + "protein": "7.680", + "carbohydrates": "35.700", + "carbohydrates_sugar": "2.320", + "fat": "4.820", + "fat_saturated": "0.714", + "fibres": "6.960", + "sodium": "0.000", + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_author": "Open Food Facts", + "ingredientweightunit_set": [], + "language": { + "id": 2, + "short_name": "en", + "full_name": "English" + } + }, + "weight_unit": null, + "weight_unit_obj": null, + "image": { + "id": 3, + "uuid": "778fe5cb-a5d9-42e5-9df2-2a47022b720f", + "ingredient_id": "58300", + "ingredient_uuid": "60e1f479-9af1-4bd4-b2a8-1ebe8974258e", + "image": "http://localhost:8000/media/ingredients/60e1f479-9af1-4bd4-b2a8-1ebe8974258e/778fe5cb-a5d9-42e5-9df2-2a47022b720f.jpg", + "last_update": "2022-08-09T15:31:46.833918+02:00", + "size": 33617, + "source_url": "", + "license": 1, + "license_author": "kiliweb" + }, + "order": 1, + "amount": "100.00" + }, + { + "id": 3, + "meal": 1, + "ingredient": 10065, + "ingredient_obj": { + "id": 10065, + "code": "0043647440020", + "name": "'Old Times' Orange Fine Cut Marmalade", + "creation_date": "2020-12-20", + "update_date": "2022-08-09", + "energy": 269, + "protein": "0.000", + "carbohydrates": "67.000", + "carbohydrates_sugar": "66.000", + "fat": "0.000", + "fat_saturated": "0.000", + "fibres": null, + "sodium": "0.000", + "license": { + "id": 5, + "full_name": "Open Data Commons Open Database License", + "short_name": "ODbL", + "url": "https://opendatacommons.org/licenses/odbl/" + }, + "license_author": "Open Food Facts", + "ingredientweightunit_set": [], + "language": { + "id": 2, + "short_name": "en", + "full_name": "English" + } + }, + "weight_unit": null, + "weight_unit_obj": null, + "image": { + "id": 5, + "uuid": "81c07bef-02ea-47ba-a18e-d7388dc2bc01", + "ingredient_id": "10065", + "ingredient_uuid": "b0c47fa4-3898-4705-b8f5-184877d50b78", + "image": "http://localhost:8000/media/ingredients/b0c47fa4-3898-4705-b8f5-184877d50b78/81c07bef-02ea-47ba-a18e-d7388dc2bc01.jpg", + "last_update": "2022-08-09T15:45:58.511169+02:00", + "size": 43397, + "source_url": "", + "license": 1, + "license_author": "tacinte" + }, + "order": 1, + "amount": "200.00" + } + ], + "get_nutritional_values": { + "energy": 853.0, + "protein": 12.08, + "carbohydrates": 180.7, + "carbohydrates_sugar": 139.62, + "fat": 4.92, + "fat_saturated": 0.71, + "fibres": 11.96, + "sodium": 0.48, + "energy_kilojoule": 3568.95 + } + } + ] +} diff --git a/test/nutrition/nutrition_provider_test.dart b/test/nutrition/nutrition_provider_test.dart new file mode 100644 index 000000000..cc25b3611 --- /dev/null +++ b/test/nutrition/nutrition_provider_test.dart @@ -0,0 +1,89 @@ +import 'dart:convert'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:wger/models/nutrition/ingredient.dart'; +import 'package:wger/providers/nutrition.dart'; + +import '../fixtures/fixture_reader.dart'; +import '../measurements/measurement_provider_test.mocks.dart'; + +void main() { + late NutritionPlansProvider nutritionProvider; + late MockWgerBaseProvider mockWgerBaseProvider; + + setUp(() { + mockWgerBaseProvider = MockWgerBaseProvider(); + nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, []); + + const String planInfoUrl = 'nutritionplaninfo'; + const String planUrl = 'nutritionplan'; + const String diaryUrl = 'nutritiondiary'; + const String ingredientUrl = 'ingredient'; + + final Map NutritionalPlanInfoResponse = jsonDecode( + fixture('nutrition/nutritional_plan_info_detail_response.json'), + ); + final Map NutritionalPlanDetailResponse = jsonDecode( + fixture('nutrition/nutritional_plan_detail_response.json'), + ); + final Map NutritionDiaryResponse = jsonDecode( + fixture('nutrition/nutrition_diary_response.json'), + ); + final Map Ingredient59887Response = jsonDecode( + fixture('nutrition/ingredient_59887_response.json'), + ); + final Map Ingredient10065Response = jsonDecode( + fixture('nutrition/ingredient_10065_response.json'), + ); + final Map Ingredient58300Response = jsonDecode( + fixture('nutrition/ingredient_58300_response.json'), + ); + + final ingredientList = [ + Ingredient.fromJson(Ingredient59887Response), + Ingredient.fromJson(Ingredient10065Response), + Ingredient.fromJson(Ingredient58300Response), + ]; + + nutritionProvider.ingredients = ingredientList; + + final Uri planInfoUri = Uri( + scheme: 'http', + host: 'localhost', + path: 'api/v2/$planInfoUrl/1', + ); + final Uri planUri = Uri( + scheme: 'http', + host: 'localhost', + path: 'api/v2/$planUrl', + ); + final Uri diaryUri = Uri( + scheme: 'http', + host: 'localhost', + path: 'api/v2/$diaryUrl', + ); + when(mockWgerBaseProvider.makeUrl(planInfoUrl, id: anyNamed('id'))).thenReturn(planInfoUri); + when(mockWgerBaseProvider.makeUrl(planUrl, id: anyNamed('id'))).thenReturn(planUri); + when(mockWgerBaseProvider.makeUrl(diaryUrl, query: anyNamed('query'))).thenReturn(diaryUri); + when(mockWgerBaseProvider.fetch(planInfoUri)).thenAnswer( + (realInvocation) => Future.value(NutritionalPlanInfoResponse), + ); + when(mockWgerBaseProvider.fetch(planUri)).thenAnswer( + (realInvocation) => Future.value(NutritionalPlanDetailResponse), + ); + when(mockWgerBaseProvider.fetch(diaryUri)).thenAnswer( + (realInvocation) => Future.value(NutritionDiaryResponse), + ); + }); + + group('fetchAndSetPlanFull', () { + test('should correctly load a full nutritional plan', () async { + // arrange + await nutritionProvider.fetchAndSetPlanFull(1); + + // assert + expect(nutritionProvider.items.isEmpty, false); + }); + }); +} From d5c70b69fd8759105901067ea87f17b939572931 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 20:51:37 +0200 Subject: [PATCH 05/12] We don't use release branches anymore --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index af702a4c8..32e21c152 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # Note: these versions are set automatically during build by the android-release.yml # github action, the current versions are ignored. -# - the version number is taken from the git branch release/x.y.z +# - the version number is taken from the git tag vX.Y.Z # - the build number is computed by reading the last one from the play store and increased by one version: 1.4.2+26 From 25d22d1402f13d53fbb3cc08255ae8172ea0490e Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 21:10:06 +0200 Subject: [PATCH 06/12] Use CircleIconAvatar in the ingredient search --- lib/widgets/nutrition/widgets.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index ec2ac70b1..7e37b41a5 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -25,6 +25,7 @@ import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:provider/provider.dart'; import 'package:wger/helpers/ui.dart'; import 'package:wger/providers/nutrition.dart'; +import 'package:wger/widgets/core/core.dart'; class IngredientTypeahead extends StatefulWidget { final TextEditingController _ingredientController; @@ -78,7 +79,7 @@ class _IngredientTypeaheadState extends State { return ListTile( leading: suggestion['data']['image'] != null ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) - : const Icon(Icons.image), + : const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)), title: Text(suggestion['value']), subtitle: Text(suggestion['data']['id'].toString()), ); From dac94935ee22c9a171942b17258b141bb767219e Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 9 Aug 2022 21:10:59 +0200 Subject: [PATCH 07/12] Don't show the ingredient ID This is only useful during development or debugging, not for the user --- lib/widgets/nutrition/widgets.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 7e37b41a5..3aed571b0 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -81,7 +81,6 @@ class _IngredientTypeaheadState extends State { ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) : const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)), title: Text(suggestion['value']), - subtitle: Text(suggestion['data']['id'].toString()), ); }, transitionBuilder: (context, suggestionsBox, controller) { From 9630e2b16bbf0d03b394fe38e167d9babbe00790 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Wed, 8 Feb 2023 12:51:36 +0100 Subject: [PATCH 08/12] Recreate generated files --- lib/main.dart | 6 +- lib/models/body_weight/weight_entry.g.dart | 3 +- lib/models/exercises/category.g.dart | 3 +- lib/models/exercises/image.g.dart | 3 +- .../measurements/measurement_category.g.dart | 4 +- .../measurements/measurement_entry.g.dart | 3 +- lib/models/nutrition/image.g.dart | 3 +- lib/models/nutrition/ingredient.g.dart | 3 +- .../nutrition/ingredient_weight_unit.g.dart | 6 +- lib/models/nutrition/log.g.dart | 9 +- lib/models/nutrition/nutritional_plan.g.dart | 3 +- lib/models/nutrition/weight_unit.g.dart | 3 +- lib/models/workouts/repetition_unit.g.dart | 3 +- lib/models/workouts/session.g.dart | 12 +- lib/models/workouts/weight_unit.g.dart | 3 +- lib/models/workouts/workout_plan.g.dart | 3 +- lib/widgets/core/core.dart | 1 - .../nutritional_plan_form_test.mocks.dart | 382 ++++++------------ 18 files changed, 133 insertions(+), 320 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 561099597..7a125ae11 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -69,8 +69,7 @@ class MyApp extends StatelessWidget { create: (ctx) => AuthProvider(), ), ChangeNotifierProxyProvider( - create: (context) => ExercisesProvider( - WgerBaseProvider(context.read())), + create: (context) => ExercisesProvider(WgerBaseProvider(context.read())), update: (context, base, previous) => previous ?? ExercisesProvider(WgerBaseProvider(base)), ), @@ -106,7 +105,8 @@ class MyApp extends StatelessWidget { ), ChangeNotifierProxyProvider( create: (context) => BodyWeightProvider(WgerBaseProvider(context.read())), - update: (context, base, previous) => previous ?? BodyWeightProvider(WgerBaseProvider(base)), + update: (context, base, previous) => + previous ?? BodyWeightProvider(WgerBaseProvider(base)), ), ChangeNotifierProxyProvider( create: (context) => GalleryProvider(context.read(), []), diff --git a/lib/models/body_weight/weight_entry.g.dart b/lib/models/body_weight/weight_entry.g.dart index 60ee02c9b..d1152d20e 100644 --- a/lib/models/body_weight/weight_entry.g.dart +++ b/lib/models/body_weight/weight_entry.g.dart @@ -18,8 +18,7 @@ WeightEntry _$WeightEntryFromJson(Map json) { ); } -Map _$WeightEntryToJson(WeightEntry instance) => - { +Map _$WeightEntryToJson(WeightEntry instance) => { 'id': instance.id, 'weight': numToString(instance.weight), 'date': toDate(instance.date), diff --git a/lib/models/exercises/category.g.dart b/lib/models/exercises/category.g.dart index 19383107b..915120d13 100644 --- a/lib/models/exercises/category.g.dart +++ b/lib/models/exercises/category.g.dart @@ -17,8 +17,7 @@ ExerciseCategory _$ExerciseCategoryFromJson(Map json) { ); } -Map _$ExerciseCategoryToJson(ExerciseCategory instance) => - { +Map _$ExerciseCategoryToJson(ExerciseCategory instance) => { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/exercises/image.g.dart b/lib/models/exercises/image.g.dart index 1240dc38d..6ef7c62e4 100644 --- a/lib/models/exercises/image.g.dart +++ b/lib/models/exercises/image.g.dart @@ -20,8 +20,7 @@ ExerciseImage _$ExerciseImageFromJson(Map json) { ); } -Map _$ExerciseImageToJson(ExerciseImage instance) => - { +Map _$ExerciseImageToJson(ExerciseImage instance) => { 'id': instance.id, 'uuid': instance.uuid, 'exercise_base': instance.exerciseBaseId, diff --git a/lib/models/measurements/measurement_category.g.dart b/lib/models/measurements/measurement_category.g.dart index ef4ebcd30..eb887b2e7 100644 --- a/lib/models/measurements/measurement_category.g.dart +++ b/lib/models/measurements/measurement_category.g.dart @@ -22,9 +22,7 @@ MeasurementCategory _$MeasurementCategoryFromJson(Map json) { ); } -Map _$MeasurementCategoryToJson( - MeasurementCategory instance) => - { +Map _$MeasurementCategoryToJson(MeasurementCategory instance) => { 'id': instance.id, 'name': instance.name, 'unit': instance.unit, diff --git a/lib/models/measurements/measurement_entry.g.dart b/lib/models/measurements/measurement_entry.g.dart index 4b0969600..7f6e346ad 100644 --- a/lib/models/measurements/measurement_entry.g.dart +++ b/lib/models/measurements/measurement_entry.g.dart @@ -20,8 +20,7 @@ MeasurementEntry _$MeasurementEntryFromJson(Map json) { ); } -Map _$MeasurementEntryToJson(MeasurementEntry instance) => - { +Map _$MeasurementEntryToJson(MeasurementEntry instance) => { 'id': instance.id, 'category': instance.category, 'date': toDate(instance.date), diff --git a/lib/models/nutrition/image.g.dart b/lib/models/nutrition/image.g.dart index 5dd96e6f0..f7bfba41a 100644 --- a/lib/models/nutrition/image.g.dart +++ b/lib/models/nutrition/image.g.dart @@ -20,8 +20,7 @@ IngredientImage _$IngredientImageFromJson(Map json) { ); } -Map _$IngredientImageToJson(IngredientImage instance) => - { +Map _$IngredientImageToJson(IngredientImage instance) => { 'id': instance.id, 'uuid': instance.uuid, 'ingredient_id': instance.ingredientId, diff --git a/lib/models/nutrition/ingredient.g.dart b/lib/models/nutrition/ingredient.g.dart index cb5168ec0..bb7edb7c3 100644 --- a/lib/models/nutrition/ingredient.g.dart +++ b/lib/models/nutrition/ingredient.g.dart @@ -43,8 +43,7 @@ Ingredient _$IngredientFromJson(Map json) { ); } -Map _$IngredientToJson(Ingredient instance) => - { +Map _$IngredientToJson(Ingredient instance) => { 'id': instance.id, 'code': instance.code, 'name': instance.name, diff --git a/lib/models/nutrition/ingredient_weight_unit.g.dart b/lib/models/nutrition/ingredient_weight_unit.g.dart index 74b1f1015..f147a2ee1 100644 --- a/lib/models/nutrition/ingredient_weight_unit.g.dart +++ b/lib/models/nutrition/ingredient_weight_unit.g.dart @@ -13,16 +13,14 @@ IngredientWeightUnit _$IngredientWeightUnitFromJson(Map json) { ); return IngredientWeightUnit( id: json['id'] as int, - weightUnit: - WeightUnit.fromJson(json['weight_unit'] as Map), + weightUnit: WeightUnit.fromJson(json['weight_unit'] as Map), ingredient: Ingredient.fromJson(json['ingredient'] as Map), grams: json['grams'] as int, amount: (json['amount'] as num).toDouble(), ); } -Map _$IngredientWeightUnitToJson( - IngredientWeightUnit instance) => +Map _$IngredientWeightUnitToJson(IngredientWeightUnit instance) => { 'id': instance.id, 'weight_unit': instance.weightUnit, diff --git a/lib/models/nutrition/log.g.dart b/lib/models/nutrition/log.g.dart index 390687681..616901551 100644 --- a/lib/models/nutrition/log.g.dart +++ b/lib/models/nutrition/log.g.dart @@ -9,14 +9,7 @@ part of 'log.dart'; Log _$LogFromJson(Map json) { $checkKeys( json, - requiredKeys: const [ - 'id', - 'plan', - 'datetime', - 'ingredient', - 'weight_unit', - 'amount' - ], + requiredKeys: const ['id', 'plan', 'datetime', 'ingredient', 'weight_unit', 'amount'], ); return Log( id: json['id'] as int?, diff --git a/lib/models/nutrition/nutritional_plan.g.dart b/lib/models/nutrition/nutritional_plan.g.dart index 9b10d8a5a..661a9f47a 100644 --- a/lib/models/nutrition/nutritional_plan.g.dart +++ b/lib/models/nutrition/nutritional_plan.g.dart @@ -18,8 +18,7 @@ NutritionalPlan _$NutritionalPlanFromJson(Map json) { ); } -Map _$NutritionalPlanToJson(NutritionalPlan instance) => - { +Map _$NutritionalPlanToJson(NutritionalPlan instance) => { 'id': instance.id, 'description': instance.description, 'creation_date': toDate(instance.creationDate), diff --git a/lib/models/nutrition/weight_unit.g.dart b/lib/models/nutrition/weight_unit.g.dart index 74e1f0cfb..6f2b9607e 100644 --- a/lib/models/nutrition/weight_unit.g.dart +++ b/lib/models/nutrition/weight_unit.g.dart @@ -17,8 +17,7 @@ WeightUnit _$WeightUnitFromJson(Map json) { ); } -Map _$WeightUnitToJson(WeightUnit instance) => - { +Map _$WeightUnitToJson(WeightUnit instance) => { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/repetition_unit.g.dart b/lib/models/workouts/repetition_unit.g.dart index 115dc338c..33e6a815e 100644 --- a/lib/models/workouts/repetition_unit.g.dart +++ b/lib/models/workouts/repetition_unit.g.dart @@ -17,8 +17,7 @@ RepetitionUnit _$RepetitionUnitFromJson(Map json) { ); } -Map _$RepetitionUnitToJson(RepetitionUnit instance) => - { +Map _$RepetitionUnitToJson(RepetitionUnit instance) => { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/session.g.dart b/lib/models/workouts/session.g.dart index e16affadb..79f4fee41 100644 --- a/lib/models/workouts/session.g.dart +++ b/lib/models/workouts/session.g.dart @@ -9,14 +9,7 @@ part of 'session.dart'; WorkoutSession _$WorkoutSessionFromJson(Map json) { $checkKeys( json, - requiredKeys: const [ - 'id', - 'workout', - 'date', - 'impression', - 'time_start', - 'time_end' - ], + requiredKeys: const ['id', 'workout', 'date', 'impression', 'time_start', 'time_end'], ); return WorkoutSession() ..id = json['id'] as int? @@ -28,8 +21,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map json) { ..timeEnd = stringToTime(json['time_end'] as String?); } -Map _$WorkoutSessionToJson(WorkoutSession instance) => - { +Map _$WorkoutSessionToJson(WorkoutSession instance) => { 'id': instance.id, 'workout': instance.workoutId, 'date': toDate(instance.date), diff --git a/lib/models/workouts/weight_unit.g.dart b/lib/models/workouts/weight_unit.g.dart index 74e1f0cfb..6f2b9607e 100644 --- a/lib/models/workouts/weight_unit.g.dart +++ b/lib/models/workouts/weight_unit.g.dart @@ -17,8 +17,7 @@ WeightUnit _$WeightUnitFromJson(Map json) { ); } -Map _$WeightUnitToJson(WeightUnit instance) => - { +Map _$WeightUnitToJson(WeightUnit instance) => { 'id': instance.id, 'name': instance.name, }; diff --git a/lib/models/workouts/workout_plan.g.dart b/lib/models/workouts/workout_plan.g.dart index ef156e3e0..ac1d6fa9f 100644 --- a/lib/models/workouts/workout_plan.g.dart +++ b/lib/models/workouts/workout_plan.g.dart @@ -19,8 +19,7 @@ WorkoutPlan _$WorkoutPlanFromJson(Map json) { ); } -Map _$WorkoutPlanToJson(WorkoutPlan instance) => - { +Map _$WorkoutPlanToJson(WorkoutPlan instance) => { 'id': instance.id, 'creation_date': instance.creationDate.toIso8601String(), 'name': instance.name, diff --git a/lib/widgets/core/core.dart b/lib/widgets/core/core.dart index d99fc9d11..d61e5939f 100644 --- a/lib/widgets/core/core.dart +++ b/lib/widgets/core/core.dart @@ -59,7 +59,6 @@ class Pill extends StatelessWidget { } } - class CircleIconAvatar extends StatelessWidget { final double radius; final Icon _icon; diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index 9d060eddb..fde0989ae 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -3,17 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i9; -import 'dart:ui' as _i10; +import 'dart:async' as _i8; +import 'dart:ui' as _i9; -import 'package:http/http.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i7; -import 'package:wger/models/nutrition/meal.dart' as _i5; -import 'package:wger/models/nutrition/meal_item.dart' as _i6; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; -import 'package:wger/providers/auth.dart' as _i2; -import 'package:wger/providers/nutrition.dart' as _i8; +import 'package:wger/models/nutrition/ingredient.dart' as _i6; +import 'package:wger/models/nutrition/meal.dart' as _i4; +import 'package:wger/models/nutrition/meal_item.dart' as _i5; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3; +import 'package:wger/providers/base_provider.dart' as _i2; +import 'package:wger/providers/nutrition.dart' as _i7; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -26,8 +25,8 @@ import 'package:wger/providers/nutrition.dart' as _i8; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { - _FakeAuthProvider_0( +class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider { + _FakeWgerBaseProvider_0( Object parent, Invocation parentInvocation, ) : super( @@ -36,8 +35,8 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { ); } -class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { - _FakeClient_1( +class _FakeNutritionalPlan_1 extends _i1.SmartFake implements _i3.NutritionalPlan { + _FakeNutritionalPlan_1( Object parent, Invocation parentInvocation, ) : super( @@ -46,8 +45,8 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { ); } -class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan { - _FakeNutritionalPlan_2( +class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal { + _FakeMeal_2( Object parent, Invocation parentInvocation, ) : super( @@ -56,8 +55,8 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla ); } -class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { - _FakeMeal_3( +class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem { + _FakeMealItem_3( Object parent, Invocation parentInvocation, ) : super( @@ -66,38 +65,8 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { ); } -class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem { - _FakeMealItem_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient { - _FakeIngredient_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeUri_6 extends _i1.SmartFake implements Uri { - _FakeUri_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { - _FakeResponse_7( +class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient { + _FakeIngredient_4( Object parent, Invocation parentInvocation, ) : super( @@ -109,45 +78,29 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { /// A class which mocks [NutritionPlansProvider]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansProvider { +class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansProvider { MockNutritionPlansProvider() { _i1.throwOnMissingStub(this); } @override - List<_i4.NutritionalPlan> get items => (super.noSuchMethod( - Invocation.getter(#items), - returnValue: <_i4.NutritionalPlan>[], - ) as List<_i4.NutritionalPlan>); - @override - _i2.AuthProvider get auth => (super.noSuchMethod( - Invocation.getter(#auth), - returnValue: _FakeAuthProvider_0( + _i2.WgerBaseProvider get baseProvider => (super.noSuchMethod( + Invocation.getter(#baseProvider), + returnValue: _FakeWgerBaseProvider_0( this, - Invocation.getter(#auth), + Invocation.getter(#baseProvider), ), - ) as _i2.AuthProvider); - @override - set auth(_i2.AuthProvider? _auth) => super.noSuchMethod( - Invocation.setter( - #auth, - _auth, - ), - returnValueForMissingStub: null, - ); + ) as _i2.WgerBaseProvider); @override - _i3.Client get client => (super.noSuchMethod( - Invocation.getter(#client), - returnValue: _FakeClient_1( - this, - Invocation.getter(#client), - ), - ) as _i3.Client); + List<_i3.NutritionalPlan> get items => (super.noSuchMethod( + Invocation.getter(#items), + returnValue: <_i3.NutritionalPlan>[], + ) as List<_i3.NutritionalPlan>); @override - set client(_i3.Client? _client) => super.noSuchMethod( + set ingredients(dynamic items) => super.noSuchMethod( Invocation.setter( - #client, - _client, + #ingredients, + items, ), returnValueForMissingStub: null, ); @@ -165,105 +118,105 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValueForMissingStub: null, ); @override - _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i3.NutritionalPlan findById(int? id) => (super.noSuchMethod( Invocation.method( #findById, [id], ), - returnValue: _FakeNutritionalPlan_2( + returnValue: _FakeNutritionalPlan_1( this, Invocation.method( #findById, [id], ), ), - ) as _i4.NutritionalPlan); + ) as _i3.NutritionalPlan); @override - _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( + _i4.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( #findMealById, [id], - )) as _i5.Meal?); + )) as _i4.Meal?); @override - _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( Invocation.method( #fetchAndSetAllPlansSparse, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( Invocation.method( #fetchAndSetAllPlansFull, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method( #fetchAndSetPlanSparse, [planId], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #fetchAndSetPlanSparse, [planId], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod( Invocation.method( #fetchAndSetPlanFull, [planId], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #fetchAndSetPlanFull, [planId], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) => (super.noSuchMethod( Invocation.method( #addPlan, [planData], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #addPlan, [planData], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + _i8.Future editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method( #editPlan, [plan], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod( + _i8.Future deletePlan(int? id) => (super.noSuchMethod( Invocation.method( #deletePlan, [id], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i5.Meal> addMeal( - _i5.Meal? meal, + _i8.Future<_i4.Meal> addMeal( + _i4.Meal? meal, int? planId, ) => (super.noSuchMethod( @@ -274,7 +227,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP planId, ], ), - returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2( this, Invocation.method( #addMeal, @@ -284,34 +237,34 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ], ), )), - ) as _i9.Future<_i5.Meal>); + ) as _i8.Future<_i4.Meal>); @override - _i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #editMeal, [meal], ), - returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2( this, Invocation.method( #editMeal, [meal], ), )), - ) as _i9.Future<_i5.Meal>); + ) as _i8.Future<_i4.Meal>); @override - _i9.Future deleteMeal(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future deleteMeal(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #deleteMeal, [meal], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i6.MealItem> addMealItem( - _i6.MealItem? mealItem, - _i5.Meal? meal, + _i8.Future<_i5.MealItem> addMealItem( + _i5.MealItem? mealItem, + _i4.Meal? meal, ) => (super.noSuchMethod( Invocation.method( @@ -321,7 +274,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP meal, ], ), - returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4( + returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3( this, Invocation.method( #addMealItem, @@ -331,41 +284,41 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ], ), )), - ) as _i9.Future<_i6.MealItem>); + ) as _i8.Future<_i5.MealItem>); @override - _i9.Future deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod( + _i8.Future deleteMealItem(_i5.MealItem? mealItem) => (super.noSuchMethod( Invocation.method( #deleteMealItem, [mealItem], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod( + _i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod( Invocation.method( #fetchIngredient, [ingredientId], ), - returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5( + returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4( this, Invocation.method( #fetchIngredient, [ingredientId], ), )), - ) as _i9.Future<_i7.Ingredient>); + ) as _i8.Future<_i6.Ingredient>); @override - _i9.Future fetchIngredientsFromCache() => (super.noSuchMethod( + _i8.Future fetchIngredientsFromCache() => (super.noSuchMethod( Invocation.method( #fetchIngredientsFromCache, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future> searchIngredient( + _i8.Future> searchIngredient( String? name, [ String? languageCode = r'en', ]) => @@ -377,28 +330,28 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP languageCode, ], ), - returnValue: _i9.Future>.value([]), - ) as _i9.Future>); + returnValue: _i8.Future>.value([]), + ) as _i8.Future>); @override - _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod( + _i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [code], ), - returnValue: _i9.Future<_i7.Ingredient?>.value(), - ) as _i9.Future<_i7.Ingredient?>); + returnValue: _i8.Future<_i6.Ingredient?>.value(), + ) as _i8.Future<_i6.Ingredient?>); @override - _i9.Future logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #logMealToDiary, [meal], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future logIngredentToDiary( - _i6.MealItem? mealItem, + _i8.Future logIngredentToDiary( + _i5.MealItem? mealItem, int? planId, [ DateTime? dateTime, ]) => @@ -411,11 +364,11 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP dateTime, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future deleteLog( + _i8.Future deleteLog( int? logId, int? planId, ) => @@ -427,129 +380,20 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP planId, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + _i8.Future fetchAndSetLogs(_i3.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method( #fetchAndSetLogs, [plan], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); - @override - Map getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod( - Invocation.method( - #getDefaultHeaders, - [], - {#includeAuth: includeAuth}, - ), - returnValue: {}, - ) as Map); - @override - Uri makeUrl( - String? path, { - int? id, - String? objectMethod, - Map? query, - }) => - (super.noSuchMethod( - Invocation.method( - #makeUrl, - [path], - { - #id: id, - #objectMethod: objectMethod, - #query: query, - }, - ), - returnValue: _FakeUri_6( - this, - Invocation.method( - #makeUrl, - [path], - { - #id: id, - #objectMethod: objectMethod, - #query: query, - }, - ), - ), - ) as Uri); - @override - _i9.Future> fetch(Uri? uri) => (super.noSuchMethod( - Invocation.method( - #fetch, - [uri], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future> fetchPaginated(Uri? uri) => (super.noSuchMethod( - Invocation.method( - #fetchPaginated, - [uri], - ), - returnValue: _i9.Future>.value([]), - ) as _i9.Future>); - @override - _i9.Future> post( - Map? data, - Uri? uri, - ) => - (super.noSuchMethod( - Invocation.method( - #post, - [ - data, - uri, - ], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future> patch( - Map? data, - Uri? uri, - ) => - (super.noSuchMethod( - Invocation.method( - #patch, - [ - data, - uri, - ], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future<_i3.Response> deleteRequest( - String? url, - int? id, - ) => - (super.noSuchMethod( - Invocation.method( - #deleteRequest, - [ - url, - id, - ], - ), - returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7( - this, - Invocation.method( - #deleteRequest, - [ - url, - id, - ], - ), - )), - ) as _i9.Future<_i3.Response>); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - void addListener(_i10.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i9.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -557,7 +401,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValueForMissingStub: null, ); @override - void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i9.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], From fa8dd7e46fc25020f0046dcb2edd9ed72674eeba Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 20 Mar 2023 14:19:29 +0100 Subject: [PATCH 09/12] Fix merge errors --- integration_test/5_nutritional_plan.dart | 8 +- lib/main.dart | 9 +- lib/providers/nutrition.dart | 7 +- .../nutritional_meal_form_test.mocks.dart | 382 ++++++------------ .../nutritional_plan_screen_test.dart | 5 +- .../nutritional_plans_screen_test.dart | 11 +- .../nutritional_plans_screen_test.mocks.dart | 212 +++++++++- 7 files changed, 326 insertions(+), 308 deletions(-) diff --git a/integration_test/5_nutritional_plan.dart b/integration_test/5_nutritional_plan.dart index cfbf66102..2b258299d 100644 --- a/integration_test/5_nutritional_plan.dart +++ b/integration_test/5_nutritional_plan.dart @@ -11,12 +11,12 @@ import 'package:wger/providers/nutrition.dart'; import 'package:wger/screens/nutritional_plan_screen.dart'; import 'package:wger/theme/theme.dart'; -import '../test/other/base_provider_test.mocks.dart'; -import '../test/utils.dart'; +import '../test/user/provider_test.mocks.dart'; Widget createNutritionalPlanScreen({locale = 'en'}) { + var mockBaseProvider = MockWgerBaseProvider(); + final key = GlobalKey(); - final client = MockClient(); final muesli = Ingredient( id: 1, @@ -96,7 +96,7 @@ Widget createNutritionalPlanScreen({locale = 'en'}) { return MultiProvider( providers: [ ChangeNotifierProvider( - create: (context) => NutritionPlansProvider(testAuthProvider, [], client), + create: (context) => NutritionPlansProvider(mockBaseProvider, []), ), ChangeNotifierProvider( create: (context) => BodyWeightProvider(mockBaseProvider), diff --git a/lib/main.dart b/lib/main.dart index 5977949b0..90dadd909 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -84,9 +84,12 @@ class MyApp extends StatelessWidget { previous ?? WorkoutPlansProvider(WgerBaseProvider(auth), exercises, []), ), ChangeNotifierProxyProvider( - create: (context) => - NutritionPlansProvider(Provider.of(context, listen: false), []), - update: (context, auth, previous) => previous ?? NutritionPlansProvider(auth, []), + create: (context) => NutritionPlansProvider( + WgerBaseProvider(Provider.of(context, listen: false)), + [], + ), + update: (context, auth, previous) => + previous ?? NutritionPlansProvider(WgerBaseProvider(auth), []), ), ChangeNotifierProxyProvider( create: (context) => MeasurementProvider( diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index ee6c9074c..0af0ee58d 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -90,9 +90,10 @@ class NutritionPlansProvider with ChangeNotifier { /// Fetches and sets all plans sparsely, i.e. only with the data on the plan /// object itself and no child attributes Future fetchAndSetAllPlansSparse() async { - final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'})); + final data = await baseProvider + .fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'})); _plans = []; - for (final planData in data['results']) { + for (final planData in data) { final plan = NutritionalPlan.fromJson(planData); _plans.add(plan); _plans.sort((a, b) => b.creationDate.compareTo(a.creationDate)); @@ -128,7 +129,7 @@ class NutritionPlansProvider with ChangeNotifier { NutritionalPlan plan; try { plan = findById(planId); - } on NoSuchEntryException catch (e) { + } on NoSuchEntryException { plan = await fetchAndSetPlanSparse(planId); } diff --git a/test/nutrition/nutritional_meal_form_test.mocks.dart b/test/nutrition/nutritional_meal_form_test.mocks.dart index a91aaed5d..dfdd9086a 100644 --- a/test/nutrition/nutritional_meal_form_test.mocks.dart +++ b/test/nutrition/nutritional_meal_form_test.mocks.dart @@ -3,17 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i9; -import 'dart:ui' as _i10; +import 'dart:async' as _i8; +import 'dart:ui' as _i9; -import 'package:http/http.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i7; -import 'package:wger/models/nutrition/meal.dart' as _i5; -import 'package:wger/models/nutrition/meal_item.dart' as _i6; -import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4; -import 'package:wger/providers/auth.dart' as _i2; -import 'package:wger/providers/nutrition.dart' as _i8; +import 'package:wger/models/nutrition/ingredient.dart' as _i6; +import 'package:wger/models/nutrition/meal.dart' as _i4; +import 'package:wger/models/nutrition/meal_item.dart' as _i5; +import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3; +import 'package:wger/providers/base_provider.dart' as _i2; +import 'package:wger/providers/nutrition.dart' as _i7; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -26,8 +25,8 @@ import 'package:wger/providers/nutrition.dart' as _i8; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { - _FakeAuthProvider_0( +class _FakeWgerBaseProvider_0 extends _i1.SmartFake implements _i2.WgerBaseProvider { + _FakeWgerBaseProvider_0( Object parent, Invocation parentInvocation, ) : super( @@ -36,8 +35,8 @@ class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { ); } -class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { - _FakeClient_1( +class _FakeNutritionalPlan_1 extends _i1.SmartFake implements _i3.NutritionalPlan { + _FakeNutritionalPlan_1( Object parent, Invocation parentInvocation, ) : super( @@ -46,8 +45,8 @@ class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { ); } -class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPlan { - _FakeNutritionalPlan_2( +class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal { + _FakeMeal_2( Object parent, Invocation parentInvocation, ) : super( @@ -56,8 +55,8 @@ class _FakeNutritionalPlan_2 extends _i1.SmartFake implements _i4.NutritionalPla ); } -class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { - _FakeMeal_3( +class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem { + _FakeMealItem_3( Object parent, Invocation parentInvocation, ) : super( @@ -66,38 +65,8 @@ class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal { ); } -class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem { - _FakeMealItem_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient { - _FakeIngredient_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeUri_6 extends _i1.SmartFake implements Uri { - _FakeUri_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { - _FakeResponse_7( +class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient { + _FakeIngredient_4( Object parent, Invocation parentInvocation, ) : super( @@ -109,45 +78,29 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response { /// A class which mocks [NutritionPlansProvider]. /// /// See the documentation for Mockito's code generation for more information. -class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansProvider { +class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansProvider { MockNutritionPlansProvider() { _i1.throwOnMissingStub(this); } @override - List<_i4.NutritionalPlan> get items => (super.noSuchMethod( - Invocation.getter(#items), - returnValue: <_i4.NutritionalPlan>[], - ) as List<_i4.NutritionalPlan>); - @override - _i2.AuthProvider get auth => (super.noSuchMethod( - Invocation.getter(#auth), - returnValue: _FakeAuthProvider_0( + _i2.WgerBaseProvider get baseProvider => (super.noSuchMethod( + Invocation.getter(#baseProvider), + returnValue: _FakeWgerBaseProvider_0( this, - Invocation.getter(#auth), + Invocation.getter(#baseProvider), ), - ) as _i2.AuthProvider); - @override - set auth(_i2.AuthProvider? _auth) => super.noSuchMethod( - Invocation.setter( - #auth, - _auth, - ), - returnValueForMissingStub: null, - ); + ) as _i2.WgerBaseProvider); @override - _i3.Client get client => (super.noSuchMethod( - Invocation.getter(#client), - returnValue: _FakeClient_1( - this, - Invocation.getter(#client), - ), - ) as _i3.Client); + List<_i3.NutritionalPlan> get items => (super.noSuchMethod( + Invocation.getter(#items), + returnValue: <_i3.NutritionalPlan>[], + ) as List<_i3.NutritionalPlan>); @override - set client(_i3.Client? _client) => super.noSuchMethod( + set ingredients(dynamic items) => super.noSuchMethod( Invocation.setter( - #client, - _client, + #ingredients, + items, ), returnValueForMissingStub: null, ); @@ -165,105 +118,105 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValueForMissingStub: null, ); @override - _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i3.NutritionalPlan findById(int? id) => (super.noSuchMethod( Invocation.method( #findById, [id], ), - returnValue: _FakeNutritionalPlan_2( + returnValue: _FakeNutritionalPlan_1( this, Invocation.method( #findById, [id], ), ), - ) as _i4.NutritionalPlan); + ) as _i3.NutritionalPlan); @override - _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( + _i4.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( #findMealById, [id], - )) as _i5.Meal?); + )) as _i4.Meal?); @override - _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( Invocation.method( #fetchAndSetAllPlansSparse, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + _i8.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( Invocation.method( #fetchAndSetAllPlansFull, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod( Invocation.method( #fetchAndSetPlanSparse, [planId], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #fetchAndSetPlanSparse, [planId], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super.noSuchMethod( Invocation.method( #fetchAndSetPlanFull, [planId], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #fetchAndSetPlanFull, [planId], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => (super.noSuchMethod( + _i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) => (super.noSuchMethod( Invocation.method( #addPlan, [planData], ), - returnValue: _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( + returnValue: _i8.Future<_i3.NutritionalPlan>.value(_FakeNutritionalPlan_1( this, Invocation.method( #addPlan, [planData], ), )), - ) as _i9.Future<_i4.NutritionalPlan>); + ) as _i8.Future<_i3.NutritionalPlan>); @override - _i9.Future editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + _i8.Future editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method( #editPlan, [plan], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod( + _i8.Future deletePlan(int? id) => (super.noSuchMethod( Invocation.method( #deletePlan, [id], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i5.Meal> addMeal( - _i5.Meal? meal, + _i8.Future<_i4.Meal> addMeal( + _i4.Meal? meal, int? planId, ) => (super.noSuchMethod( @@ -274,7 +227,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP planId, ], ), - returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2( this, Invocation.method( #addMeal, @@ -284,34 +237,34 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ], ), )), - ) as _i9.Future<_i5.Meal>); + ) as _i8.Future<_i4.Meal>); @override - _i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #editMeal, [meal], ), - returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3( + returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2( this, Invocation.method( #editMeal, [meal], ), )), - ) as _i9.Future<_i5.Meal>); + ) as _i8.Future<_i4.Meal>); @override - _i9.Future deleteMeal(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future deleteMeal(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #deleteMeal, [meal], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i6.MealItem> addMealItem( - _i6.MealItem? mealItem, - _i5.Meal? meal, + _i8.Future<_i5.MealItem> addMealItem( + _i5.MealItem? mealItem, + _i4.Meal? meal, ) => (super.noSuchMethod( Invocation.method( @@ -321,7 +274,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP meal, ], ), - returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4( + returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3( this, Invocation.method( #addMealItem, @@ -331,41 +284,41 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP ], ), )), - ) as _i9.Future<_i6.MealItem>); + ) as _i8.Future<_i5.MealItem>); @override - _i9.Future deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod( + _i8.Future deleteMealItem(_i5.MealItem? mealItem) => (super.noSuchMethod( Invocation.method( #deleteMealItem, [mealItem], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod( + _i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) => (super.noSuchMethod( Invocation.method( #fetchIngredient, [ingredientId], ), - returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5( + returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4( this, Invocation.method( #fetchIngredient, [ingredientId], ), )), - ) as _i9.Future<_i7.Ingredient>); + ) as _i8.Future<_i6.Ingredient>); @override - _i9.Future fetchIngredientsFromCache() => (super.noSuchMethod( + _i8.Future fetchIngredientsFromCache() => (super.noSuchMethod( Invocation.method( #fetchIngredientsFromCache, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future> searchIngredient( + _i8.Future> searchIngredient( String? name, [ String? languageCode = r'en', ]) => @@ -377,28 +330,28 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP languageCode, ], ), - returnValue: _i9.Future>.value([]), - ) as _i9.Future>); + returnValue: _i8.Future>.value([]), + ) as _i8.Future>); @override - _i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod( + _i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) => (super.noSuchMethod( Invocation.method( #searchIngredientWithCode, [code], ), - returnValue: _i9.Future<_i7.Ingredient?>.value(), - ) as _i9.Future<_i7.Ingredient?>); + returnValue: _i8.Future<_i6.Ingredient?>.value(), + ) as _i8.Future<_i6.Ingredient?>); @override - _i9.Future logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod( + _i8.Future logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod( Invocation.method( #logMealToDiary, [meal], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future logIngredentToDiary( - _i6.MealItem? mealItem, + _i8.Future logIngredentToDiary( + _i5.MealItem? mealItem, int? planId, [ DateTime? dateTime, ]) => @@ -411,11 +364,11 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP dateTime, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future deleteLog( + _i8.Future deleteLog( int? logId, int? planId, ) => @@ -427,129 +380,20 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP planId, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future fetchAndSetLogs(_i4.NutritionalPlan? plan) => (super.noSuchMethod( + _i8.Future fetchAndSetLogs(_i3.NutritionalPlan? plan) => (super.noSuchMethod( Invocation.method( #fetchAndSetLogs, [plan], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); - @override - Map getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod( - Invocation.method( - #getDefaultHeaders, - [], - {#includeAuth: includeAuth}, - ), - returnValue: {}, - ) as Map); - @override - Uri makeUrl( - String? path, { - int? id, - String? objectMethod, - Map? query, - }) => - (super.noSuchMethod( - Invocation.method( - #makeUrl, - [path], - { - #id: id, - #objectMethod: objectMethod, - #query: query, - }, - ), - returnValue: _FakeUri_6( - this, - Invocation.method( - #makeUrl, - [path], - { - #id: id, - #objectMethod: objectMethod, - #query: query, - }, - ), - ), - ) as Uri); - @override - _i9.Future> fetch(Uri? uri) => (super.noSuchMethod( - Invocation.method( - #fetch, - [uri], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future> fetchPaginated(Uri? uri) => (super.noSuchMethod( - Invocation.method( - #fetchPaginated, - [uri], - ), - returnValue: _i9.Future>.value([]), - ) as _i9.Future>); - @override - _i9.Future> post( - Map? data, - Uri? uri, - ) => - (super.noSuchMethod( - Invocation.method( - #post, - [ - data, - uri, - ], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future> patch( - Map? data, - Uri? uri, - ) => - (super.noSuchMethod( - Invocation.method( - #patch, - [ - data, - uri, - ], - ), - returnValue: _i9.Future>.value({}), - ) as _i9.Future>); - @override - _i9.Future<_i3.Response> deleteRequest( - String? url, - int? id, - ) => - (super.noSuchMethod( - Invocation.method( - #deleteRequest, - [ - url, - id, - ], - ), - returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7( - this, - Invocation.method( - #deleteRequest, - [ - url, - id, - ], - ), - )), - ) as _i9.Future<_i3.Response>); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - void addListener(_i10.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i9.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -557,7 +401,7 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValueForMissingStub: null, ); @override - void removeListener(_i10.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i9.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], diff --git a/test/nutrition/nutritional_plan_screen_test.dart b/test/nutrition/nutritional_plan_screen_test.dart index d41cf31be..b2419ddad 100644 --- a/test/nutrition/nutritional_plan_screen_test.dart +++ b/test/nutrition/nutritional_plan_screen_test.dart @@ -31,22 +31,19 @@ import 'package:wger/widgets/nutrition/charts.dart'; import '../../test_data/nutritional_plans.dart'; import 'nutritional_plan_screen_test.mocks.dart'; -import '../utils.dart'; @GenerateMocks([WgerBaseProvider, AuthProvider, http.Client]) void main() { Widget createNutritionalPlan({locale = 'en'}) { final key = GlobalKey(); - final client = MockClient(); final mockBaseProvider = MockWgerBaseProvider(); - final mockAuthProvider = MockAuthProvider(); final plan = getNutritionalPlan(); return MultiProvider( providers: [ ChangeNotifierProvider( - create: (context) => NutritionPlansProvider(mockAuthProvider, [], client), + create: (context) => NutritionPlansProvider(mockBaseProvider, []), ), ChangeNotifierProvider( create: (context) => BodyWeightProvider(mockBaseProvider), diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index 066ecc6f0..b7fd34dcd 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -25,6 +25,7 @@ import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/auth.dart'; +import 'package:wger/providers/base_provider.dart'; import 'package:wger/providers/nutrition.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/nutritional_plans_screen.dart'; @@ -32,9 +33,10 @@ import 'package:wger/widgets/nutrition/forms.dart'; import 'nutritional_plan_screen_test.mocks.dart'; -@GenerateMocks([AuthProvider, http.Client]) +@GenerateMocks([AuthProvider, WgerBaseProvider, http.Client]) void main() { final mockAuthProvider = MockAuthProvider(); + final mockBaseProvider = MockWgerBaseProvider(); final client = MockClient(); Widget createHomeScreen({locale = 'en'}) { @@ -43,8 +45,8 @@ void main() { headers: anyNamed('headers'), )).thenAnswer((_) async => http.Response('', 200)); - when(mockWgerBaseProvider.deleteRequest(any, any)).thenAnswer( - (_) async => http.Response('', 200), + when(mockBaseProvider.deleteRequest(any, any)).thenAnswer( + (_) async => http.Response('', 200), ); when(mockAuthProvider.token).thenReturn('1234'); @@ -53,7 +55,7 @@ void main() { return ChangeNotifierProvider( create: (context) => NutritionPlansProvider( - mockAuthProvider, + mockBaseProvider, [ NutritionalPlan( id: 1, @@ -66,7 +68,6 @@ void main() { creationDate: DateTime(2021, 01, 10), ), ], - client, ), child: MaterialApp( locale: Locale(locale), diff --git a/test/nutrition/nutritional_plans_screen_test.mocks.dart b/test/nutrition/nutritional_plans_screen_test.mocks.dart index d38144701..8e5e3589d 100644 --- a/test/nutrition/nutritional_plans_screen_test.mocks.dart +++ b/test/nutrition/nutritional_plans_screen_test.mocks.dart @@ -4,14 +4,15 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i5; -import 'dart:convert' as _i7; -import 'dart:typed_data' as _i8; +import 'dart:convert' as _i8; +import 'dart:typed_data' as _i9; import 'dart:ui' as _i6; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:package_info/package_info.dart' as _i4; import 'package:wger/providers/auth.dart' as _i3; +import 'package:wger/providers/base_provider.dart' as _i7; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -34,8 +35,8 @@ class _FakeClient_0 extends _i1.SmartFake implements _i2.Client { ); } -class _FakeResponse_1 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_1( +class _FakeAuthProvider_1 extends _i1.SmartFake implements _i3.AuthProvider { + _FakeAuthProvider_1( Object parent, Invocation parentInvocation, ) : super( @@ -44,8 +45,28 @@ class _FakeResponse_1 extends _i1.SmartFake implements _i2.Response { ); } -class _FakeStreamedResponse_2 extends _i1.SmartFake implements _i2.StreamedResponse { - _FakeStreamedResponse_2( +class _FakeUri_2 extends _i1.SmartFake implements Uri { + _FakeUri_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeResponse_3 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStreamedResponse_4 extends _i1.SmartFake implements _i2.StreamedResponse { + _FakeStreamedResponse_4( Object parent, Invocation parentInvocation, ) : super( @@ -293,6 +314,157 @@ class MockAuthProvider extends _i1.Mock implements _i3.AuthProvider { ); } +/// A class which mocks [WgerBaseProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWgerBaseProvider extends _i1.Mock implements _i7.WgerBaseProvider { + MockWgerBaseProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i3.AuthProvider get auth => (super.noSuchMethod( + Invocation.getter(#auth), + returnValue: _FakeAuthProvider_1( + this, + Invocation.getter(#auth), + ), + ) as _i3.AuthProvider); + @override + set auth(_i3.AuthProvider? _auth) => super.noSuchMethod( + Invocation.setter( + #auth, + _auth, + ), + returnValueForMissingStub: null, + ); + @override + _i2.Client get client => (super.noSuchMethod( + Invocation.getter(#client), + returnValue: _FakeClient_0( + this, + Invocation.getter(#client), + ), + ) as _i2.Client); + @override + set client(_i2.Client? _client) => super.noSuchMethod( + Invocation.setter( + #client, + _client, + ), + returnValueForMissingStub: null, + ); + @override + Map getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod( + Invocation.method( + #getDefaultHeaders, + [], + {#includeAuth: includeAuth}, + ), + returnValue: {}, + ) as Map); + @override + Uri makeUrl( + String? path, { + int? id, + String? objectMethod, + Map? query, + }) => + (super.noSuchMethod( + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + returnValue: _FakeUri_2( + this, + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + ), + ) as Uri); + @override + _i5.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetch, + [uri], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future> fetchPaginated(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetchPaginated, + [uri], + ), + returnValue: _i5.Future>.value([]), + ) as _i5.Future>); + @override + _i5.Future> post( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #post, + [ + data, + uri, + ], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future> patch( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #patch, + [ + data, + uri, + ], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future<_i2.Response> deleteRequest( + String? url, + int? id, + ) => + (super.noSuchMethod( + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( + this, + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + )), + ) as _i5.Future<_i2.Response>); +} + /// A class which mocks [Client]. /// /// See the documentation for Mockito's code generation for more information. @@ -312,7 +484,7 @@ class MockClient extends _i1.Mock implements _i2.Client { [url], {#headers: headers}, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #head, @@ -332,7 +504,7 @@ class MockClient extends _i1.Mock implements _i2.Client { [url], {#headers: headers}, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #get, @@ -346,7 +518,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i7.Encoding? encoding, + _i8.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -358,7 +530,7 @@ class MockClient extends _i1.Mock implements _i2.Client { #encoding: encoding, }, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #post, @@ -376,7 +548,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i7.Encoding? encoding, + _i8.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -388,7 +560,7 @@ class MockClient extends _i1.Mock implements _i2.Client { #encoding: encoding, }, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #put, @@ -406,7 +578,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i7.Encoding? encoding, + _i8.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -418,7 +590,7 @@ class MockClient extends _i1.Mock implements _i2.Client { #encoding: encoding, }, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #patch, @@ -436,7 +608,7 @@ class MockClient extends _i1.Mock implements _i2.Client { Uri? url, { Map? headers, Object? body, - _i7.Encoding? encoding, + _i8.Encoding? encoding, }) => (super.noSuchMethod( Invocation.method( @@ -448,7 +620,7 @@ class MockClient extends _i1.Mock implements _i2.Client { #encoding: encoding, }, ), - returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_1( + returnValue: _i5.Future<_i2.Response>.value(_FakeResponse_3( this, Invocation.method( #delete, @@ -475,7 +647,7 @@ class MockClient extends _i1.Mock implements _i2.Client { returnValue: _i5.Future.value(''), ) as _i5.Future); @override - _i5.Future<_i8.Uint8List> readBytes( + _i5.Future<_i9.Uint8List> readBytes( Uri? url, { Map? headers, }) => @@ -485,15 +657,15 @@ class MockClient extends _i1.Mock implements _i2.Client { [url], {#headers: headers}, ), - returnValue: _i5.Future<_i8.Uint8List>.value(_i8.Uint8List(0)), - ) as _i5.Future<_i8.Uint8List>); + returnValue: _i5.Future<_i9.Uint8List>.value(_i9.Uint8List(0)), + ) as _i5.Future<_i9.Uint8List>); @override _i5.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => (super.noSuchMethod( Invocation.method( #send, [request], ), - returnValue: _i5.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_2( + returnValue: _i5.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_4( this, Invocation.method( #send, From 984df49c414eb422a4336d81b8a71cc5d3412b54 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 20 Mar 2023 17:14:12 +0100 Subject: [PATCH 10/12] Add switch to search for ingredients in English as well --- lib/providers/nutrition.dart | 16 +- lib/widgets/nutrition/forms.dart | 13 +- lib/widgets/nutrition/widgets.dart | 237 ++++++++++-------- .../nutritional_meal_form_test.mocks.dart | 14 +- .../nutritional_meal_item_form_test.dart | 23 +- .../nutritional_plan_form_test.mocks.dart | 14 +- 6 files changed, 179 insertions(+), 138 deletions(-) diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 0af0ee58d..32f9eed78 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -330,14 +330,24 @@ class NutritionPlansProvider with ChangeNotifier { } /// Searches for an ingredient - Future searchIngredient(String name, [String languageCode = 'en']) async { + Future searchIngredient( + String name, { + String languageCode = 'en', + bool searchEnglish = false, + }) async { if (name.length <= 1) { return []; } + final languages = [languageCode]; + if (searchEnglish && languageCode != LANGUAGE_SHORT_ENGLISH) { + languages.add(LANGUAGE_SHORT_ENGLISH); + } + // Send the request final response = await baseProvider.fetch( - baseProvider.makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languageCode}), + baseProvider + .makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languages.join(',')}), ); // Process the response @@ -355,7 +365,7 @@ class NutritionPlansProvider with ChangeNotifier { baseProvider.makeUrl(_ingredientPath, query: {'code': code}), ); - if (data["count"] == 0) { + if (data['count'] == 0) { return null; } else { return Ingredient.fromJson(data['results'][0]); diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 46a43678a..10aee009d 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -17,7 +17,6 @@ */ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; import 'package:wger/exceptions/http_exception.dart'; @@ -148,9 +147,9 @@ class MealItemForm extends StatelessWidget { IngredientTypeahead( _ingredientIdController, _ingredientController, - true, - _barcode, - _test, + showScanner: true, + barcode: _barcode, + test: _test, ), TextFormField( key: const Key('field-weight'), @@ -255,9 +254,6 @@ class IngredientLogForm extends StatelessWidget { IngredientTypeahead( _ingredientIdController, _ingredientController, - true, - '', - false, ), TextFormField( decoration: InputDecoration(labelText: AppLocalizations.of(context).weight), @@ -277,7 +273,8 @@ class IngredientLogForm extends StatelessWidget { }, ), TextFormField( - readOnly: true, // Stop keyboard from appearing + readOnly: true, + // Stop keyboard from appearing decoration: InputDecoration( labelText: AppLocalizations.of(context).date, suffixIcon: const Icon(Icons.calendar_today_outlined), diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 3aed571b0..6cbd4c9f2 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -18,11 +18,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:provider/provider.dart'; +import 'package:wger/helpers/consts.dart'; import 'package:wger/helpers/ui.dart'; import 'package:wger/providers/nutrition.dart'; import 'package:wger/widgets/core/core.dart'; @@ -30,12 +30,18 @@ import 'package:wger/widgets/core/core.dart'; class IngredientTypeahead extends StatefulWidget { final TextEditingController _ingredientController; final TextEditingController _ingredientIdController; - late String? _barcode; - late final bool? _test; - final bool _showScanner; - IngredientTypeahead(this._ingredientIdController, this._ingredientController, this._showScanner, - [this._barcode, this._test]); + String? barcode = ''; + late final bool? test; + final bool showScanner; + + IngredientTypeahead( + this._ingredientIdController, + this._ingredientController, { + this.showScanner = true, + this.test = false, + this.barcode = '', + }); @override _IngredientTypeaheadState createState() => _IngredientTypeaheadState(); @@ -45,7 +51,12 @@ Future scanBarcode(BuildContext context) async { String barcode; try { barcode = await FlutterBarcodeScanner.scanBarcode( - '#ff6666', AppLocalizations.of(context).close, true, ScanMode.BARCODE); + '#ff6666', + AppLocalizations.of(context).close, + true, + ScanMode.BARCODE, + ); + if (barcode.compareTo('-1') == 0) { return ''; } @@ -57,116 +68,134 @@ Future scanBarcode(BuildContext context) async { } class _IngredientTypeaheadState extends State { + var _searchEnglish = true; + @override Widget build(BuildContext context) { - return TypeAheadFormField( - textFieldConfiguration: TextFieldConfiguration( - controller: widget._ingredientController, - decoration: InputDecoration( - prefixIcon: const Icon(Icons.search), - labelText: AppLocalizations.of(context).searchIngredient, - suffixIcon: widget._showScanner ? scanButton() : null, + return Column( + children: [ + TypeAheadFormField( + textFieldConfiguration: TextFieldConfiguration( + controller: widget._ingredientController, + decoration: InputDecoration( + prefixIcon: const Icon(Icons.search), + labelText: AppLocalizations.of(context).searchIngredient, + suffixIcon: widget.showScanner ? scanButton() : null, + ), + ), + suggestionsCallback: (pattern) async { + return Provider.of(context, listen: false).searchIngredient( + pattern, + languageCode: Localizations.localeOf(context).languageCode, + searchEnglish: _searchEnglish, + ); + }, + itemBuilder: (context, dynamic suggestion) { + final url = context.read().baseProvider.auth.serverUrl; + return ListTile( + leading: suggestion['data']['image'] != null + ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) + : const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)), + title: Text(suggestion['value']), + ); + }, + transitionBuilder: (context, suggestionsBox, controller) { + return suggestionsBox; + }, + onSuggestionSelected: (dynamic suggestion) { + widget._ingredientIdController.text = suggestion['data']['id'].toString(); + widget._ingredientController.text = suggestion['value']; + }, + validator: (value) { + if (value!.isEmpty) { + return AppLocalizations.of(context).selectIngredient; + } + return null; + }, ), - ), - suggestionsCallback: (pattern) async { - return Provider.of(context, listen: false).searchIngredient( - pattern, - Localizations.localeOf(context).languageCode, - ); - }, - itemBuilder: (context, dynamic suggestion) { - final url = context.read().baseProvider.auth.serverUrl; - return ListTile( - leading: suggestion['data']['image'] != null - ? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image'])) - : const CircleIconAvatar(Icon(Icons.image, color: Colors.grey)), - title: Text(suggestion['value']), - ); - }, - transitionBuilder: (context, suggestionsBox, controller) { - return suggestionsBox; - }, - onSuggestionSelected: (dynamic suggestion) { - widget._ingredientIdController.text = suggestion['data']['id'].toString(); - widget._ingredientController.text = suggestion['value']; - }, - validator: (value) { - if (value!.isEmpty) { - return AppLocalizations.of(context).selectIngredient; - } - return null; - }, + if (Localizations.localeOf(context).languageCode != LANGUAGE_SHORT_ENGLISH) + SwitchListTile( + title: Text(AppLocalizations.of(context).searchNamesInEnglish), + value: _searchEnglish, + onChanged: (_) { + setState(() { + _searchEnglish = !_searchEnglish; + }); + }, + dense: true, + ), + ], ); } Widget scanButton() { return IconButton( - key: const Key('scan-button'), - onPressed: () async { - try { - if (!widget._test!) { - widget._barcode = await scanBarcode(context); - } + key: const Key('scan-button'), + onPressed: () async { + try { + if (!widget.test!) { + widget.barcode = await scanBarcode(context); + } - if (widget._barcode!.isNotEmpty) { - final result = await Provider.of(context, listen: false) - .searchIngredientWithCode(widget._barcode!); + if (widget.barcode!.isNotEmpty) { + final result = await Provider.of(context, listen: false) + .searchIngredientWithCode(widget.barcode!); - if (result != null) { - showDialog( - context: context, - builder: (ctx) => AlertDialog( - key: const Key('found-dialog'), - title: Text(AppLocalizations.of(context).productFound), - content: - Text(AppLocalizations.of(context).productFoundDescription(result.name)), - actions: [ - TextButton( - key: const Key('found-dialog-confirm-button'), - child: Text(MaterialLocalizations.of(context).continueButtonLabel), - onPressed: () { - widget._ingredientController.text = result.name; - widget._ingredientIdController.text = result.id.toString(); - Navigator.of(ctx).pop(); - }, - ), - TextButton( - key: const Key('found-dialog-close-button'), - child: Text(MaterialLocalizations.of(context).closeButtonLabel), - onPressed: () { - Navigator.of(ctx).pop(); - }, - ) - ], - ), - ); - } else { - //nothing is matching barcode - showDialog( - context: context, - builder: (ctx) => AlertDialog( - key: const Key('notFound-dialog'), - title: Text(AppLocalizations.of(context).productNotFound), - content: Text( - AppLocalizations.of(context).productNotFoundDescription(widget._barcode!), + if (result != null) { + showDialog( + context: context, + builder: (ctx) => AlertDialog( + key: const Key('found-dialog'), + title: Text(AppLocalizations.of(context).productFound), + content: Text(AppLocalizations.of(context).productFoundDescription(result.name)), + actions: [ + TextButton( + key: const Key('found-dialog-confirm-button'), + child: Text(MaterialLocalizations.of(context).continueButtonLabel), + onPressed: () { + widget._ingredientController.text = result.name; + widget._ingredientIdController.text = result.id.toString(); + Navigator.of(ctx).pop(); + }, ), - actions: [ - TextButton( - key: const Key('notFound-dialog-close-button'), - child: Text(MaterialLocalizations.of(context).closeButtonLabel), - onPressed: () { - Navigator.of(ctx).pop(); - }, - ) - ], + TextButton( + key: const Key('found-dialog-close-button'), + child: Text(MaterialLocalizations.of(context).closeButtonLabel), + onPressed: () { + Navigator.of(ctx).pop(); + }, + ) + ], + ), + ); + } else { + //nothing is matching barcode + showDialog( + context: context, + builder: (ctx) => AlertDialog( + key: const Key('notFound-dialog'), + title: Text(AppLocalizations.of(context).productNotFound), + content: Text( + AppLocalizations.of(context).productNotFoundDescription(widget.barcode!), ), - ); - } + actions: [ + TextButton( + key: const Key('notFound-dialog-close-button'), + child: Text(MaterialLocalizations.of(context).closeButtonLabel), + onPressed: () { + Navigator.of(ctx).pop(); + }, + ) + ], + ), + ); } - } catch (e) { - showErrorDialog(e, context); } - }, - icon: Image.asset('assets/images/barcode_scanner_icon.png')); + } catch (e) { + showErrorDialog(e, context); + } + }, + icon: Image.asset('assets/images/barcode_scanner_icon.png'), + ); } } diff --git a/test/nutrition/nutritional_meal_form_test.mocks.dart b/test/nutrition/nutritional_meal_form_test.mocks.dart index dfdd9086a..cf57b4bc3 100644 --- a/test/nutrition/nutritional_meal_form_test.mocks.dart +++ b/test/nutrition/nutritional_meal_form_test.mocks.dart @@ -319,16 +319,18 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansP ) as _i8.Future); @override _i8.Future> searchIngredient( - String? name, [ + String? name, { String? languageCode = r'en', - ]) => + bool? searchEnglish = false, + }) => (super.noSuchMethod( Invocation.method( #searchIngredient, - [ - name, - languageCode, - ], + [name], + { + #languageCode: languageCode, + #searchEnglish: searchEnglish, + }, ), returnValue: _i8.Future>.value([]), ) as _i8.Future>); diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index d454abd36..4e2659766 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -24,7 +24,7 @@ import '../other/base_provider_test.mocks.dart'; import 'nutritional_plan_form_test.mocks.dart'; void main() { - Ingredient ingr = Ingredient( + final ingredient = Ingredient( id: 1, code: '123456787', name: 'Water', @@ -40,14 +40,12 @@ void main() { ); late MockWgerBaseProvider mockWgerBaseProvider; - late NutritionPlansProvider mockNutritionWithClient; var mockNutrition = MockNutritionPlansProvider(); final client = MockClient(); setUp(() { mockWgerBaseProvider = MockWgerBaseProvider(); - mockNutritionWithClient = NutritionPlansProvider(mockWgerBaseProvider, []); }); var plan1 = NutritionalPlan.empty(); @@ -57,22 +55,25 @@ void main() { final Uri tUriEmptyCode = Uri.parse('https://localhost/api/v2/ingredient/?code=\"%20\"'); final Uri tUriBadCode = Uri.parse('https://localhost/api/v2/ingredient/?code=222'); - when(client.get(tUriRightCode, headers: anyNamed('headers'))).thenAnswer((_) => - Future.value(http.Response(fixture('nutrition/search_ingredient_right_code.json'), 200))); + when(client.get(tUriRightCode, headers: anyNamed('headers'))).thenAnswer( + (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_right_code.json'), 200)), + ); - when(client.get(tUriEmptyCode, headers: anyNamed('headers'))).thenAnswer((_) => - Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200))); + when(client.get(tUriEmptyCode, headers: anyNamed('headers'))).thenAnswer( + (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)), + ); - when(client.get(tUriBadCode, headers: anyNamed('headers'))).thenAnswer((_) => - Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200))); + when(client.get(tUriBadCode, headers: anyNamed('headers'))).thenAnswer( + (_) => Future.value(http.Response(fixture('nutrition/search_ingredient_wrong_code.json'), 200)), + ); setUp(() { plan1 = getNutritionalPlan(); meal1 = plan1.meals.first; - final MealItem mealItem = MealItem(ingredientId: ingr.id, amount: 2); + final MealItem mealItem = MealItem(ingredientId: ingredient.id, amount: 2); mockNutrition = MockNutritionPlansProvider(); - when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingr)); + when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingredient)); when(mockNutrition.searchIngredientWithCode('')).thenAnswer((_) => Future.value(null)); when(mockNutrition.searchIngredientWithCode('222')).thenAnswer((_) => Future.value(null)); when(mockNutrition.searchIngredient(any)).thenAnswer((_) => diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index fde0989ae..802102d97 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -319,16 +319,18 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i7.NutritionPlansP ) as _i8.Future); @override _i8.Future> searchIngredient( - String? name, [ + String? name, { String? languageCode = r'en', - ]) => + bool? searchEnglish = false, + }) => (super.noSuchMethod( Invocation.method( #searchIngredient, - [ - name, - languageCode, - ], + [name], + { + #languageCode: languageCode, + #searchEnglish: searchEnglish, + }, ), returnValue: _i8.Future>.value([]), ) as _i8.Future>); From 6197e4dd2adb24b0bc095755a263077018604fa8 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 20 Mar 2023 17:17:53 +0100 Subject: [PATCH 11/12] Use paginated api when fetching log entries --- lib/providers/nutrition.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index 32f9eed78..1911c0d55 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -103,8 +103,8 @@ class NutritionPlansProvider with ChangeNotifier { /// Fetches and sets all plans fully, i.e. with all corresponding child objects Future fetchAndSetAllPlansFull() async { - final data = await baseProvider.fetch(baseProvider.makeUrl(_nutritionalPlansPath)); - for (final entry in data['results']) { + final data = await baseProvider.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath)); + for (final entry in data) { await fetchAndSetPlanFull(entry['id']); } } @@ -411,16 +411,15 @@ class NutritionPlansProvider with ChangeNotifier { /// Load nutrition diary entries for plan Future fetchAndSetLogs(NutritionalPlan plan) async { - // TODO(x): update fetch to that it can use the pagination - final data = await baseProvider.fetch( + final data = await baseProvider.fetchPaginated( baseProvider.makeUrl( _nutritionDiaryPath, - query: {'plan': plan.id.toString(), 'limit': '1000'}, + query: {'plan': plan.id.toString(), 'limit': '999'}, ), ); plan.logs = []; - for (final logData in data['results']) { + for (final logData in data) { final log = Log.fromJson(logData); final ingredient = await fetchIngredient(log.ingredientId); log.ingredientObj = ingredient; From 65dd284f8fdbebb59bd4ea90759049feb25c6661 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 8 Apr 2023 23:44:47 +0200 Subject: [PATCH 12/12] Fix test --- test/nutrition/nutrition_provider_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/nutrition/nutrition_provider_test.dart b/test/nutrition/nutrition_provider_test.dart index cc25b3611..fdedd435c 100644 --- a/test/nutrition/nutrition_provider_test.dart +++ b/test/nutrition/nutrition_provider_test.dart @@ -27,9 +27,9 @@ void main() { final Map NutritionalPlanDetailResponse = jsonDecode( fixture('nutrition/nutritional_plan_detail_response.json'), ); - final Map NutritionDiaryResponse = jsonDecode( + final List NutritionDiaryResponse = jsonDecode( fixture('nutrition/nutrition_diary_response.json'), - ); + )['results']; final Map Ingredient59887Response = jsonDecode( fixture('nutrition/ingredient_59887_response.json'), ); @@ -72,7 +72,7 @@ void main() { when(mockWgerBaseProvider.fetch(planUri)).thenAnswer( (realInvocation) => Future.value(NutritionalPlanDetailResponse), ); - when(mockWgerBaseProvider.fetch(diaryUri)).thenAnswer( + when(mockWgerBaseProvider.fetchPaginated(diaryUri)).thenAnswer( (realInvocation) => Future.value(NutritionDiaryResponse), ); });