From 9f365f80691fbeebae970260ef821963d6276f28 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Fri, 1 May 2026 12:27:49 +0200 Subject: [PATCH] Consolidate ingredient search methods into the ingredient repo --- lib/helpers/shared_preferences.dart | 2 +- lib/models/nutrition/ingredient_filters.dart | 2 +- lib/providers/ingredient_repository.dart | 91 ++++++++++++++- ...nutrition_ingredient_filters_riverpod.dart | 2 +- lib/providers/nutrition_notifier.dart | 27 ----- lib/providers/nutrition_notifier.g.dart | 2 +- lib/providers/nutrition_repository.dart | 84 +------------ lib/widgets/nutrition/widgets.dart | 37 +++--- test/core/validators_test.mocks.dart | 44 +++++++ ...measurement_entries_screen_test.mocks.dart | 110 +++++++++--------- .../ingredient_filters_provider_test.dart | 2 +- test/nutrition/ingredient_typeahead_test.dart | 18 ++- .../nutrition_provider_test.mocks.dart | 110 +++++++++--------- .../nutritional_meal_item_form_test.dart | 12 +- .../nutritional_plan_form_test.mocks.dart | 110 +++++++++--------- .../nutritional_plan_screen_test.mocks.dart | 110 +++++++++--------- .../nutritional_plans_screen_test.mocks.dart | 110 +++++++++--------- test/weight/weight_screen_test.mocks.dart | 110 +++++++++--------- 18 files changed, 499 insertions(+), 484 deletions(-) diff --git a/lib/helpers/shared_preferences.dart b/lib/helpers/shared_preferences.dart index 72f517b59..03a3fdaab 100644 --- a/lib/helpers/shared_preferences.dart +++ b/lib/helpers/shared_preferences.dart @@ -1,7 +1,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/util/legacy_to_async_migration_util.dart'; import 'package:wger/models/nutrition/ingredient.dart'; -import 'package:wger/providers/nutrition_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; /// A helper class that manages preferences using SharedPreferencesAsync /// and handles migration from the legacy SharedPreferences to diff --git a/lib/models/nutrition/ingredient_filters.dart b/lib/models/nutrition/ingredient_filters.dart index 897491052..4a0201aeb 100644 --- a/lib/models/nutrition/ingredient_filters.dart +++ b/lib/models/nutrition/ingredient_filters.dart @@ -1,6 +1,6 @@ //model is used to store ingredient filters values import 'package:wger/models/nutrition/ingredient.dart'; -import 'package:wger/providers/nutrition_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; class IngredientFilters { final bool isVegan; diff --git a/lib/providers/ingredient_repository.dart b/lib/providers/ingredient_repository.dart index d0d7096a4..7d9619a1b 100644 --- a/lib/providers/ingredient_repository.dart +++ b/lib/providers/ingredient_repository.dart @@ -19,21 +19,36 @@ import 'package:drift/drift.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart'; +import 'package:wger/helpers/consts.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/ingredient_weight_unit.dart'; +import 'package:wger/providers/base_provider.dart'; +import 'package:wger/providers/wger_base.dart'; import '../database/powersync/database.dart'; +/// Which language(s) the server-side ingredient search should consider. +enum IngredientSearchLanguage { + current, + currentAndEnglish, + all, +} + final ingredientRepositoryProvider = Provider((ref) { + final base = ref.read(wgerBaseProvider); final db = ref.read(driftPowerSyncDatabase); - return IngredientRepository(db); + return IngredientRepository(base, db); }); +/// Data access for ingredient lookups and searches class IngredientRepository { final _logger = Logger('IngredientRepository'); + final WgerBaseProvider _base; final DriftPowersyncDatabase _db; - IngredientRepository(this._db); + static const ingredientInfoPath = 'ingredientinfo'; + + IngredientRepository(this._base, this._db); /// Watches a single ingredient by [id] with its `image` and `weightUnits` /// fields fully hydrated. Emits `null` if no ingredient with that id exists, @@ -60,7 +75,7 @@ class IngredientRepository { /// /// Hydrates `image` and `weightUnits` on the returned rows so the /// result is shape-compatible with the REST search. - Future> searchByName( + Future> searchIngredientLocal( String term, { bool isVegan = false, bool isVegetarian = false, @@ -87,6 +102,76 @@ class IngredientRepository { return _hydrate(await query.get()); } + /// Searches for ingredients via the wger REST API. + Future> searchIngredientServer( + String name, { + String languageCode = 'en', + IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current, + bool isVegan = false, + bool isVegetarian = false, + NutriScore? nutriscoreMax, + }) async { + if (name.length <= 1) { + return []; + } + final List languages = []; + + switch (searchLanguage) { + case IngredientSearchLanguage.current: + languages.add(languageCode); + case IngredientSearchLanguage.currentAndEnglish: + languages.add(languageCode); + if (languageCode != LANGUAGE_SHORT_ENGLISH) { + languages.add(LANGUAGE_SHORT_ENGLISH); + } + case IngredientSearchLanguage.all: + // Don't add any language code to search in all languages + break; + } + + final query = { + 'name__search': name, + 'limit': API_RESULTS_PAGE_SIZE, + }; + if (languages.isNotEmpty) { + query['language__code'] = languages.join(','); + } + if (isVegan) { + query['is_vegan'] = 'true'; + } + if (isVegetarian) { + query['is_vegetarian'] = 'true'; + } + if (nutriscoreMax != null) { + query['nutriscore__lte'] = nutriscoreMax.name; + } + + _logger.info('Searching ingredients from server'); + final response = await _base.fetch( + _base.makeUrl(ingredientInfoPath, query: query), + timeout: const Duration(seconds: 20), + ); + + return (response['results'] as List) + .map((data) => Ingredient.fromJson(data as Map)) + .toList(); + } + + /// Looks up an ingredient by its product barcode via the REST API. + /// Returns `null` if no matching product is found. + Future searchIngredientByBarcode(String barcode) async { + if (barcode.isEmpty) { + return null; + } + final data = await _base.fetch( + _base.makeUrl(ingredientInfoPath, query: {'code': barcode}), + ); + if (data['count'] == 0) { + return null; + } + return Ingredient.fromJson(data['results'][0]); + } + /// Builds the standard joined query used by every ingredient lookup JoinedSelectStatement _baseJoinedQuery() { return _db.select(_db.ingredientTable).join([ diff --git a/lib/providers/nutrition_ingredient_filters_riverpod.dart b/lib/providers/nutrition_ingredient_filters_riverpod.dart index 02f771518..781e0365c 100644 --- a/lib/providers/nutrition_ingredient_filters_riverpod.dart +++ b/lib/providers/nutrition_ingredient_filters_riverpod.dart @@ -21,7 +21,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:wger/helpers/shared_preferences.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/ingredient_filters.dart'; -import 'package:wger/providers/nutrition_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; part 'nutrition_ingredient_filters_riverpod.g.dart'; diff --git a/lib/providers/nutrition_notifier.dart b/lib/providers/nutrition_notifier.dart index b7d3be70b..519398878 100644 --- a/lib/providers/nutrition_notifier.dart +++ b/lib/providers/nutrition_notifier.dart @@ -22,7 +22,6 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:stream_transform/stream_transform.dart'; import 'package:wger/core/exceptions/http_exception.dart'; import 'package:wger/core/exceptions/no_such_entry_exception.dart'; -import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/log.dart'; import 'package:wger/models/nutrition/meal.dart'; import 'package:wger/models/nutrition/meal_item.dart'; @@ -305,32 +304,6 @@ class NutritionNotifier extends _$NutritionNotifier { } } - // --- Ingredients --- - - Future> searchIngredient( - String name, { - String languageCode = 'en', - IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current, - bool isVegan = false, - bool isVegetarian = false, - NutriScore? nutriscoreMax, - }) { - final repo = ref.read(nutritionRepositoryProvider); - return repo.searchIngredient( - name, - languageCode: languageCode, - searchLanguage: searchLanguage, - isVegan: isVegan, - isVegetarian: isVegetarian, - nutriscoreMax: nutriscoreMax, - ); - } - - Future searchIngredientWithBarcode(String barcode) { - final repo = ref.read(nutritionRepositoryProvider); - return repo.searchIngredientWithBarcode(barcode); - } - // --- Logs (nutrition diary) --- Future logMealToDiary(Meal meal, DateTime mealDateTime) async { diff --git a/lib/providers/nutrition_notifier.g.dart b/lib/providers/nutrition_notifier.g.dart index 98fdec208..e46165d2f 100644 --- a/lib/providers/nutrition_notifier.g.dart +++ b/lib/providers/nutrition_notifier.g.dart @@ -33,7 +33,7 @@ final class NutritionNotifierProvider NutritionNotifier create() => NutritionNotifier(); } -String _$nutritionNotifierHash() => r'afac5137c8f510197cbefb08fe595f8a59d4024b'; +String _$nutritionNotifierHash() => r'ac4b649e3622f55c01486efa4538038f68dba113'; abstract class _$NutritionNotifier extends $StreamNotifier { Stream build(); diff --git a/lib/providers/nutrition_repository.dart b/lib/providers/nutrition_repository.dart index 008c6c1c8..cdf6c1fee 100644 --- a/lib/providers/nutrition_repository.dart +++ b/lib/providers/nutrition_repository.dart @@ -30,12 +30,6 @@ import 'package:wger/models/nutrition/nutritional_plan.dart'; import 'package:wger/providers/base_provider.dart'; import 'package:wger/providers/wger_base.dart'; -enum IngredientSearchLanguage { - current, - currentAndEnglish, - all, -} - final nutritionRepositoryProvider = Provider((ref) { final base = ref.read(wgerBaseProvider); final db = ref.read(driftPowerSyncDatabase); @@ -50,7 +44,7 @@ final nutritionRepositoryProvider = Provider((ref) { /// database — see [watchAllDrift], [editLocalDrift], [deleteLocalDrift], /// [watchAllLogsHydrated], [addLogLocalDrift], [deleteLogLocalDrift]. /// -/// Local ingredient lookups are handled by [IngredientRepository] (PowerSync). +/// Ingredient searches (local + REST) live on [IngredientRepository]. class NutritionRepository { final _logger = Logger('NutritionRepository'); final WgerBaseProvider _base; @@ -60,7 +54,6 @@ class NutritionRepository { static const plansInfoPath = 'nutritionplaninfo'; static const mealPath = 'meal'; static const mealItemPath = 'mealitem'; - static const ingredientInfoPath = 'ingredientinfo'; NutritionRepository(this._base, this._db); @@ -153,81 +146,6 @@ class NutritionRepository { return _base.deleteRequest(mealItemPath, id); } - // --- Ingredients --- - - /// Searches for an ingredient via the REST API. - /// - /// [nutriscoreMax] — if non-null, the worst acceptable Nutri-Score grade, - /// sent to the backend as `nutriscore__lte`. The Django filterset - /// compares lexicographically on the `a`..`e` choices, so passing - /// [NutriScore.b] yields "only A or B". - Future> searchIngredient( - String name, { - String languageCode = 'en', - IngredientSearchLanguage searchLanguage = IngredientSearchLanguage.current, - bool isVegan = false, - bool isVegetarian = false, - NutriScore? nutriscoreMax, - }) async { - if (name.length <= 1) { - return []; - } - final List languages = []; - - switch (searchLanguage) { - case IngredientSearchLanguage.current: - languages.add(languageCode); - case IngredientSearchLanguage.currentAndEnglish: - languages.add(languageCode); - if (languageCode != LANGUAGE_SHORT_ENGLISH) { - languages.add(LANGUAGE_SHORT_ENGLISH); - } - case IngredientSearchLanguage.all: - // Don't add any language code to search in all languages - break; - } - - final query = { - 'name__search': name, - 'limit': API_RESULTS_PAGE_SIZE, - }; - if (languages.isNotEmpty) { - query['language__code'] = languages.join(','); - } - if (isVegan) { - query['is_vegan'] = 'true'; - } - if (isVegetarian) { - query['is_vegetarian'] = 'true'; - } - if (nutriscoreMax != null) { - query['nutriscore__lte'] = nutriscoreMax.name; - } - - _logger.info('Searching ingredients from server'); - final response = await _base.fetch( - _base.makeUrl(ingredientInfoPath, query: query), - timeout: const Duration(seconds: 20), - ); - - return (response['results'] as List) - .map((data) => Ingredient.fromJson(data as Map)) - .toList(); - } - - Future searchIngredientWithBarcode(String barcode) async { - if (barcode.isEmpty) { - return null; - } - final data = await _base.fetch( - _base.makeUrl(ingredientInfoPath, query: {'code': barcode}), - ); - if (data['count'] == 0) { - return null; - } - return Ingredient.fromJson(data['results'][0]); - } - // --- Nutrition diary (logs) --- /// Streams all of the user's diary entries with their related [Ingredient] diff --git a/lib/widgets/nutrition/widgets.dart b/lib/widgets/nutrition/widgets.dart index 6c2afc115..77be92efe 100644 --- a/lib/widgets/nutrition/widgets.dart +++ b/lib/widgets/nutrition/widgets.dart @@ -30,8 +30,6 @@ import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/providers/ingredient_repository.dart'; import 'package:wger/providers/network_provider.dart'; import 'package:wger/providers/nutrition_ingredient_filters_riverpod.dart'; -import 'package:wger/providers/nutrition_notifier.dart'; -import 'package:wger/providers/nutrition_repository.dart'; import 'package:wger/widgets/core/core.dart'; import 'package:wger/widgets/core/wger_image.dart'; import 'package:wger/widgets/nutrition/helpers.dart'; @@ -159,26 +157,23 @@ class _IngredientTypeaheadState extends ConsumerState { // Online: REST search across all ingredients in the wger DB. // Offline: SQL substring search against the local snapshot. // Both honour the diet flags and the Nutri-Score filter. + final ingredientRepo = ref.read(ingredientRepositoryProvider); if (ref.read(networkStatusProvider)) { - return ref - .read(nutritionProvider.notifier) - .searchIngredient( - pattern, - languageCode: Localizations.localeOf(context).languageCode, - searchLanguage: filters.searchLanguage, - isVegan: filters.isVegan, - isVegetarian: filters.isVegetarian, - nutriscoreMax: filters.nutriscoreMax, - ); + return ingredientRepo.searchIngredientServer( + pattern, + languageCode: Localizations.localeOf(context).languageCode, + searchLanguage: filters.searchLanguage, + isVegan: filters.isVegan, + isVegetarian: filters.isVegetarian, + nutriscoreMax: filters.nutriscoreMax, + ); } - return ref - .read(ingredientRepositoryProvider) - .searchByName( - pattern, - isVegan: filters.isVegan, - isVegetarian: filters.isVegetarian, - nutriscoreMax: filters.nutriscoreMax, - ); + return ingredientRepo.searchIngredientLocal( + pattern, + isVegan: filters.isVegan, + isVegetarian: filters.isVegetarian, + nutriscoreMax: filters.nutriscoreMax, + ); }, itemBuilder: (context, ingredient) { final i18n = AppLocalizations.of(context); @@ -275,7 +270,7 @@ class _IngredientTypeaheadState extends ConsumerState { showDialog( context: context, builder: (context) => FutureBuilder( - future: ref.read(nutritionProvider.notifier).searchIngredientWithBarcode(barcode), + future: ref.read(ingredientRepositoryProvider).searchIngredientByBarcode(barcode), builder: (BuildContext context, AsyncSnapshot snapshot) { return IngredientScanResultDialog(snapshot, barcode, widget.selectIngredient); }, diff --git a/test/core/validators_test.mocks.dart b/test/core/validators_test.mocks.dart index bf03552bb..3ec19c1f1 100644 --- a/test/core/validators_test.mocks.dart +++ b/test/core/validators_test.mocks.dart @@ -4195,6 +4195,39 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations { ) as String); + @override + String get filterNutriscore => + (super.noSuchMethod( + Invocation.getter(#filterNutriscore), + returnValue: _i3.dummyValue( + this, + Invocation.getter(#filterNutriscore), + ), + ) + as String); + + @override + String get filterNutriscoreOff => + (super.noSuchMethod( + Invocation.getter(#filterNutriscoreOff), + returnValue: _i3.dummyValue( + this, + Invocation.getter(#filterNutriscoreOff), + ), + ) + as String); + + @override + String get filterNutriscoreNoFilter => + (super.noSuchMethod( + Invocation.getter(#filterNutriscoreNoFilter), + returnValue: _i3.dummyValue( + this, + Invocation.getter(#filterNutriscoreNoFilter), + ), + ) + as String); + @override String exerciseNr(String? nr) => (super.noSuchMethod( @@ -4480,4 +4513,15 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations { ), ) as String); + + @override + String filterNutriscoreOrBetter(String? grade) => + (super.noSuchMethod( + Invocation.method(#filterNutriscoreOrBetter, [grade]), + returnValue: _i3.dummyValue( + this, + Invocation.method(#filterNutriscoreOrBetter, [grade]), + ), + ) + as String); } diff --git a/test/measurements/measurement_entries_screen_test.mocks.dart b/test/measurements/measurement_entries_screen_test.mocks.dart index 9a20e5c11..bc4b7f30b 100644 --- a/test/measurements/measurement_entries_screen_test.mocks.dart +++ b/test/measurements/measurement_entries_screen_test.mocks.dart @@ -9,10 +9,10 @@ import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:wger/models/measurements/measurement_category.dart' as _i5; import 'package:wger/models/measurements/measurement_entry.dart' as _i6; -import 'package:wger/models/nutrition/ingredient.dart' as _i9; -import 'package:wger/models/nutrition/log.dart' as _i10; +import 'package:wger/models/nutrition/ingredient.dart' as _i11; +import 'package:wger/models/nutrition/log.dart' as _i9; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i8; -import 'package:wger/providers/ingredient_repository.dart' as _i11; +import 'package:wger/providers/ingredient_repository.dart' as _i10; import 'package:wger/providers/measurement_repository.dart' as _i3; import 'package:wger/providers/nutrition_repository.dart' as _i7; @@ -263,50 +263,15 @@ class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepositor as _i4.Future<_i2.Response>); @override - _i4.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i4.Future>.value( - <_i9.Ingredient>[], - ), - ) - as _i4.Future>); - - @override - _i4.Future<_i9.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i4.Future<_i9.Ingredient?>.value(), - ) - as _i4.Future<_i9.Ingredient?>); - - @override - _i4.Stream> watchAllLogsHydrated() => + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override - _i4.Future addLogLocalDrift(_i10.LogItem? log) => + _i4.Future addLogLocalDrift(_i9.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i4.Future.value(), @@ -327,38 +292,38 @@ class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i11.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i10.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i9.Ingredient?> watchById(int? id) => + _i4.Stream<_i11.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i9.Ingredient?>.empty(), + returnValue: _i4.Stream<_i11.Ingredient?>.empty(), ) - as _i4.Stream<_i9.Ingredient?>); + as _i4.Stream<_i11.Ingredient?>); @override - _i4.Future<_i9.Ingredient?> getById(int? id) => + _i4.Future<_i11.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i9.Ingredient?>.value(), + returnValue: _i4.Future<_i11.Ingredient?>.value(), ) - as _i4.Future<_i9.Ingredient?>); + as _i4.Future<_i11.Ingredient?>); @override - _i4.Future> searchByName( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i9.NutriScore? nutriscoreMax, + _i11.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -367,9 +332,44 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i9.Ingredient>[], + returnValue: _i4.Future>.value( + <_i11.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); + + @override + _i4.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i10.IngredientSearchLanguage? searchLanguage = _i10.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i11.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i4.Future>.value( + <_i11.Ingredient>[], + ), + ) + as _i4.Future>); + + @override + _i4.Future<_i11.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i4.Future<_i11.Ingredient?>.value(), + ) + as _i4.Future<_i11.Ingredient?>); } diff --git a/test/nutrition/ingredient_filters_provider_test.dart b/test/nutrition/ingredient_filters_provider_test.dart index 91fcfd777..6ab8c4740 100644 --- a/test/nutrition/ingredient_filters_provider_test.dart +++ b/test/nutrition/ingredient_filters_provider_test.dart @@ -21,8 +21,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; import 'package:wger/helpers/shared_preferences.dart'; +import 'package:wger/providers/ingredient_repository.dart'; import 'package:wger/providers/nutrition_ingredient_filters_riverpod.dart'; -import 'package:wger/providers/nutrition_repository.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); diff --git a/test/nutrition/ingredient_typeahead_test.dart b/test/nutrition/ingredient_typeahead_test.dart index 229d00aad..dfd9ba036 100644 --- a/test/nutrition/ingredient_typeahead_test.dart +++ b/test/nutrition/ingredient_typeahead_test.dart @@ -28,26 +28,23 @@ import 'package:wger/helpers/shared_preferences.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/providers/ingredient_repository.dart'; -import 'package:wger/providers/nutrition_repository.dart'; import 'package:wger/widgets/nutrition/widgets.dart'; import '../../test_data/nutritional_plans.dart'; import 'nutritional_plan_form_test.mocks.dart'; void main() { - late MockNutritionRepository mockRepo; late MockIngredientRepository mockIngredientRepo; setUp(() async { SharedPreferences.setMockInitialValues({}); SharedPreferencesAsyncPlatform.instance = InMemorySharedPreferencesAsync.empty(); await PreferenceHelper.instance.migrationSupportFunctionForSharedPreferences(); - mockRepo = MockNutritionRepository(); mockIngredientRepo = MockIngredientRepository(); when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null); when( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( any, languageCode: anyNamed('languageCode'), searchLanguage: anyNamed('searchLanguage'), @@ -81,7 +78,6 @@ void main() { Widget createWidgetUnderTest() { return ProviderScope( overrides: [ - nutritionRepositoryProvider.overrideWithValue(mockRepo), ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo), ], child: MaterialApp( @@ -132,7 +128,7 @@ void main() { testWidgets('Shows only Vegan chip when ingredient is vegan', (WidgetTester tester) async { // ingredient1 (Water) is vegan + vegetarian when( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( any, languageCode: anyNamed('languageCode'), searchLanguage: anyNamed('searchLanguage'), @@ -156,7 +152,7 @@ void main() { ) async { // milk is vegetarian but not vegan when( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( any, languageCode: anyNamed('languageCode'), searchLanguage: anyNamed('searchLanguage'), @@ -178,7 +174,7 @@ void main() { testWidgets('Shows no dietary chips when ingredient has no info', (WidgetTester tester) async { // ingredient2 (Burger soup) has no dietary info when( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( any, languageCode: anyNamed('languageCode'), searchLanguage: anyNamed('searchLanguage'), @@ -222,7 +218,7 @@ void main() { // Assert verify( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( 'Apple', languageCode: 'en', searchLanguage: IngredientSearchLanguage.current, @@ -273,7 +269,7 @@ void main() { // Assert — index 1 maps to NutriScore.a verify( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( 'Apple', languageCode: 'en', searchLanguage: IngredientSearchLanguage.current, @@ -293,7 +289,7 @@ void main() { await tester.pump(const Duration(milliseconds: 600)); verify( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientServer( 'Apple', languageCode: 'en', searchLanguage: IngredientSearchLanguage.current, diff --git a/test/nutrition/nutrition_provider_test.mocks.dart b/test/nutrition/nutrition_provider_test.mocks.dart index 8c25f03df..a0a600424 100644 --- a/test/nutrition/nutrition_provider_test.mocks.dart +++ b/test/nutrition/nutrition_provider_test.mocks.dart @@ -7,10 +7,10 @@ import 'dart:async' as _i4; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i6; -import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:wger/models/nutrition/ingredient.dart' as _i8; +import 'package:wger/models/nutrition/log.dart' as _i6; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; -import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/ingredient_repository.dart' as _i7; import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: type=lint @@ -177,50 +177,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor as _i4.Future<_i2.Response>); @override - _i4.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], - ), - ) - as _i4.Future>); - - @override - _i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), - ) - as _i4.Future<_i6.Ingredient?>); - - @override - _i4.Stream> watchAllLogsHydrated() => + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override - _i4.Future addLogLocalDrift(_i7.LogItem? log) => + _i4.Future addLogLocalDrift(_i6.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i4.Future.value(), @@ -241,38 +206,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i6.Ingredient?> watchById(int? id) => + _i4.Stream<_i8.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i6.Ingredient?>.empty(), + returnValue: _i4.Stream<_i8.Ingredient?>.empty(), ) - as _i4.Stream<_i6.Ingredient?>); + as _i4.Stream<_i8.Ingredient?>); @override - _i4.Future<_i6.Ingredient?> getById(int? id) => + _i4.Future<_i8.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), + returnValue: _i4.Future<_i8.Ingredient?>.value(), ) - as _i4.Future<_i6.Ingredient?>); + as _i4.Future<_i8.Ingredient?>); @override - _i4.Future> searchByName( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, + _i8.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -281,9 +246,44 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); + + @override + _i4.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i8.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], + ), + ) + as _i4.Future>); + + @override + _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i4.Future<_i8.Ingredient?>.value(), + ) + as _i4.Future<_i8.Ingredient?>); } diff --git a/test/nutrition/nutritional_meal_item_form_test.dart b/test/nutrition/nutritional_meal_item_form_test.dart index 642c4aca3..e9d8ea703 100644 --- a/test/nutrition/nutritional_meal_item_form_test.dart +++ b/test/nutrition/nutritional_meal_item_form_test.dart @@ -107,12 +107,16 @@ void main() { mockIngredientRepo = MockIngredientRepository(); when( - mockRepo.searchIngredientWithBarcode('123'), + mockIngredientRepo.searchIngredientByBarcode('123'), ).thenAnswer((_) => Future.value(ingredient)); - when(mockRepo.searchIngredientWithBarcode('')).thenAnswer((_) => Future.value(null)); - when(mockRepo.searchIngredientWithBarcode('222')).thenAnswer((_) => Future.value(null)); when( - mockRepo.searchIngredient( + mockIngredientRepo.searchIngredientByBarcode(''), + ).thenAnswer((_) => Future.value(null)); + when( + mockIngredientRepo.searchIngredientByBarcode('222'), + ).thenAnswer((_) => Future.value(null)); + when( + mockIngredientRepo.searchIngredientServer( any, languageCode: anyNamed('languageCode'), searchLanguage: anyNamed('searchLanguage'), diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index 7decfb1bc..9e3c213f1 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -7,10 +7,10 @@ import 'dart:async' as _i4; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:wger/models/nutrition/ingredient.dart' as _i6; -import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:wger/models/nutrition/ingredient.dart' as _i8; +import 'package:wger/models/nutrition/log.dart' as _i6; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; -import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/ingredient_repository.dart' as _i7; import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: type=lint @@ -177,50 +177,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor as _i4.Future<_i2.Response>); @override - _i4.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], - ), - ) - as _i4.Future>); - - @override - _i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), - ) - as _i4.Future<_i6.Ingredient?>); - - @override - _i4.Stream> watchAllLogsHydrated() => + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override - _i4.Future addLogLocalDrift(_i7.LogItem? log) => + _i4.Future addLogLocalDrift(_i6.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i4.Future.value(), @@ -241,38 +206,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i6.Ingredient?> watchById(int? id) => + _i4.Stream<_i8.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i6.Ingredient?>.empty(), + returnValue: _i4.Stream<_i8.Ingredient?>.empty(), ) - as _i4.Stream<_i6.Ingredient?>); + as _i4.Stream<_i8.Ingredient?>); @override - _i4.Future<_i6.Ingredient?> getById(int? id) => + _i4.Future<_i8.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), + returnValue: _i4.Future<_i8.Ingredient?>.value(), ) - as _i4.Future<_i6.Ingredient?>); + as _i4.Future<_i8.Ingredient?>); @override - _i4.Future> searchByName( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, + _i8.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -281,9 +246,44 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); + + @override + _i4.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i8.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], + ), + ) + as _i4.Future>); + + @override + _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i4.Future<_i8.Ingredient?>.value(), + ) + as _i4.Future<_i8.Ingredient?>); } diff --git a/test/nutrition/nutritional_plan_screen_test.mocks.dart b/test/nutrition/nutritional_plan_screen_test.mocks.dart index 5b66db294..1779bd33e 100644 --- a/test/nutrition/nutritional_plan_screen_test.mocks.dart +++ b/test/nutrition/nutritional_plan_screen_test.mocks.dart @@ -11,11 +11,11 @@ import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i10; import 'package:wger/models/body_weight/weight_entry.dart' as _i13; -import 'package:wger/models/nutrition/ingredient.dart' as _i6; -import 'package:wger/models/nutrition/log.dart' as _i7; +import 'package:wger/models/nutrition/ingredient.dart' as _i8; +import 'package:wger/models/nutrition/log.dart' as _i6; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i5; import 'package:wger/providers/body_weight_repository.dart' as _i12; -import 'package:wger/providers/ingredient_repository.dart' as _i8; +import 'package:wger/providers/ingredient_repository.dart' as _i7; import 'package:wger/providers/nutrition_repository.dart' as _i3; // ignore_for_file: type=lint @@ -187,50 +187,15 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor as _i4.Future<_i2.Response>); @override - _i4.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i3.IngredientSearchLanguage? searchLanguage = _i3.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], - ), - ) - as _i4.Future>); - - @override - _i4.Future<_i6.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), - ) - as _i4.Future<_i6.Ingredient?>); - - @override - _i4.Stream> watchAllLogsHydrated() => + _i4.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i4.Stream>.empty(), + returnValue: _i4.Stream>.empty(), ) - as _i4.Stream>); + as _i4.Stream>); @override - _i4.Future addLogLocalDrift(_i7.LogItem? log) => + _i4.Future addLogLocalDrift(_i6.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i4.Future.value(), @@ -251,38 +216,38 @@ class MockNutritionRepository extends _i1.Mock implements _i3.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i7.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i4.Stream<_i6.Ingredient?> watchById(int? id) => + _i4.Stream<_i8.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i4.Stream<_i6.Ingredient?>.empty(), + returnValue: _i4.Stream<_i8.Ingredient?>.empty(), ) - as _i4.Stream<_i6.Ingredient?>); + as _i4.Stream<_i8.Ingredient?>); @override - _i4.Future<_i6.Ingredient?> getById(int? id) => + _i4.Future<_i8.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i4.Future<_i6.Ingredient?>.value(), + returnValue: _i4.Future<_i8.Ingredient?>.value(), ) - as _i4.Future<_i6.Ingredient?>); + as _i4.Future<_i8.Ingredient?>); @override - _i4.Future> searchByName( + _i4.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i6.NutriScore? nutriscoreMax, + _i8.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -291,11 +256,46 @@ class MockIngredientRepository extends _i1.Mock implements _i8.IngredientReposit #limit: limit, }, ), - returnValue: _i4.Future>.value( - <_i6.Ingredient>[], + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], ), ) - as _i4.Future>); + as _i4.Future>); + + @override + _i4.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i7.IngredientSearchLanguage? searchLanguage = _i7.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i8.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i4.Future>.value( + <_i8.Ingredient>[], + ), + ) + as _i4.Future>); + + @override + _i4.Future<_i8.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i4.Future<_i8.Ingredient?>.value(), + ) + as _i4.Future<_i8.Ingredient?>); } /// A class which mocks [Client]. diff --git a/test/nutrition/nutritional_plans_screen_test.mocks.dart b/test/nutrition/nutritional_plans_screen_test.mocks.dart index 5efa77469..fa1813c2d 100644 --- a/test/nutrition/nutritional_plans_screen_test.mocks.dart +++ b/test/nutrition/nutritional_plans_screen_test.mocks.dart @@ -11,12 +11,12 @@ import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i11; import 'package:wger/models/body_weight/weight_entry.dart' as _i14; -import 'package:wger/models/nutrition/ingredient.dart' as _i7; -import 'package:wger/models/nutrition/log.dart' as _i8; +import 'package:wger/models/nutrition/ingredient.dart' as _i9; +import 'package:wger/models/nutrition/log.dart' as _i7; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6; import 'package:wger/models/user/profile.dart' as _i3; import 'package:wger/providers/body_weight_repository.dart' as _i13; -import 'package:wger/providers/ingredient_repository.dart' as _i9; +import 'package:wger/providers/ingredient_repository.dart' as _i8; import 'package:wger/providers/nutrition_repository.dart' as _i4; import 'package:wger/providers/user_profile_repository.dart' as _i15; @@ -193,50 +193,15 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor as _i5.Future<_i2.Response>); @override - _i5.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i4.IngredientSearchLanguage? searchLanguage = _i4.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i7.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i5.Future>.value( - <_i7.Ingredient>[], - ), - ) - as _i5.Future>); - - @override - _i5.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i5.Future<_i7.Ingredient?>.value(), - ) - as _i5.Future<_i7.Ingredient?>); - - @override - _i5.Stream> watchAllLogsHydrated() => + _i5.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i5.Stream>.empty(), ) - as _i5.Stream>); + as _i5.Stream>); @override - _i5.Future addLogLocalDrift(_i8.LogItem? log) => + _i5.Future addLogLocalDrift(_i7.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i5.Future.value(), @@ -257,38 +222,38 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream<_i7.Ingredient?> watchById(int? id) => + _i5.Stream<_i9.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i5.Stream<_i7.Ingredient?>.empty(), + returnValue: _i5.Stream<_i9.Ingredient?>.empty(), ) - as _i5.Stream<_i7.Ingredient?>); + as _i5.Stream<_i9.Ingredient?>); @override - _i5.Future<_i7.Ingredient?> getById(int? id) => + _i5.Future<_i9.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i5.Future<_i7.Ingredient?>.value(), + returnValue: _i5.Future<_i9.Ingredient?>.value(), ) - as _i5.Future<_i7.Ingredient?>); + as _i5.Future<_i9.Ingredient?>); @override - _i5.Future> searchByName( + _i5.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i7.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -297,11 +262,46 @@ class MockIngredientRepository extends _i1.Mock implements _i9.IngredientReposit #limit: limit, }, ), - returnValue: _i5.Future>.value( - <_i7.Ingredient>[], + returnValue: _i5.Future>.value( + <_i9.Ingredient>[], ), ) - as _i5.Future>); + as _i5.Future>); + + @override + _i5.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i9.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i5.Future>.value( + <_i9.Ingredient>[], + ), + ) + as _i5.Future>); + + @override + _i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i5.Future<_i9.Ingredient?>.value(), + ) + as _i5.Future<_i9.Ingredient?>); } /// A class which mocks [Client]. diff --git a/test/weight/weight_screen_test.mocks.dart b/test/weight/weight_screen_test.mocks.dart index 6e18ec257..a8663a2a9 100644 --- a/test/weight/weight_screen_test.mocks.dart +++ b/test/weight/weight_screen_test.mocks.dart @@ -8,12 +8,12 @@ import 'dart:async' as _i5; import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:wger/models/body_weight/weight_entry.dart' as _i11; -import 'package:wger/models/nutrition/ingredient.dart' as _i7; -import 'package:wger/models/nutrition/log.dart' as _i8; +import 'package:wger/models/nutrition/ingredient.dart' as _i9; +import 'package:wger/models/nutrition/log.dart' as _i7; import 'package:wger/models/nutrition/nutritional_plan.dart' as _i6; import 'package:wger/models/user/profile.dart' as _i3; import 'package:wger/providers/body_weight_repository.dart' as _i10; -import 'package:wger/providers/ingredient_repository.dart' as _i9; +import 'package:wger/providers/ingredient_repository.dart' as _i8; import 'package:wger/providers/nutrition_repository.dart' as _i4; import 'package:wger/providers/user_profile_repository.dart' as _i12; @@ -185,50 +185,15 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor as _i5.Future<_i2.Response>); @override - _i5.Future> searchIngredient( - String? name, { - String? languageCode = 'en', - _i4.IngredientSearchLanguage? searchLanguage = _i4.IngredientSearchLanguage.current, - bool? isVegan = false, - bool? isVegetarian = false, - _i7.NutriScore? nutriscoreMax, - }) => - (super.noSuchMethod( - Invocation.method( - #searchIngredient, - [name], - { - #languageCode: languageCode, - #searchLanguage: searchLanguage, - #isVegan: isVegan, - #isVegetarian: isVegetarian, - #nutriscoreMax: nutriscoreMax, - }, - ), - returnValue: _i5.Future>.value( - <_i7.Ingredient>[], - ), - ) - as _i5.Future>); - - @override - _i5.Future<_i7.Ingredient?> searchIngredientWithBarcode(String? barcode) => - (super.noSuchMethod( - Invocation.method(#searchIngredientWithBarcode, [barcode]), - returnValue: _i5.Future<_i7.Ingredient?>.value(), - ) - as _i5.Future<_i7.Ingredient?>); - - @override - _i5.Stream> watchAllLogsHydrated() => + _i5.Stream> watchAllLogsHydrated() => (super.noSuchMethod( Invocation.method(#watchAllLogsHydrated, []), - returnValue: _i5.Stream>.empty(), + returnValue: _i5.Stream>.empty(), ) - as _i5.Stream>); + as _i5.Stream>); @override - _i5.Future addLogLocalDrift(_i8.LogItem? log) => + _i5.Future addLogLocalDrift(_i7.LogItem? log) => (super.noSuchMethod( Invocation.method(#addLogLocalDrift, [log]), returnValue: _i5.Future.value(), @@ -249,38 +214,38 @@ class MockNutritionRepository extends _i1.Mock implements _i4.NutritionRepositor /// A class which mocks [IngredientRepository]. /// /// See the documentation for Mockito's code generation for more information. -class MockIngredientRepository extends _i1.Mock implements _i9.IngredientRepository { +class MockIngredientRepository extends _i1.Mock implements _i8.IngredientRepository { MockIngredientRepository() { _i1.throwOnMissingStub(this); } @override - _i5.Stream<_i7.Ingredient?> watchById(int? id) => + _i5.Stream<_i9.Ingredient?> watchById(int? id) => (super.noSuchMethod( Invocation.method(#watchById, [id]), - returnValue: _i5.Stream<_i7.Ingredient?>.empty(), + returnValue: _i5.Stream<_i9.Ingredient?>.empty(), ) - as _i5.Stream<_i7.Ingredient?>); + as _i5.Stream<_i9.Ingredient?>); @override - _i5.Future<_i7.Ingredient?> getById(int? id) => + _i5.Future<_i9.Ingredient?> getById(int? id) => (super.noSuchMethod( Invocation.method(#getById, [id]), - returnValue: _i5.Future<_i7.Ingredient?>.value(), + returnValue: _i5.Future<_i9.Ingredient?>.value(), ) - as _i5.Future<_i7.Ingredient?>); + as _i5.Future<_i9.Ingredient?>); @override - _i5.Future> searchByName( + _i5.Future> searchIngredientLocal( String? term, { bool? isVegan = false, bool? isVegetarian = false, - _i7.NutriScore? nutriscoreMax, + _i9.NutriScore? nutriscoreMax, int? limit = 100, }) => (super.noSuchMethod( Invocation.method( - #searchByName, + #searchIngredientLocal, [term], { #isVegan: isVegan, @@ -289,11 +254,46 @@ class MockIngredientRepository extends _i1.Mock implements _i9.IngredientReposit #limit: limit, }, ), - returnValue: _i5.Future>.value( - <_i7.Ingredient>[], + returnValue: _i5.Future>.value( + <_i9.Ingredient>[], ), ) - as _i5.Future>); + as _i5.Future>); + + @override + _i5.Future> searchIngredientServer( + String? name, { + String? languageCode = 'en', + _i8.IngredientSearchLanguage? searchLanguage = _i8.IngredientSearchLanguage.current, + bool? isVegan = false, + bool? isVegetarian = false, + _i9.NutriScore? nutriscoreMax, + }) => + (super.noSuchMethod( + Invocation.method( + #searchIngredientServer, + [name], + { + #languageCode: languageCode, + #searchLanguage: searchLanguage, + #isVegan: isVegan, + #isVegetarian: isVegetarian, + #nutriscoreMax: nutriscoreMax, + }, + ), + returnValue: _i5.Future>.value( + <_i9.Ingredient>[], + ), + ) + as _i5.Future>); + + @override + _i5.Future<_i9.Ingredient?> searchIngredientByBarcode(String? barcode) => + (super.noSuchMethod( + Invocation.method(#searchIngredientByBarcode, [barcode]), + returnValue: _i5.Future<_i9.Ingredient?>.value(), + ) + as _i5.Future<_i9.Ingredient?>); } /// A class which mocks [BodyWeightRepository].