mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-06 15:54:31 +01:00
Pass the base provider to the nutritional provider as an argument
This makes it easier to test and is the same behaviour as the measurement provider
This commit is contained in:
1 parent
cb4bce7653
commit
8a3351159a
8 files changed
+191
-242
No files matched your search
+15
-14
@@ -64,38 +64,39 @@ class MyApp extends StatelessWidget {
|
||||
create: (ctx) => AuthProvider(),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
|
||||
create: (context) =>
|
||||
ExercisesProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
create: (context) => ExercisesProvider(context.read<AuthProvider>(), []),
|
||||
update: (context, auth, previous) => previous ?? ExercisesProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider, WorkoutPlansProvider>(
|
||||
create: (context) => WorkoutPlansProvider(
|
||||
Provider.of<AuthProvider>(context, listen: false),
|
||||
Provider.of<ExercisesProvider>(context, listen: false),
|
||||
context.read<AuthProvider>(),
|
||||
context.read<ExercisesProvider>(),
|
||||
[],
|
||||
),
|
||||
update: (context, auth, exercises, previous) =>
|
||||
previous ?? WorkoutPlansProvider(auth, exercises, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
|
||||
create: (context) =>
|
||||
NutritionPlansProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) => previous ?? NutritionPlansProvider(auth, []),
|
||||
create: (context) => NutritionPlansProvider(
|
||||
WgerBaseProvider(context.read<AuthProvider>()),
|
||||
[],
|
||||
),
|
||||
update: (context, auth, previous) =>
|
||||
previous ?? NutritionPlansProvider(WgerBaseProvider(auth), []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, MeasurementProvider>(
|
||||
create: (context) => MeasurementProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false))),
|
||||
update: (context, base, previous) =>
|
||||
previous ?? MeasurementProvider(WgerBaseProvider(base)),
|
||||
WgerBaseProvider(context.read<AuthProvider>()),
|
||||
),
|
||||
update: (context, auth, previous) =>
|
||||
previous ?? MeasurementProvider(WgerBaseProvider(auth)),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, BodyWeightProvider>(
|
||||
create: (context) =>
|
||||
BodyWeightProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
create: (context) => BodyWeightProvider(context.read<AuthProvider>(), []),
|
||||
update: (context, auth, previous) => previous ?? BodyWeightProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, GalleryProvider>(
|
||||
create: (context) =>
|
||||
GalleryProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
create: (context) => GalleryProvider(context.read<AuthProvider>(), []),
|
||||
update: (context, auth, previous) => previous ?? GalleryProvider(auth, []),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -32,7 +32,6 @@ class MeasurementProvider with ChangeNotifier {
|
||||
List<MeasurementCategory> _categories = [];
|
||||
|
||||
MeasurementProvider(this.baseProvider);
|
||||
//: super(auth, client);
|
||||
|
||||
List<MeasurementCategory> get categories => _categories;
|
||||
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wger/exceptions/http_exception.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
@@ -31,10 +29,9 @@ import 'package:wger/models/nutrition/log.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/meal_item.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/auth.dart';
|
||||
import 'package:wger/providers/base_provider.dart';
|
||||
|
||||
class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
class NutritionPlansProvider with ChangeNotifier {
|
||||
static const _nutritionalPlansPath = 'nutritionplan';
|
||||
static const _nutritionalPlansInfoPath = 'nutritionplaninfo';
|
||||
static const _mealPath = 'meal';
|
||||
@@ -44,12 +41,11 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
static const _nutritionDiaryPath = 'nutritiondiary';
|
||||
static const _ingredientImagePath = 'ingredient-image';
|
||||
|
||||
final WgerBaseProvider baseProvider;
|
||||
List<NutritionalPlan> _plans = [];
|
||||
List<Ingredient> _ingredients = [];
|
||||
|
||||
NutritionPlansProvider(AuthProvider auth, List<NutritionalPlan> entries, [http.Client? client])
|
||||
: _plans = entries,
|
||||
super(auth, client);
|
||||
NutritionPlansProvider(this.baseProvider, List<NutritionalPlan> entries) : _plans = entries;
|
||||
|
||||
List<NutritionalPlan> get items {
|
||||
return [..._plans];
|
||||
@@ -86,7 +82,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Fetches and sets all plans sparsely, i.e. only with the data on the plan
|
||||
/// object itself and no child attributes
|
||||
Future<void> fetchAndSetAllPlansSparse() async {
|
||||
final data = await fetch(makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
|
||||
final url = baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'});
|
||||
final data = await baseProvider.fetch(url);
|
||||
for (final planData in data['results']) {
|
||||
final plan = NutritionalPlan.fromJson(planData);
|
||||
_plans.add(plan);
|
||||
@@ -97,7 +94,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Fetches and sets all plans fully, i.e. with all corresponding child objects
|
||||
Future<void> fetchAndSetAllPlansFull() async {
|
||||
final data = await fetch(makeUrl(_nutritionalPlansPath));
|
||||
final data = await baseProvider.fetch(baseProvider.makeUrl(_nutritionalPlansPath));
|
||||
for (final entry in data['results']) {
|
||||
await fetchAndSetPlanFull(entry['id']);
|
||||
}
|
||||
@@ -108,7 +105,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// This method only loads the data on the nutritional plan object itself,
|
||||
/// no meals, etc.
|
||||
Future<NutritionalPlan> fetchAndSetPlanSparse(int planId) async {
|
||||
final planData = await fetch(makeUrl(_nutritionalPlansPath, id: planId));
|
||||
final url = baseProvider.makeUrl(_nutritionalPlansPath, id: planId);
|
||||
final planData = await baseProvider.fetch(url);
|
||||
final plan = NutritionalPlan.fromJson(planData);
|
||||
_plans.add(plan);
|
||||
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
|
||||
@@ -127,7 +125,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Plan
|
||||
final fullPlanData = await fetch(makeUrl(_nutritionalPlansInfoPath, id: planId));
|
||||
final url = baseProvider.makeUrl(_nutritionalPlansInfoPath, id: planId);
|
||||
final fullPlanData = await baseProvider.fetch(url);
|
||||
|
||||
// Meals
|
||||
final List<Meal> meals = [];
|
||||
@@ -161,7 +160,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<NutritionalPlan> addPlan(NutritionalPlan planData) async {
|
||||
final data = await post(planData.toJson(), makeUrl(_nutritionalPlansPath));
|
||||
final data = await baseProvider.post(
|
||||
planData.toJson(),
|
||||
baseProvider.makeUrl(_nutritionalPlansPath),
|
||||
);
|
||||
final plan = NutritionalPlan.fromJson(data);
|
||||
_plans.add(plan);
|
||||
_plans.sort((a, b) => b.creationDate.compareTo(a.creationDate));
|
||||
@@ -170,7 +172,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editPlan(NutritionalPlan plan) async {
|
||||
await patch(plan.toJson(), makeUrl(_nutritionalPlansPath, id: plan.id));
|
||||
await baseProvider.patch(
|
||||
plan.toJson(),
|
||||
baseProvider.makeUrl(_nutritionalPlansPath, id: plan.id),
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -180,7 +185,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
_plans.removeAt(existingPlanIndex);
|
||||
notifyListeners();
|
||||
|
||||
final response = await deleteRequest(_nutritionalPlansPath, id);
|
||||
final response = await baseProvider.deleteRequest(_nutritionalPlansPath, id);
|
||||
|
||||
if (response.statusCode >= 400) {
|
||||
_plans.insert(existingPlanIndex, existingPlan);
|
||||
@@ -193,7 +198,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Adds a meal to a plan
|
||||
Future<Meal> addMeal(Meal meal, int planId) async {
|
||||
final plan = findById(planId);
|
||||
final data = await post(meal.toJson(), makeUrl(_mealPath));
|
||||
final data = await baseProvider.post(
|
||||
meal.toJson(),
|
||||
baseProvider.makeUrl(_mealPath),
|
||||
);
|
||||
|
||||
meal = Meal.fromJson(data);
|
||||
plan.meals.add(meal);
|
||||
@@ -204,7 +212,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Edits an existing meal
|
||||
Future<Meal> editMeal(Meal meal) async {
|
||||
final data = await patch(meal.toJson(), makeUrl(_mealPath, id: meal.id));
|
||||
final data = await baseProvider.patch(
|
||||
meal.toJson(),
|
||||
baseProvider.makeUrl(_mealPath, id: meal.id),
|
||||
);
|
||||
meal = Meal.fromJson(data);
|
||||
|
||||
notifyListeners();
|
||||
@@ -221,7 +232,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealPath, meal.id!);
|
||||
final response = await baseProvider.deleteRequest(_mealPath, meal.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
plan.meals.insert(mealIndex, existingMeal);
|
||||
notifyListeners();
|
||||
@@ -231,7 +242,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Adds a meal item to a meal
|
||||
Future<MealItem> addMealItem(MealItem mealItem, Meal meal) async {
|
||||
final data = await post(mealItem.toJson(), makeUrl(_mealItemPath));
|
||||
final data = await baseProvider.post(mealItem.toJson(), baseProvider.makeUrl(_mealItemPath));
|
||||
|
||||
mealItem = MealItem.fromJson(data);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
@@ -251,7 +262,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response = await deleteRequest(_mealItemPath, mealItem.id!);
|
||||
final response = await baseProvider.deleteRequest(_mealItemPath, mealItem.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
meal.mealItems.insert(mealItemIndex, existingMealItem);
|
||||
notifyListeners();
|
||||
@@ -271,7 +282,9 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Get ingredient from the server and save to cache
|
||||
} on StateError {
|
||||
final data = await fetch(makeUrl(_ingredientPath, id: ingredientId));
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientPath, id: ingredientId),
|
||||
);
|
||||
ingredient = Ingredient.fromJson(data);
|
||||
_ingredients.add(ingredient);
|
||||
|
||||
@@ -315,24 +328,12 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final response = await client.get(
|
||||
makeUrl(
|
||||
_ingredientSearchPath,
|
||||
query: {'term': name, 'language': languageCode},
|
||||
),
|
||||
headers: <String, String>{
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
},
|
||||
final response = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languageCode}),
|
||||
);
|
||||
|
||||
// Something wrong with our request
|
||||
if (response.statusCode >= 400) {
|
||||
throw WgerHttpException(response.body);
|
||||
}
|
||||
|
||||
// Process the response
|
||||
return json.decode(utf8.decode(response.bodyBytes))['suggestions'] as List<dynamic>;
|
||||
return response['suggestions'];
|
||||
}
|
||||
|
||||
/// Searches for an ingredient with code
|
||||
@@ -342,11 +343,8 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Send the request
|
||||
final data = await fetch(
|
||||
makeUrl(
|
||||
_ingredientPath,
|
||||
query: {'code': code},
|
||||
),
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientPath, query: {'code': code}),
|
||||
);
|
||||
|
||||
if (data["count"] == 0) {
|
||||
@@ -362,7 +360,10 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
final plan = findById(meal.planId);
|
||||
final Log log = Log.fromMealItem(item, plan.id!, meal.id);
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
final data = await baseProvider.post(
|
||||
log.toJson(),
|
||||
baseProvider.makeUrl(_nutritionDiaryPath),
|
||||
);
|
||||
log.id = data['id'];
|
||||
plan.logs.add(log);
|
||||
}
|
||||
@@ -375,7 +376,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
final Log log = Log.fromMealItem(mealItem, plan.id!, null, dateTime);
|
||||
|
||||
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
|
||||
final data = await baseProvider.post(log.toJson(), baseProvider.makeUrl(_nutritionDiaryPath));
|
||||
log.id = data['id'];
|
||||
plan.logs.add(log);
|
||||
notifyListeners();
|
||||
@@ -383,7 +384,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
/// Deletes a log entry
|
||||
Future<void> deleteLog(int logId, int planId) async {
|
||||
await deleteRequest(_nutritionDiaryPath, logId);
|
||||
await baseProvider.deleteRequest(_nutritionDiaryPath, logId);
|
||||
|
||||
final plan = findById(planId);
|
||||
plan.logs.removeWhere((element) => element.id == logId);
|
||||
@@ -393,8 +394,11 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
/// Load nutrition diary entries for plan
|
||||
Future<void> fetchAndSetLogs(NutritionalPlan plan) async {
|
||||
// TODO(x): update fetch to that it can use the pagination
|
||||
final data = await fetch(
|
||||
makeUrl(_nutritionDiaryPath, query: {'plan': plan.id.toString(), 'limit': '1000'}),
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(
|
||||
_nutritionDiaryPath,
|
||||
query: {'plan': plan.id.toString(), 'limit': '1000'},
|
||||
),
|
||||
);
|
||||
|
||||
plan.logs = [];
|
||||
|
||||
@@ -74,7 +74,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, dynamic suggestion) {
|
||||
final url = context.read<NutritionPlansProvider>().auth.serverUrl;
|
||||
final url = context.read<NutritionPlansProvider>().baseProvider.auth.serverUrl;
|
||||
return ListTile(
|
||||
leading: suggestion['data']['image'] != null
|
||||
? CircleAvatar(backgroundImage: NetworkImage(url! + suggestion['data']['image']))
|
||||
|
||||
@@ -15,11 +15,11 @@ import 'package:wger/models/nutrition/nutritional_plan.dart';
|
||||
import 'package:wger/providers/nutrition.dart';
|
||||
import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
import '../../test_data/nutritional_plans.dart';
|
||||
|
||||
import '../../test_data/nutritional_plans.dart';
|
||||
import '../fixtures/fixture_reader.dart';
|
||||
import '../measurements/measurement_provider_test.mocks.dart';
|
||||
import '../other/base_provider_test.mocks.dart';
|
||||
import '../utils.dart';
|
||||
import 'nutritional_plan_form_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
@@ -38,9 +38,16 @@ void main() {
|
||||
sodium: 0.5,
|
||||
);
|
||||
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
late NutritionPlansProvider mockNutritionWithClient;
|
||||
|
||||
var mockNutrition = MockNutritionPlansProvider();
|
||||
final client = MockClient();
|
||||
final mockNutritionWithClient = NutritionPlansProvider(testAuthProvider, [], client);
|
||||
|
||||
setUp(() {
|
||||
mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
mockNutritionWithClient = NutritionPlansProvider(mockWgerBaseProvider, []);
|
||||
});
|
||||
|
||||
var plan1 = NutritionalPlan.empty();
|
||||
var meal1 = Meal();
|
||||
@@ -140,6 +147,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
group('Test searchIngredientWithCode() function', () {
|
||||
test('with correct code', () async {
|
||||
final Ingredient? ingredient = await mockNutritionWithClient.searchIngredientWithCode('123');
|
||||
@@ -157,6 +165,8 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
group('Test weight formfield', () {
|
||||
testWidgets('add empty weight', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true));
|
||||
|
||||
@@ -3,17 +3,16 @@
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i9;
|
||||
import 'dart:ui' as _i10;
|
||||
import 'dart:async' as _i8;
|
||||
import 'dart:ui' as _i9;
|
||||
|
||||
import 'package:http/http.dart' as _i3;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/models/nutrition/ingredient.dart' as _i7;
|
||||
import 'package:wger/models/nutrition/meal.dart' as _i5;
|
||||
import 'package:wger/models/nutrition/meal_item.dart' as _i6;
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i4;
|
||||
import 'package:wger/providers/auth.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
import 'package:wger/models/nutrition/ingredient.dart' as _i6;
|
||||
import 'package:wger/models/nutrition/meal.dart' as _i4;
|
||||
import 'package:wger/models/nutrition/meal_item.dart' as _i5;
|
||||
import 'package:wger/models/nutrition/nutritional_plan.dart' as _i3;
|
||||
import 'package:wger/providers/base_provider.dart' as _i2;
|
||||
import 'package:wger/providers/nutrition.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -26,44 +25,30 @@ import 'package:wger/providers/nutrition.dart' as _i8;
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider {
|
||||
_FakeAuthProvider_0(Object parent, Invocation parentInvocation)
|
||||
class _FakeWgerBaseProvider_0 extends _i1.SmartFake
|
||||
implements _i2.WgerBaseProvider {
|
||||
_FakeWgerBaseProvider_0(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeClient_1 extends _i1.SmartFake implements _i3.Client {
|
||||
_FakeClient_1(Object parent, Invocation parentInvocation)
|
||||
class _FakeNutritionalPlan_1 extends _i1.SmartFake
|
||||
implements _i3.NutritionalPlan {
|
||||
_FakeNutritionalPlan_1(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeNutritionalPlan_2 extends _i1.SmartFake
|
||||
implements _i4.NutritionalPlan {
|
||||
_FakeNutritionalPlan_2(Object parent, Invocation parentInvocation)
|
||||
class _FakeMeal_2 extends _i1.SmartFake implements _i4.Meal {
|
||||
_FakeMeal_2(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeMeal_3 extends _i1.SmartFake implements _i5.Meal {
|
||||
_FakeMeal_3(Object parent, Invocation parentInvocation)
|
||||
class _FakeMealItem_3 extends _i1.SmartFake implements _i5.MealItem {
|
||||
_FakeMealItem_3(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeMealItem_4 extends _i1.SmartFake implements _i6.MealItem {
|
||||
_FakeMealItem_4(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeIngredient_5 extends _i1.SmartFake implements _i7.Ingredient {
|
||||
_FakeIngredient_5(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeUri_6 extends _i1.SmartFake implements Uri {
|
||||
_FakeUri_6(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
_FakeResponse_7(Object parent, Invocation parentInvocation)
|
||||
class _FakeIngredient_4 extends _i1.SmartFake implements _i6.Ingredient {
|
||||
_FakeIngredient_4(Object parent, Invocation parentInvocation)
|
||||
: super(parent, parentInvocation);
|
||||
}
|
||||
|
||||
@@ -71,31 +56,21 @@ class _FakeResponse_7 extends _i1.SmartFake implements _i3.Response {
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionPlansProvider extends _i1.Mock
|
||||
implements _i8.NutritionPlansProvider {
|
||||
implements _i7.NutritionPlansProvider {
|
||||
MockNutritionPlansProvider() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
List<_i4.NutritionalPlan> get items =>
|
||||
_i2.WgerBaseProvider get baseProvider => (super.noSuchMethod(
|
||||
Invocation.getter(#baseProvider),
|
||||
returnValue:
|
||||
_FakeWgerBaseProvider_0(this, Invocation.getter(#baseProvider)))
|
||||
as _i2.WgerBaseProvider);
|
||||
@override
|
||||
List<_i3.NutritionalPlan> get items =>
|
||||
(super.noSuchMethod(Invocation.getter(#items),
|
||||
returnValue: <_i4.NutritionalPlan>[]) as List<_i4.NutritionalPlan>);
|
||||
@override
|
||||
_i2.AuthProvider get auth => (super.noSuchMethod(Invocation.getter(#auth),
|
||||
returnValue: _FakeAuthProvider_0(this, Invocation.getter(#auth)))
|
||||
as _i2.AuthProvider);
|
||||
@override
|
||||
set auth(_i2.AuthProvider? _auth) =>
|
||||
super.noSuchMethod(Invocation.setter(#auth, _auth),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
_i3.Client get client => (super.noSuchMethod(Invocation.getter(#client),
|
||||
returnValue: _FakeClient_1(this, Invocation.getter(#client)))
|
||||
as _i3.Client);
|
||||
@override
|
||||
set client(_i3.Client? _client) =>
|
||||
super.noSuchMethod(Invocation.setter(#client, _client),
|
||||
returnValueForMissingStub: null);
|
||||
returnValue: <_i3.NutritionalPlan>[]) as List<_i3.NutritionalPlan>);
|
||||
@override
|
||||
bool get hasListeners =>
|
||||
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
|
||||
@@ -104,178 +79,138 @@ class MockNutritionPlansProvider extends _i1.Mock
|
||||
void clear() => super.noSuchMethod(Invocation.method(#clear, []),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
_i4.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
_i3.NutritionalPlan findById(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(#findById, [id]),
|
||||
returnValue:
|
||||
_FakeNutritionalPlan_2(this, Invocation.method(#findById, [id])))
|
||||
as _i4.NutritionalPlan);
|
||||
_FakeNutritionalPlan_1(this, Invocation.method(#findById, [id])))
|
||||
as _i3.NutritionalPlan);
|
||||
@override
|
||||
_i5.Meal? findMealById(int? id) =>
|
||||
(super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i5.Meal?);
|
||||
_i4.Meal? findMealById(int? id) =>
|
||||
(super.noSuchMethod(Invocation.method(#findMealById, [id])) as _i4.Meal?);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansSparse() => (super.noSuchMethod(
|
||||
Invocation.method(#fetchAndSetAllPlansSparse, []),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchAndSetAllPlansFull() => (super.noSuchMethod(
|
||||
Invocation.method(#fetchAndSetAllPlansFull, []),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanSparse(int? planId) =>
|
||||
(super.noSuchMethod(Invocation.method(#fetchAndSetPlanSparse, [planId]),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(this,
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_1(this,
|
||||
Invocation.method(#fetchAndSetPlanSparse, [planId]))))
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super
|
||||
_i8.Future<_i3.NutritionalPlan> fetchAndSetPlanFull(int? planId) => (super
|
||||
.noSuchMethod(Invocation.method(#fetchAndSetPlanFull, [planId]),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_1(
|
||||
this, Invocation.method(#fetchAndSetPlanFull, [planId]))))
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) =>
|
||||
_i8.Future<_i3.NutritionalPlan> addPlan(_i3.NutritionalPlan? planData) =>
|
||||
(super.noSuchMethod(Invocation.method(#addPlan, [planData]),
|
||||
returnValue: _i9.Future<_i4.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_2(
|
||||
returnValue: _i8.Future<_i3.NutritionalPlan>.value(
|
||||
_FakeNutritionalPlan_1(
|
||||
this, Invocation.method(#addPlan, [planData]))))
|
||||
as _i9.Future<_i4.NutritionalPlan>);
|
||||
as _i8.Future<_i3.NutritionalPlan>);
|
||||
@override
|
||||
_i9.Future<void> editPlan(_i4.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
_i8.Future<void> editPlan(_i3.NutritionalPlan? plan) => (super.noSuchMethod(
|
||||
Invocation.method(#editPlan, [plan]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
_i8.Future<void> deletePlan(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(#deletePlan, [id]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> addMeal(_i5.Meal? meal, int? planId) =>
|
||||
_i8.Future<_i4.Meal> addMeal(_i4.Meal? meal, int? planId) =>
|
||||
(super.noSuchMethod(Invocation.method(#addMeal, [meal, planId]),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(_FakeMeal_3(
|
||||
returnValue: _i8.Future<_i4.Meal>.value(_FakeMeal_2(
|
||||
this, Invocation.method(#addMeal, [meal, planId]))))
|
||||
as _i9.Future<_i5.Meal>);
|
||||
as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<_i5.Meal> editMeal(_i5.Meal? meal) =>
|
||||
_i8.Future<_i4.Meal> editMeal(_i4.Meal? meal) =>
|
||||
(super.noSuchMethod(Invocation.method(#editMeal, [meal]),
|
||||
returnValue: _i9.Future<_i5.Meal>.value(
|
||||
_FakeMeal_3(this, Invocation.method(#editMeal, [meal]))))
|
||||
as _i9.Future<_i5.Meal>);
|
||||
returnValue: _i8.Future<_i4.Meal>.value(
|
||||
_FakeMeal_2(this, Invocation.method(#editMeal, [meal]))))
|
||||
as _i8.Future<_i4.Meal>);
|
||||
@override
|
||||
_i9.Future<void> deleteMeal(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteMeal(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(#deleteMeal, [meal]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i6.MealItem> addMealItem(
|
||||
_i6.MealItem? mealItem, _i5.Meal? meal) =>
|
||||
_i8.Future<_i5.MealItem> addMealItem(
|
||||
_i5.MealItem? mealItem, _i4.Meal? meal) =>
|
||||
(super.noSuchMethod(Invocation.method(#addMealItem, [mealItem, meal]),
|
||||
returnValue: _i9.Future<_i6.MealItem>.value(_FakeMealItem_4(
|
||||
returnValue: _i8.Future<_i5.MealItem>.value(_FakeMealItem_3(
|
||||
this, Invocation.method(#addMealItem, [mealItem, meal]))))
|
||||
as _i9.Future<_i6.MealItem>);
|
||||
as _i8.Future<_i5.MealItem>);
|
||||
@override
|
||||
_i9.Future<void> deleteMealItem(_i6.MealItem? mealItem) =>
|
||||
_i8.Future<void> deleteMealItem(_i5.MealItem? mealItem) =>
|
||||
(super.noSuchMethod(Invocation.method(#deleteMealItem, [mealItem]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value())
|
||||
as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value())
|
||||
as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient> fetchIngredient(int? ingredientId) =>
|
||||
_i8.Future<_i6.Ingredient> fetchIngredient(int? ingredientId) =>
|
||||
(super.noSuchMethod(Invocation.method(#fetchIngredient, [ingredientId]),
|
||||
returnValue: _i9.Future<_i7.Ingredient>.value(_FakeIngredient_5(
|
||||
returnValue: _i8.Future<_i6.Ingredient>.value(_FakeIngredient_4(
|
||||
this, Invocation.method(#fetchIngredient, [ingredientId]))))
|
||||
as _i9.Future<_i7.Ingredient>);
|
||||
as _i8.Future<_i6.Ingredient>);
|
||||
@override
|
||||
_i9.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
_i8.Future<void> fetchIngredientsFromCache() => (super.noSuchMethod(
|
||||
Invocation.method(#fetchIngredientsFromCache, []),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<List<dynamic>> searchIngredient(String? name,
|
||||
_i8.Future<List<dynamic>> searchIngredient(String? name,
|
||||
[String? languageCode = r'en']) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#searchIngredient, [name, languageCode]),
|
||||
returnValue: _i9.Future<List<dynamic>>.value(<dynamic>[]))
|
||||
as _i9.Future<List<dynamic>>);
|
||||
returnValue: _i8.Future<List<dynamic>>.value(<dynamic>[]))
|
||||
as _i8.Future<List<dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i7.Ingredient?> searchIngredientWithCode(String? code) =>
|
||||
_i8.Future<_i6.Ingredient?> searchIngredientWithCode(String? code) =>
|
||||
(super.noSuchMethod(Invocation.method(#searchIngredientWithCode, [code]),
|
||||
returnValue: _i9.Future<_i7.Ingredient?>.value())
|
||||
as _i9.Future<_i7.Ingredient?>);
|
||||
returnValue: _i8.Future<_i6.Ingredient?>.value())
|
||||
as _i8.Future<_i6.Ingredient?>);
|
||||
@override
|
||||
_i9.Future<void> logMealToDiary(_i5.Meal? meal) => (super.noSuchMethod(
|
||||
_i8.Future<void> logMealToDiary(_i4.Meal? meal) => (super.noSuchMethod(
|
||||
Invocation.method(#logMealToDiary, [meal]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> logIngredentToDiary(_i6.MealItem? mealItem, int? planId,
|
||||
_i8.Future<void> logIngredentToDiary(_i5.MealItem? mealItem, int? planId,
|
||||
[DateTime? dateTime]) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#logIngredentToDiary, [mealItem, planId, dateTime]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub:
|
||||
_i9.Future<void>.value()) as _i9.Future<void>);
|
||||
_i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> deleteLog(int? logId, int? planId) => (super.noSuchMethod(
|
||||
_i8.Future<void> deleteLog(int? logId, int? planId) => (super.noSuchMethod(
|
||||
Invocation.method(#deleteLog, [logId, planId]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value()) as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value()) as _i8.Future<void>);
|
||||
@override
|
||||
_i9.Future<void> fetchAndSetLogs(_i4.NutritionalPlan? plan) =>
|
||||
_i8.Future<void> fetchAndSetLogs(_i3.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(Invocation.method(#fetchAndSetLogs, [plan]),
|
||||
returnValue: _i9.Future<void>.value(),
|
||||
returnValueForMissingStub: _i9.Future<void>.value())
|
||||
as _i9.Future<void>);
|
||||
returnValue: _i8.Future<void>.value(),
|
||||
returnValueForMissingStub: _i8.Future<void>.value())
|
||||
as _i8.Future<void>);
|
||||
@override
|
||||
Uri makeUrl(String? path,
|
||||
{int? id, String? objectMethod, Map<String, dynamic>? query}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#makeUrl, [path],
|
||||
{#id: id, #objectMethod: objectMethod, #query: query}),
|
||||
returnValue: _FakeUri_6(
|
||||
this,
|
||||
Invocation.method(#makeUrl, [
|
||||
path
|
||||
], {
|
||||
#id: id,
|
||||
#objectMethod: objectMethod,
|
||||
#query: query
|
||||
}))) as Uri);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> fetch(Uri? uri) =>
|
||||
(super.noSuchMethod(Invocation.method(#fetch, [uri]),
|
||||
returnValue:
|
||||
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}))
|
||||
as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> post(Map<String, dynamic>? data, Uri? uri) =>
|
||||
(super.noSuchMethod(Invocation.method(#post, [data, uri]),
|
||||
returnValue:
|
||||
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}))
|
||||
as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<Map<String, dynamic>> patch(
|
||||
Map<String, dynamic>? data, Uri? uri) =>
|
||||
(super.noSuchMethod(Invocation.method(#patch, [data, uri]),
|
||||
returnValue:
|
||||
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}))
|
||||
as _i9.Future<Map<String, dynamic>>);
|
||||
@override
|
||||
_i9.Future<_i3.Response> deleteRequest(String? url, int? id) =>
|
||||
(super.noSuchMethod(Invocation.method(#deleteRequest, [url, id]),
|
||||
returnValue: _i9.Future<_i3.Response>.value(_FakeResponse_7(
|
||||
this, Invocation.method(#deleteRequest, [url, id]))))
|
||||
as _i9.Future<_i3.Response>);
|
||||
@override
|
||||
void addListener(_i10.VoidCallback? listener) =>
|
||||
void addListener(_i9.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#addListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
void removeListener(_i10.VoidCallback? listener) =>
|
||||
void removeListener(_i9.VoidCallback? listener) =>
|
||||
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
|
||||
returnValueForMissingStub: null);
|
||||
@override
|
||||
|
||||
@@ -26,6 +26,7 @@ import 'package:wger/screens/nutritional_plan_screen.dart';
|
||||
import 'package:wger/widgets/nutrition/charts.dart';
|
||||
|
||||
import '../../test_data/nutritional_plans.dart';
|
||||
import '../measurements/measurement_provider_test.mocks.dart';
|
||||
import '../other/base_provider_test.mocks.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
@@ -33,13 +34,14 @@ void main() {
|
||||
Widget createNutritionalPlan({locale = 'en'}) {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final client = MockClient();
|
||||
final mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
|
||||
final plan = getNutritionalPlan();
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(testAuthProvider, [], client),
|
||||
create: (context) => NutritionPlansProvider(mockWgerBaseProvider, []),
|
||||
),
|
||||
ChangeNotifierProvider<BodyWeightProvider>(
|
||||
create: (context) => BodyWeightProvider(testAuthProvider, [], client),
|
||||
|
||||
@@ -28,25 +28,23 @@ import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/screens/nutritional_plans_screen.dart';
|
||||
import 'package:wger/widgets/nutrition/forms.dart';
|
||||
|
||||
import '../other/base_provider_test.mocks.dart';
|
||||
import '../utils.dart';
|
||||
import '../measurements/measurement_provider_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
Widget createHomeScreen({locale = 'en'}) {
|
||||
final client = MockClient();
|
||||
when(client.delete(
|
||||
any,
|
||||
headers: anyNamed('headers'),
|
||||
)).thenAnswer((_) async => http.Response('', 200));
|
||||
final mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
|
||||
when(mockWgerBaseProvider.deleteRequest(any, any)).thenAnswer(
|
||||
(_) async => http.Response('', 200),
|
||||
);
|
||||
|
||||
return ChangeNotifierProvider<NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(
|
||||
testAuthProvider,
|
||||
mockWgerBaseProvider,
|
||||
[
|
||||
NutritionalPlan(id: 1, description: 'test plan 1', creationDate: DateTime(2021, 01, 01)),
|
||||
NutritionalPlan(id: 2, description: 'test plan 2', creationDate: DateTime(2021, 01, 10)),
|
||||
],
|
||||
client,
|
||||
),
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
|
||||
Reference in new issue
Block a user