diff --git a/assets/images/barcode_scanner_icon.png b/assets/images/barcode_scanner_icon.png new file mode 100644 index 000000000..7bd38e5ca Binary files /dev/null and b/assets/images/barcode_scanner_icon.png differ diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index be62be299..69e7b34c5 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -507,5 +507,43 @@ "description": "Snackbar message to show on copying data to a new log entry" }, "appUpdateTitle" : "Update needed", - "appUpdateContent" : "This version of the app is not compatible with the server, please update your application." + "appUpdateContent" : "This version of the app is not compatible with the server, please update your application.", + + "productFound": "Product found", + "@productFound": { + "description": "Header label for dialog when product is found with barcode" + }, + + "productFoundDescription": "The barcode corresponds to this product: \n {productName} \nDo you want to continue ?", + "@productFoundDescription": { + "description": "Dialog info when product is found with barcode", + "type": "text", + "placeholders": { + "productName": {} + } + }, + + "productNotFound": "Product not found", + "@productNotFound": { + "description": "Header label for dialog when product is not found with barcode" + }, + + "productNotFoundDescription": "Product with scanned barcode ({barcode}) was not found.", + "@productNotFoundDescription": { + "description": "Dialog info when product is not found with barcode", + "type": "text", + "placeholders": { + "barcode": {} + } + }, + + "scanBarcode": "Scan barcode", + "@scanBarcode": { + "description": "Label for scan barcode button" + }, + + "close": "Close", + "@close": { + "description": "Translation for close" + } } 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 2b0bf68eb..445750776 100644 --- a/lib/models/exercises/exercise.g.dart +++ b/lib/models/exercises/exercise.g.dart @@ -44,7 +44,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) => { @@ -55,7 +56,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(), 'comments': instance.tips.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/ingredient.dart b/lib/models/nutrition/ingredient.dart index 69d1ce446..a60d6f797 100644 --- a/lib/models/nutrition/ingredient.dart +++ b/lib/models/nutrition/ingredient.dart @@ -25,6 +25,10 @@ class Ingredient { @JsonKey(required: true) final int id; + /// Barcode of the product + @JsonKey(required: true) + final String code; + /// Name of the product @JsonKey(required: true) final String name; @@ -66,6 +70,7 @@ class Ingredient { const Ingredient({ required this.id, + required this.code, required this.name, required this.creationDate, required this.energy, diff --git a/lib/models/nutrition/ingredient.g.dart b/lib/models/nutrition/ingredient.g.dart index 05ef48d77..c4afcabb3 100644 --- a/lib/models/nutrition/ingredient.g.dart +++ b/lib/models/nutrition/ingredient.g.dart @@ -11,6 +11,7 @@ Ingredient _$IngredientFromJson(Map json) { json, requiredKeys: const [ 'id', + 'code', 'name', 'creation_date', 'energy', @@ -25,6 +26,7 @@ Ingredient _$IngredientFromJson(Map json) { ); return Ingredient( id: json['id'] as int, + code: json['code'] as String, name: json['name'] as String, creationDate: DateTime.parse(json['creation_date'] as String), energy: json['energy'] as int, @@ -38,8 +40,10 @@ Ingredient _$IngredientFromJson(Map json) { ); } -Map _$IngredientToJson(Ingredient instance) => { +Map _$IngredientToJson(Ingredient instance) => + { 'id': instance.id, + 'code': instance.code, 'name': instance.name, 'creation_date': toDate(instance.creationDate), 'energy': instance.energy, diff --git a/lib/models/nutrition/ingredient_weight_unit.g.dart b/lib/models/nutrition/ingredient_weight_unit.g.dart index f147a2ee1..141e9b7e5 100644 --- a/lib/models/nutrition/ingredient_weight_unit.g.dart +++ b/lib/models/nutrition/ingredient_weight_unit.g.dart @@ -13,7 +13,8 @@ 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(), 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 5fcc9d621..89834c863 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -326,6 +326,28 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier { return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List; } + /// Searches for an ingredient with code + Future searchIngredientWithCode(String code) async { + + if (code.isEmpty ) { + return null; + } + + // Send the request + final data = await fetch( + makeUrl( + _ingredientPath, + query: {'code': code}, + ), + ); + + if(data["count"]==0){ + return null; + }else{ + return Ingredient.fromJson(data['results'][0]); + } + } + /// Log meal to nutrition diary Future logMealToDiary(Meal meal) async { for (final item in meal.mealItems) { diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 70e0725cb..b082b6a47 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -17,6 +17,7 @@ */ 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'; @@ -116,17 +117,25 @@ class MealItemForm extends StatelessWidget { final Meal _meal; late final MealItem _mealItem; final List _listMealItems; + late String _barcode; + late bool _test; final _form = GlobalKey(); final _ingredientIdController = TextEditingController(); final _ingredientController = TextEditingController(); final _amountController = TextEditingController(); - MealItemForm(this._meal, this._listMealItems, [mealItem]) { + MealItemForm(this._meal, this._listMealItems, [mealItem, code, test]) { _mealItem = mealItem ?? MealItem.empty(); + _test = test ?? false; + _barcode = code ?? ''; _mealItem.mealId = _meal.id!; } + TextEditingController get ingredientIdController => _ingredientIdController; + + MealItem get mealItem => _mealItem; + @override Widget build(BuildContext context) { final String unit = AppLocalizations.of(context).g; @@ -136,8 +145,9 @@ class MealItemForm extends StatelessWidget { key: _form, child: Column( children: [ - IngredientTypeahead(_ingredientIdController, _ingredientController), + IngredientTypeahead(_ingredientIdController, _ingredientController, true, _barcode, _test, ), TextFormField( + key: const Key('field-weight'), decoration: InputDecoration(labelText: AppLocalizations.of(context).weight), controller: _amountController, keyboardType: TextInputType.number, @@ -155,6 +165,7 @@ class MealItemForm extends StatelessWidget { }, ), ElevatedButton( + key: const Key(SUBMIT_BUTTON_KEY_NAME), child: Text(AppLocalizations.of(context).save), onPressed: () async { if (!_form.currentState!.validate()) { @@ -235,7 +246,7 @@ class IngredientLogForm extends StatelessWidget { key: _form, child: Column( children: [ - IngredientTypeahead(_ingredientIdController, _ingredientController), + IngredientTypeahead(_ingredientIdController, _ingredientController, true, '', false,), TextFormField( decoration: InputDecoration(labelText: AppLocalizations.of(context).weight), controller: _amountController, diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 6438ce305..771f5c73a 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -17,22 +17,43 @@ */ 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/ui.dart'; import 'package:wger/providers/nutrition.dart'; class IngredientTypeahead extends StatefulWidget { final TextEditingController _ingredientController; final TextEditingController _ingredientIdController; + late String? _barcode; + late final bool? _test; + final bool _showScanner; - const IngredientTypeahead(this._ingredientIdController, this._ingredientController); + IngredientTypeahead(this._ingredientIdController, this._ingredientController, this._showScanner, [this._barcode, this._test]); @override _IngredientTypeaheadState createState() => _IngredientTypeaheadState(); } +Future scanBarcode(BuildContext context) async { + String barcode; + try { + barcode = await FlutterBarcodeScanner.scanBarcode( + '#ff6666', AppLocalizations.of(context).close, true, ScanMode.BARCODE); + if(barcode.compareTo('-1') == 0){ + return ''; + } + } on PlatformException { + return ''; + } + + return barcode; +} + class _IngredientTypeaheadState extends State { @override Widget build(BuildContext context) { @@ -40,8 +61,9 @@ class _IngredientTypeaheadState extends State { textFieldConfiguration: TextFieldConfiguration( controller: widget._ingredientController, decoration: InputDecoration( + prefixIcon: const Icon(Icons.search), labelText: AppLocalizations.of(context).searchIngredient, - suffixIcon: const Icon(Icons.search), + suffixIcon: widget._showScanner ? scanButton() : null, ), ), suggestionsCallback: (pattern) async { @@ -71,4 +93,74 @@ class _IngredientTypeaheadState extends State { }, ); } + + Widget scanButton(){ + return IconButton( + 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(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!),), + 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')); + } + } diff --git a/pubspec.lock b/pubspec.lock index d179f097f..2d5a87df3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -300,6 +300,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_barcode_scanner: + dependency: "direct main" + description: + name: flutter_barcode_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" flutter_calendar_carousel: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5551bdb77..d44bcc986 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,6 +52,7 @@ dependencies: shared_preferences: ^2.0.7 table_calendar: ^3.0.2 url_launcher: ^6.0.10 + flutter_barcode_scanner: ^2.0.0 dev_dependencies: flutter_test: diff --git a/test/fixtures/ingredient_suggestions.json b/test/fixtures/ingredient_suggestions.json new file mode 100644 index 000000000..b0dafe128 --- /dev/null +++ b/test/fixtures/ingredient_suggestions.json @@ -0,0 +1,15 @@ +{"suggestions":[ + { + "value": "'n Dry 100% Rapeseed Oil 1 Litre", + "data": { + "id": 61810, + "name": "'n Dry 100% Rapeseed Oil 1 Litre" + }}, + { + "value": "100% Apple & Mango", + "data": { + "id": 61972, + "name": "100% Apple & Mango" + } + }] + } diff --git a/test/fixtures/search_ingredient_right_code.json b/test/fixtures/search_ingredient_right_code.json new file mode 100644 index 000000000..0168580f2 --- /dev/null +++ b/test/fixtures/search_ingredient_right_code.json @@ -0,0 +1,25 @@ +{ + "count":1, + "next":null, + "previous":null, + "results":[ + { + "id":9436, + "code":"0013087245950", + "name":" Gâteau double chocolat ", + "creation_date":"2020-12-20", + "update_date":"2020-12-20", + "energy":360, + "protein":"5.000", + "carbohydrates":"45.000", + "carbohydrates_sugar":"27.000", + "fat":"18.000", + "fat_saturated":"4.500", + "fibres":"2.000", + "sodium":"0.356", + "license":5, + "license_author":"Open Food Facts", + "language":12 + } + ] +} \ No newline at end of file diff --git a/test/fixtures/search_ingredient_wrong_code.json b/test/fixtures/search_ingredient_wrong_code.json new file mode 100644 index 000000000..b9c66e112 --- /dev/null +++ b/test/fixtures/search_ingredient_wrong_code.json @@ -0,0 +1,6 @@ +{ + "count":0, + "next":null, + "previous":null, + "results":[] +} \ No newline at end of file diff --git a/test/gallery/gallery_screen_test.mocks.dart b/test/gallery/gallery_screen_test.mocks.dart index 8f5d6f1d4..1490b2f82 100644 --- a/test/gallery/gallery_screen_test.mocks.dart +++ b/test/gallery/gallery_screen_test.mocks.dart @@ -38,31 +38,33 @@ 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()) 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()) 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, []), @@ -84,43 +86,50 @@ class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider { returnValue: Future.value(), returnValueForMissingStub: 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}), + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), returnValue: _FakeUri_2()) as Uri); @override - _i6.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) - as _i6.Future>); + _i6.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method(#fetch, [uri]), + returnValue: Future>.value({})) + as _i6.Future>); @override _i6.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + 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: + 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: Future<_i3.Response>.value(_FakeResponse_3())) + as _i6.Future<_i3.Response>); @override String toString() => super.toString(); @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 89093d716..44427afa2 100644 --- a/test/measurements/measurement_categories_screen_test.mocks.dart +++ b/test/measurements/measurement_categories_screen_test.mocks.dart @@ -20,36 +20,41 @@ import 'package:wger/providers/measurement.dart' as _i4; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -class _FakeWgerBaseProvider_0 extends _i1.Fake implements _i2.WgerBaseProvider {} +class _FakeWgerBaseProvider_0 extends _i1.Fake implements _i2.WgerBaseProvider { +} -class _FakeMeasurementCategory_1 extends _i1.Fake implements _i3.MeasurementCategory {} +class _FakeMeasurementCategory_1 extends _i1.Fake + implements _i3.MeasurementCategory {} /// 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); + (super.noSuchMethod(Invocation.getter(#baseProvider), + returnValue: _FakeWgerBaseProvider_0()) 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); + _i3.MeasurementCategory findCategoryById(int? id) => (super.noSuchMethod( + Invocation.method(#findCategoryById, [id]), + returnValue: _FakeMeasurementCategory_1()) as _i3.MeasurementCategory); @override _i5.Future fetchAndSetCategories() => (super.noSuchMethod(Invocation.method(#fetchAndSetCategories, []), @@ -61,10 +66,10 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide returnValue: Future.value(), returnValueForMissingStub: 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: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); @override _i5.Future addCategory(_i3.MeasurementCategory? category) => (super.noSuchMethod(Invocation.method(#addCategory, [category]), @@ -77,7 +82,8 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide returnValueForMissingStub: Future.value()) as _i5.Future); @override _i5.Future editCategory(int? id, String? newName, String? newUnit) => - (super.noSuchMethod(Invocation.method(#editCategory, [id, newName, newUnit]), + (super.noSuchMethod( + Invocation.method(#editCategory, [id, newName, newUnit]), returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i5.Future); @override @@ -91,25 +97,28 @@ class MockMeasurementProvider extends _i1.Mock implements _i4.MeasurementProvide returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i5.Future editEntry( - int? id, int? categoryId, num? newValue, String? newNotes, DateTime? newDate) => + _i5.Future editEntry(int? id, int? categoryId, num? newValue, + String? newNotes, DateTime? newDate) => (super.noSuchMethod( - Invocation.method(#editEntry, [id, categoryId, newValue, newNotes, newDate]), + Invocation.method( + #editEntry, [id, categoryId, newValue, newNotes, newDate]), returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i5.Future); @override String toString() => super.toString(); @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); } diff --git a/test/measurements/measurement_provider_test.mocks.dart b/test/measurements/measurement_provider_test.mocks.dart index 45ea064bb..1f87fba29 100644 --- a/test/measurements/measurement_provider_test.mocks.dart +++ b/test/measurements/measurement_provider_test.mocks.dart @@ -35,43 +35,49 @@ 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()) 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()) 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}), + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), returnValue: _FakeUri_2()) as Uri); @override - _i5.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) - as _i5.Future>); + _i5.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method(#fetch, [uri]), + returnValue: Future>.value({})) + as _i5.Future>); @override _i5.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + 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: + 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: Future<_i3.Response>.value(_FakeResponse_3())) + as _i5.Future<_i3.Response>); @override String toString() => super.toString(); } diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart new file mode 100644 index 000000000..ce7b250b4 --- /dev/null +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -0,0 +1,323 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_typeahead/flutter_typeahead.dart'; +import 'package:http/http.dart' as http; +import 'package:mockito/mockito.dart'; +import 'package:provider/provider.dart'; +import 'package:wger/helpers/consts.dart'; +import 'package:wger/models/nutrition/ingredient.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/nutrition.dart'; +import 'package:wger/screens/nutritional_plan_screen.dart'; +import 'package:wger/widgets/nutrition/forms.dart'; +import '../../test_data/nutritional_plans.dart'; + +import '../fixtures/fixture_reader.dart'; +import '../other/base_provider_test.mocks.dart'; +import '../utils.dart'; +import 'nutritional_plan_form_test.mocks.dart'; + + + +void main() { + + Ingredient ingr = Ingredient( + id: 1, + code: '123456787', + name: 'Water', + creationDate: DateTime(2021, 5, 1), + energy: 500, + carbohydrates: 10, + carbohydratesSugar: 2, + protein: 5, + fat: 20, + fatSaturated: 7, + fibres: 12, + sodium: 0.5, + ); + + var mockNutrition = MockNutritionPlansProvider(); + final client = MockClient(); + final mockNutritionWithClient = NutritionPlansProvider(testAuthProvider, [], client); + + var plan1 = NutritionalPlan.empty(); + var meal1 = Meal(); + + final Uri tUriRightCode = Uri.parse('https://localhost/api/v2/ingredient/?code=123'); + 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: {'authorization':'Token FooBar', 'user-agent':'wger App'})) + .thenAnswer((_) => Future.value(http.Response(fixture('search_ingredient_right_code.json'),200))); + + when(client.get( + tUriEmptyCode, + headers: {'authorization':'Token FooBar', 'user-agent':'wger App'})) + .thenAnswer((_) => Future.value(http.Response(fixture('search_ingredient_wrong_code.json'),200))); + + when(client.get( + tUriBadCode, + headers: {'authorization':'Token FooBar', 'user-agent':'wger App'})) + .thenAnswer((_) => Future.value(http.Response(fixture('search_ingredient_wrong_code.json'),200))); + + setUp(() { + plan1 = getNutritionalPlan(); + meal1 = plan1.meals.first; + final MealItem mealItem = MealItem(ingredientId: ingr.id, amount: 2); + mockNutrition = MockNutritionPlansProvider(); + + when(mockNutrition.searchIngredientWithCode('123')).thenAnswer((_) => Future.value(ingr)); + when(mockNutrition.searchIngredientWithCode('')).thenAnswer((_) => Future.value(null)); + when(mockNutrition.searchIngredientWithCode('222')).thenAnswer((_) => Future.value(null)); + when(mockNutrition.searchIngredient(any)).thenAnswer((_) => Future.value(json.decode(fixture('ingredient_suggestions')) as List)); + + when(mockNutrition.addMealItem(any, meal1)).thenAnswer((_) => Future.value(mealItem)); + }); + + Widget createMealItemFormScreen(Meal meal, String code, bool test, {locale = 'en'}) { + final key = GlobalKey(); + + + return ChangeNotifierProvider( + create: (context) => mockNutrition, + child: MaterialApp( + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: key, + home: Scaffold( + body: MealItemForm(meal, const [], null, code, test), + ), + routes: { + NutritionalPlanScreen.routeName: (ctx) => NutritionalPlanScreen(), + }, + ), + ); + } + + testWidgets('Test the widgets on the meal item form', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '', true)); + await tester.pumpAndSettle(); + + expect(find.byType(TypeAheadFormField), findsOneWidget); + expect(find.byType(TextFormField), findsOneWidget); + expect(find.byKey(const Key('scan-button')), findsOneWidget); + expect(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), findsOneWidget); + + expect(meal1.mealItems.length, 2); + }); + + + group('Test the AlertDialogs for scanning result', () { + testWidgets('with empty code',(WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byType(AlertDialog), findsNothing); + + }); + + testWidgets('with correct code',(WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + }); + + testWidgets('with incorrect code',(WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '222', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('notFound-dialog')), findsOneWidget); + }); + + }); + + group('Test searchIngredientWithCode() function', () { + test('with correct code', () async { + final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode('123'); + expect(ingredient!.id, 9436); + }); + + test('with incorrect code', () async { + final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode('222'); + expect(ingredient, null); + }); + + test('with empty code', () async { + final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode(''); + expect(ingredient, null); + }); + }); + + group('Test weight formfield', (){ + testWidgets('add empty weight', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.enterText(find.byKey(const Key('field-weight')), ''); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please enter a valid number'), findsOneWidget); + + }); + + testWidgets('add correct weight type', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.enterText(find.byKey(const Key('field-weight')), '2'); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please enter a valid number'), findsNothing); + + }); + testWidgets('add incorrect weight type', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.enterText(find.byKey(const Key('field-weight')), 'test'); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please enter a valid number'), findsOneWidget); + + }); + }); + + group('Test ingredient found dialog', (){ + testWidgets('confirm found ingredient dialog', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + final MealItemForm formScreen = tester.widget(find.byType(MealItemForm)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); + await tester.pumpAndSettle(); + + expect(formScreen.ingredientIdController.text, '1'); + + }); + + testWidgets('close found ingredient dialog', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + await tester.tap(find.byKey(const Key('found-dialog-close-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsNothing); + + + }); + }); + + group('Test the adding a new item to meal', (){ + + testWidgets('save empty ingredient', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please select an ingredient'), findsOneWidget); + + expect(find.text('Please enter a valid number'), findsOneWidget); + + }); + + testWidgets('save ingredient without weight', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please enter a valid number'), findsOneWidget); + + }); + + testWidgets('save ingredient with incorrect weight input type', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(find.text('Please enter a valid number'), findsOneWidget); + + }); + + testWidgets('save complete ingredient with correct weight input type', (WidgetTester tester) async { + await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true)); + + final MealItemForm formScreen = tester.widget(find.byType(MealItemForm)); + + await tester.tap(find.byKey(const Key('scan-button'))); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsOneWidget); + + await tester.tap(find.byKey(const Key('found-dialog-confirm-button'))); + await tester.pumpAndSettle(); + + expect(formScreen.ingredientIdController.text, '1'); + + await tester.enterText(find.byKey(const Key('field-weight')), '2'); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('found-dialog')), findsNothing); + + await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); + await tester.pumpAndSettle(); + + expect(formScreen.mealItem.amount,2); + + verify(mockNutrition.addMealItem(any, meal1)); + + }); + + }); + +} \ No newline at end of file diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index ab76647c2..55ebc112a 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -42,38 +42,41 @@ class _FakeResponse_7 extends _i1.Fake 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 _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()) 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()) 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); + (super.noSuchMethod(Invocation.method(#findById, [id]), + returnValue: _FakeNutritionalPlan_2()) as _i4.NutritionalPlan); @override _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?); @@ -90,17 +93,20 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP @override _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]), - returnValue: Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) + returnValue: + Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) 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())) + returnValue: + Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) 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: + Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2())) as _i9.Future<_i4.NutritionalPlan>); @override _i9.Future editPlan(_i4.NutritionalPlan? plan) => @@ -108,26 +114,31 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValue: Future.value(), returnValueForMissingStub: 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: Future.value(), + returnValueForMissingStub: 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: Future<_i5.Meal>.value(_FakeMeal_3())) + 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: Future<_i5.Meal>.value(_FakeMeal_3())) + 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); @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: Future<_i6.MealItem>.value(_FakeMealItem_4())) + as _i9.Future<_i6.MealItem>); @override _i9.Future deleteMealItem(_i6.MealItem? mealItem) => (super.noSuchMethod(Invocation.method(#deleteMealItem, [mealItem]), @@ -144,17 +155,27 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValue: Future.value(), returnValueForMissingStub: 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: 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?>); @override _i9.Future logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod(Invocation.method(#logMealToDiary, [meal]), returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i9.Future); @override - _i9.Future logIngredentToDiary(_i6.MealItem? mealItem, int? planId, [DateTime? dateTime]) => - (super.noSuchMethod(Invocation.method(#logIngredentToDiary, [mealItem, planId, dateTime]), + _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); @override @@ -168,43 +189,50 @@ class MockNutritionPlansProvider extends _i1.Mock implements _i8.NutritionPlansP returnValue: Future.value(), returnValueForMissingStub: 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}), + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), returnValue: _FakeUri_6()) as Uri); @override - _i9.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) - as _i9.Future>); + _i9.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method(#fetch, [uri]), + returnValue: Future>.value({})) + as _i9.Future>); @override _i9.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + 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: + 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: Future<_i3.Response>.value(_FakeResponse_7())) + as _i9.Future<_i3.Response>); @override String toString() => super.toString(); @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 c052da819..de3e71521 100644 --- a/test/other/base_provider_test.mocks.dart +++ b/test/other/base_provider_test.mocks.dart @@ -23,7 +23,8 @@ import 'package:mockito/mockito.dart' as _i1; class _FakeResponse_0 extends _i1.Fake implements _i2.Response {} -class _FakeStreamedResponse_1 extends _i1.Fake implements _i3.StreamedResponse {} +class _FakeStreamedResponse_1 extends _i1.Fake implements _i3.StreamedResponse { +} /// A class which mocks [Client]. /// @@ -36,51 +37,73 @@ class MockClient extends _i1.Mock implements _i4.Client { @override _i5.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: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.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: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.Future<_i2.Response> post(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => + {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>); + Invocation.method(#post, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.Future<_i2.Response> put(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => + {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>); + Invocation.method(#put, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.Future<_i2.Response> patch(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => + {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>); + Invocation.method(#patch, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.Future<_i2.Response> delete(Uri? url, - {Map? headers, Object? body, _i6.Encoding? encoding}) => + {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>); + Invocation.method(#delete, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future<_i2.Response>.value(_FakeResponse_0())) + as _i5.Future<_i2.Response>); @override _i5.Future read(Uri? url, {Map? headers}) => (super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}), returnValue: Future.value('')) as _i5.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>); + _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>); @override _i5.Future<_i3.StreamedResponse> send(_i8.BaseRequest? request) => (super.noSuchMethod(Invocation.method(#send, [request]), - returnValue: Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_1())) + returnValue: + Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_1())) as _i5.Future<_i3.StreamedResponse>); @override - void close() => - super.noSuchMethod(Invocation.method(#close, []), returnValueForMissingStub: null); + void close() => super.noSuchMethod(Invocation.method(#close, []), + returnValueForMissingStub: null); @override String toString() => super.toString(); } diff --git a/test/workout/workout_form_test.mocks.dart b/test/workout/workout_form_test.mocks.dart index 00b22094a..0e935afc0 100644 --- a/test/workout/workout_form_test.mocks.dart +++ b/test/workout/workout_form_test.mocks.dart @@ -55,73 +55,79 @@ class _FakeResponse_11 extends _i1.Fake implements _i5.Response {} /// 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); + (super.noSuchMethod(Invocation.getter(#defaultWeightUnit), + returnValue: _FakeWeightUnit_0()) 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); @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()) 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()) 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()) - as _i6.WorkoutPlan); + (super.noSuchMethod(Invocation.method(#findById, [id]), + returnValue: _FakeWorkoutPlan_4()) 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); + _i13.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( + Invocation.method(#fetchAndSetAllPlansFull, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i13.Future); @override - _i13.Future fetchAndSetAllPlansSparse() => - (super.noSuchMethod(Invocation.method(#fetchAndSetAllPlansSparse, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( + Invocation.method(#fetchAndSetAllPlansSparse, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i13.Future); @override _i13.Future<_i6.WorkoutPlan> fetchAndSetPlanSparse(int? planId) => (super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]), @@ -129,7 +135,8 @@ class MockWorkoutPlansProvider extends _i1.Mock implements _i12.WorkoutPlansProv as _i13.Future<_i6.WorkoutPlan>); @override _i13.Future<_i6.WorkoutPlan> fetchAndSetWorkoutPlanFull(int? workoutId) => - (super.noSuchMethod(Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]), + (super.noSuchMethod( + Invocation.method(#fetchAndSetWorkoutPlanFull, [workoutId]), returnValue: Future<_i6.WorkoutPlan>.value(_FakeWorkoutPlan_4())) as _i13.Future<_i6.WorkoutPlan>); @override @@ -140,78 +147,89 @@ class MockWorkoutPlansProvider extends _i1.Mock implements _i12.WorkoutPlansProv @override _i13.Future editWorkout(_i6.WorkoutPlan? workout) => (super.noSuchMethod(Invocation.method(#editWorkout, [workout]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + returnValue: Future.value(), + returnValueForMissingStub: 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); + _i13.Future deleteWorkout(int? id) => (super.noSuchMethod( + Invocation.method(#deleteWorkout, [id]), + returnValue: Future.value(), + returnValueForMissingStub: 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: + Future>.value({})) as _i13.Future>); @override - _i13.Future fetchAndSetRepetitionUnits() => - (super.noSuchMethod(Invocation.method(#fetchAndSetRepetitionUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future fetchAndSetRepetitionUnits() => (super.noSuchMethod( + Invocation.method(#fetchAndSetRepetitionUnits, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i13.Future); @override - _i13.Future fetchAndSetWeightUnits() => - (super.noSuchMethod(Invocation.method(#fetchAndSetWeightUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future fetchAndSetWeightUnits() => (super.noSuchMethod( + Invocation.method(#fetchAndSetWeightUnits, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i13.Future); @override - _i13.Future fetchAndSetUnits() => - (super.noSuchMethod(Invocation.method(#fetchAndSetUnits, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i13.Future); + _i13.Future fetchAndSetUnits() => (super.noSuchMethod( + Invocation.method(#fetchAndSetUnits, []), + returnValue: Future.value(), + returnValueForMissingStub: 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: Future<_i7.Day>.value(_FakeDay_5())) + as _i13.Future<_i7.Day>); @override - _i13.Future editDay(_i7.Day? day) => (super.noSuchMethod(Invocation.method(#editDay, [day]), + _i13.Future editDay(_i7.Day? day) => (super.noSuchMethod( + Invocation.method(#editDay, [day]), returnValue: Future.value(), returnValueForMissingStub: 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); + _i13.Future deleteDay(_i7.Day? day) => (super.noSuchMethod( + Invocation.method(#deleteDay, [day]), + returnValue: Future.value(), + returnValueForMissingStub: 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: Future<_i8.Set>.value(_FakeSet_6())) + 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); + _i13.Future editSet(_i8.Set? workoutSet) => (super.noSuchMethod( + Invocation.method(#editSet, [workoutSet]), + returnValue: Future.value(), + returnValueForMissingStub: 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: 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: Future.value(), + returnValueForMissingStub: Future.value()) + as _i13.Future); @override - _i13.Future fetchSmartText(_i8.Set? workoutSet, _i14.Exercise? exercise) => - (super.noSuchMethod(Invocation.method(#fetchSmartText, [workoutSet, exercise]), + _i13.Future fetchSmartText( + _i8.Set? workoutSet, _i14.Exercise? exercise) => + (super.noSuchMethod( + Invocation.method(#fetchSmartText, [workoutSet, exercise]), returnValue: 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); + _i13.Future deleteSet(_i8.Set? workoutSet) => (super.noSuchMethod( + Invocation.method(#deleteSet, [workoutSet]), + returnValue: Future.value(), + returnValueForMissingStub: 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: Future<_i9.Setting>.value(_FakeSetting_7())) + as _i13.Future<_i9.Setting>); @override _i13.Future fetchSessionData() => (super.noSuchMethod(Invocation.method(#fetchSessionData, []), @@ -219,55 +237,65 @@ class MockWorkoutPlansProvider extends _i1.Mock implements _i12.WorkoutPlansProv @override _i13.Future<_i10.WorkoutSession> addSession(_i10.WorkoutSession? session) => (super.noSuchMethod(Invocation.method(#addSession, [session]), - returnValue: Future<_i10.WorkoutSession>.value(_FakeWorkoutSession_8())) + returnValue: + Future<_i10.WorkoutSession>.value(_FakeWorkoutSession_8())) 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: Future<_i11.Log>.value(_FakeLog_9())) + 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); + _i13.Future deleteLog(_i11.Log? log) => (super.noSuchMethod( + Invocation.method(#deleteLog, [log]), + returnValue: Future.value(), + returnValueForMissingStub: 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}), + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), returnValue: _FakeUri_10()) as Uri); @override - _i13.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) - as _i13.Future>); + _i13.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method(#fetch, [uri]), + returnValue: 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: + 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: + 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: Future<_i5.Response>.value(_FakeResponse_11())) + as _i13.Future<_i5.Response>); @override String toString() => super.toString(); @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 87955720d..3c5a26670 100644 --- a/test/workout/workout_set_form_test.mocks.dart +++ b/test/workout/workout_set_form_test.mocks.dart @@ -39,29 +39,30 @@ 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()) 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()) 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()) - as _i4.Exercise); + _i4.Exercise findById(int? exerciseId) => + (super.noSuchMethod(Invocation.method(#findById, [exerciseId]), + returnValue: _FakeExercise_2()) as _i4.Exercise); @override _i6.Future fetchAndSetCategories() => (super.noSuchMethod(Invocation.method(#fetchAndSetCategories, []), @@ -80,54 +81,65 @@ class MockExercisesProvider extends _i1.Mock implements _i5.ExercisesProvider { @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>); + 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>); + _i6.Future> searchExercise(String? name, + [String? languageCode = r'en']) => + (super.noSuchMethod( + Invocation.method(#searchExercise, [name, languageCode]), + returnValue: 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}), + Invocation.method(#makeUrl, [path], + {#id: id, #objectMethod: objectMethod, #query: query}), returnValue: _FakeUri_3()) as Uri); @override - _i6.Future> fetch(Uri? uri) => - (super.noSuchMethod(Invocation.method(#fetch, [uri]), - returnValue: Future>.value({})) - as _i6.Future>); + _i6.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method(#fetch, [uri]), + returnValue: Future>.value({})) + as _i6.Future>); @override _i6.Future> post(Map? data, Uri? uri) => (super.noSuchMethod(Invocation.method(#post, [data, uri]), - returnValue: Future>.value({})) + returnValue: + 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: + 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: Future<_i3.Response>.value(_FakeResponse_4())) + as _i6.Future<_i3.Response>); @override String toString() => super.toString(); @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); } diff --git a/test_data/nutritional_plans.dart b/test_data/nutritional_plans.dart index 5e7836c87..3a39a6645 100644 --- a/test_data/nutritional_plans.dart +++ b/test_data/nutritional_plans.dart @@ -25,6 +25,7 @@ import 'package:wger/models/nutrition/nutritional_plan.dart'; final ingredient1 = Ingredient( id: 1, + code: '123456787', name: 'Water', creationDate: DateTime(2021, 5, 1), energy: 500, @@ -38,6 +39,7 @@ final ingredient1 = Ingredient( ); final ingredient2 = Ingredient( id: 2, + code: '123456788', name: 'Burger soup', creationDate: DateTime(2021, 5, 10), energy: 25, @@ -51,6 +53,7 @@ final ingredient2 = Ingredient( ); final ingredient3 = Ingredient( id: 3, + code: '123456789', name: 'Broccoli cake', creationDate: DateTime(2021, 5, 2), energy: 1200,