Files
flutter/test_data/nutritional_plans.dart
2026-09-26 22:38:40 +02:00

231 lines
5.9 KiB
Dart

/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wger Workout Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:material_ui/material_ui.dart';
import 'package:wger/features/nutrition/models/ingredient.dart';
import 'package:wger/features/nutrition/models/log.dart';
import 'package:wger/features/nutrition/models/meal.dart';
import 'package:wger/features/nutrition/models/meal_item.dart';
import 'package:wger/features/nutrition/models/nutritional_plan.dart';
final ingredient1 = Ingredient(
remoteId: '1',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/1',
id: 1,
code: '123456787',
name: 'Water',
brand: null,
created: DateTime(2021, 5, 1),
energy: 500,
carbohydrates: 10,
carbohydratesSugar: 2,
protein: 5,
fat: 20,
fatSaturated: 7,
fiber: 12,
sodium: 0.5,
isVegan: true,
isVegetarian: true,
nutriscore: NutriScore.a,
);
final ingredient2 = Ingredient(
remoteId: '2',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/2',
id: 2,
code: '123456788',
name: 'Burger soup',
brand: null,
created: DateTime(2021, 5, 10),
energy: 25,
carbohydrates: 10,
carbohydratesSugar: 2,
protein: 1,
fat: 12,
fatSaturated: 9,
fiber: 50,
sodium: 0,
);
final ingredient3 = Ingredient(
remoteId: '3',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/3',
id: 3,
code: '123456789',
name: 'Broccoli cake',
brand: 'Weightwatchers',
created: DateTime(2021, 5, 2),
energy: 1200,
carbohydrates: 110,
carbohydratesSugar: 2,
protein: 9,
fat: 10,
fatSaturated: 8,
fiber: 1,
sodium: 10,
);
final muesli = Ingredient(
remoteId: '1',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/1',
id: 1,
code: '123456787',
name: 'Müsli',
brand: 'Spar Gourmet',
created: DateTime(2021, 5, 1),
energy: 500,
carbohydrates: 10,
carbohydratesSugar: 2,
protein: 5,
fat: 20,
fatSaturated: 7,
fiber: 12,
sodium: 0.5,
isVegan: true,
isVegetarian: true,
nutriscore: NutriScore.b,
);
final milk = Ingredient(
remoteId: '1',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/1',
id: 1,
code: '123456787',
name: 'Milk',
brand: null,
created: DateTime(2021, 5, 1),
energy: 500,
carbohydrates: 10,
carbohydratesSugar: 2,
protein: 5,
fat: 20,
fatSaturated: 7,
fiber: 12,
sodium: 0.5,
isVegetarian: true,
nutriscore: NutriScore.c,
);
final apple = Ingredient(
remoteId: '1',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/1',
id: 1,
code: '123456787',
name: 'Apple',
created: DateTime(2021, 5, 1),
energy: 500,
carbohydrates: 10,
carbohydratesSugar: 2,
protein: 5,
fat: 20,
fatSaturated: 7,
fiber: 12,
sodium: 0.5,
);
final cake = Ingredient(
remoteId: '1',
sourceName: 'Built-in testdata',
sourceUrl: 'https://example.com/ingredient/1',
id: 1,
code: '111111111',
name: 'Lemon CAke',
created: DateTime(2021, 5, 1),
energy: 400,
carbohydrates: 53,
carbohydratesSugar: 37,
protein: 4,
fat: 12,
fatSaturated: 0,
fiber: 0,
sodium: 0,
);
/// Stable UUIDs for the test plans and meals so cross-references
/// (Meal.planId, MealItem.mealId, LogItem.planId/mealId) line up across
/// fixtures and assertions.
const testPlanUuid1 = 'cc000000-0000-4000-8000-000000000001';
const testMealUuid1 = 'aa000000-0000-4000-8000-000000000001';
const testMealUuid2 = 'aa000000-0000-4000-8000-000000000002';
/// Three diary entries matching the meals on [getNutritionalPlan]: 100 g of
/// `ingredient1` (Water), 75 g of `ingredient2` (Burger soup), and 300 g of
/// `ingredient3` (Broccoli cake). Useful as a pre-hydrated payload for
/// `watchAllLogsHydrated` mocks.
List<LogItem> getTestNutritionLogs() => [
LogItem(
planId: testPlanUuid1,
mealId: testMealUuid1,
ingredientId: 1,
amount: 100,
datetime: DateTime(2021, 6, 1),
)..ingredient = ingredient1,
LogItem(
planId: testPlanUuid1,
mealId: testMealUuid1,
ingredientId: 2,
amount: 75,
datetime: DateTime(2021, 6, 1),
)..ingredient = ingredient2,
LogItem(
planId: testPlanUuid1,
mealId: testMealUuid1,
ingredientId: 3,
amount: 300,
datetime: DateTime(2021, 6, 10),
)..ingredient = ingredient3,
];
NutritionalPlan getNutritionalPlan() {
final mealItem1 = MealItem(ingredientId: 1, amount: 100);
mealItem1.ingredient = ingredient1;
final mealItem2 = MealItem(ingredientId: 2, amount: 75);
mealItem2.ingredient = ingredient2;
final mealItem3 = MealItem(ingredientId: 3, amount: 300);
mealItem3.ingredient = ingredient3;
final meal1 = Meal(
id: testMealUuid1,
plan: testPlanUuid1,
time: const TimeOfDay(hour: 17, minute: 0),
name: 'Initial Name 1',
);
meal1.mealItems = [mealItem1, mealItem2];
final meal2 = Meal(
id: testMealUuid2,
plan: testPlanUuid1,
time: const TimeOfDay(hour: 22, minute: 5),
name: 'Initial Name 2',
);
meal2.mealItems = [mealItem3];
final NutritionalPlan plan = NutritionalPlan(
id: testPlanUuid1,
description: 'Less fat, more protein',
creationDate: DateTime(2021, 5, 23),
startDate: DateTime(2021, 5, 23),
);
plan.meals = [meal1, meal2];
plan.diaryEntries = getTestNutritionLogs();
return plan;
}