From 1e5b44c0f5d23e9e20d25e2d3d78d3f0b3c6c26f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 27 Jun 2025 23:09:10 +0200 Subject: [PATCH] fix tests part 1 --- .../nutrition/nutritional_plan_form_test.dart | 22 +++++++++++++------ .../nutritional_plan_model_test.dart | 15 +++++++++---- .../nutritional_plans_screen_test.dart | 17 +++++++++----- test_data/nutritional_plans.dart | 10 ++++++--- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/test/nutrition/nutritional_plan_form_test.dart b/test/nutrition/nutritional_plan_form_test.dart index 5c56634d..a4be9d13 100644 --- a/test/nutrition/nutritional_plan_form_test.dart +++ b/test/nutrition/nutritional_plan_form_test.dart @@ -37,6 +37,7 @@ void main() { final plan1 = NutritionalPlan( id: 1, creationDate: DateTime(2021, 1, 1), + startDate: DateTime(2021, 1, 1), description: 'test plan 1', ); final plan2 = NutritionalPlan.empty(); @@ -60,13 +61,15 @@ void main() { navigatorKey: key, home: Scaffold(body: PlanForm(plan)), routes: { - NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(), + NutritionalPlanScreen.routeName: (ctx) => + const NutritionalPlanScreen(), }, ), ); } - testWidgets('Test the widgets on the nutritional plan form', (WidgetTester tester) async { + testWidgets('Test the widgets on the nutritional plan form', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen(plan1)); await tester.pumpAndSettle(); @@ -75,7 +78,8 @@ void main() { expect(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), findsOneWidget); }); - testWidgets('Test editing an existing nutritional plan', (WidgetTester tester) async { + testWidgets('Test editing an existing nutritional plan', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen(plan1)); await tester.pumpAndSettle(); @@ -84,7 +88,8 @@ void main() { findsOneWidget, reason: 'Description of existing nutritional plan is filled in', ); - await tester.enterText(find.byKey(const Key('field-description')), 'New description'); + await tester.enterText( + find.byKey(const Key('field-description')), 'New description'); await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); // Correct method was called @@ -105,12 +110,15 @@ void main() { //); }); - testWidgets('Test creating a new nutritional plan', (WidgetTester tester) async { + testWidgets('Test creating a new nutritional plan', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen(plan2)); await tester.pumpAndSettle(); - expect(find.text(''), findsOneWidget, reason: 'New nutritional plan has no description'); - await tester.enterText(find.byKey(const Key('field-description')), 'New cool plan'); + expect(find.text(''), findsOneWidget, + reason: 'New nutritional plan has no description'); + await tester.enterText( + find.byKey(const Key('field-description')), 'New cool plan'); await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME))); // Correct method was called diff --git a/test/nutrition/nutritional_plan_model_test.dart b/test/nutrition/nutritional_plan_model_test.dart index ac35a162..eca7b351 100644 --- a/test/nutrition/nutritional_plan_model_test.dart +++ b/test/nutrition/nutritional_plan_model_test.dart @@ -46,11 +46,13 @@ void main() { ), ); }); - test('Test NutritionalPlan.nutritionalValues based on 3 macros and energy', () { + test('Test NutritionalPlan.nutritionalValues based on 3 macros and energy', + () { expect( NutritionalPlan( description: '3 macros and energy defined', creationDate: DateTime(2024, 5, 4), + startDate: DateTime(2024, 5, 4), goalProtein: 150, goalCarbohydrates: 100, goalFat: 100, @@ -64,11 +66,13 @@ void main() { ), ); }); - test('Test NutritionalPlan.nutritionalValues based on 2 macros and energy', () { + test('Test NutritionalPlan.nutritionalValues based on 2 macros and energy', + () { expect( NutritionalPlan( description: '2 macros and energy defined', creationDate: DateTime(2024, 5, 4), + startDate: DateTime(2024, 5, 4), goalProtein: 100, goalCarbohydrates: 100, goalEnergy: 1700, @@ -86,6 +90,7 @@ void main() { NutritionalPlan( description: '3 macros defined', creationDate: DateTime(2024, 5, 4), + startDate: DateTime(2024, 5, 4), goalProtein: 100, goalCarbohydrates: 100, goalFat: 10, @@ -101,12 +106,14 @@ void main() { test('Test the nutritionalValues method for meals', () { final meal = plan.meals.first; - final values = NutritionalValues.values(518.75, 5.75, 17.5, 3.5, 29.0, 13.75, 49.5, 0.5); + final values = NutritionalValues.values( + 518.75, 5.75, 17.5, 3.5, 29.0, 13.75, 49.5, 0.5); expect(meal.plannedNutritionalValues, values); }); test('Test that the getter returns all meal items for a plan', () { - expect(plan.dedupMealItems, plan.meals[0].mealItems + plan.meals[1].mealItems); + expect(plan.dedupMealItems, + plan.meals[0].mealItems + plan.meals[1].mealItems); }); }); } diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index d3ff7657..845bbbd9 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -70,11 +70,13 @@ void main() { id: 1, description: 'test plan 1', creationDate: DateTime(2021, 01, 01), + startDate: DateTime(2021, 01, 01), ), NutritionalPlan( id: 2, description: 'test plan 2', creationDate: DateTime(2021, 01, 10), + startDate: DateTime(2021, 01, 10), ), ], database: database, @@ -89,7 +91,8 @@ void main() { ); } - testWidgets('Test the widgets on the nutritional plans screen', (WidgetTester tester) async { + testWidgets('Test the widgets on the nutritional plans screen', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); //debugDumpApp(); @@ -98,7 +101,8 @@ void main() { expect(find.byType(ListTile), findsNWidgets(2)); }); - testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async { + testWidgets('Test deleting an item using the Delete button', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); await tester.tap(find.byIcon(Icons.delete).first); @@ -114,7 +118,8 @@ void main() { expect(find.byType(ListTile), findsOneWidget); }); - testWidgets('Test the form on the nutritional plan screen', (WidgetTester tester) async { + testWidgets('Test the form on the nutritional plan screen', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); expect(find.byType(PlanForm), findsNothing); @@ -123,14 +128,16 @@ void main() { expect(find.byType(PlanForm), findsOneWidget); }); - testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async { + testWidgets('Tests the localization of dates - EN', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen()); expect(find.text('1/1/2021'), findsOneWidget); expect(find.text('1/10/2021'), findsOneWidget); }); - testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async { + testWidgets('Tests the localization of dates - DE', + (WidgetTester tester) async { await tester.pumpWidget(createHomeScreen(locale: 'de')); expect(find.text('1.1.2021'), findsOneWidget); diff --git a/test_data/nutritional_plans.dart b/test_data/nutritional_plans.dart index 1b3a42cc..d249b48a 100644 --- a/test_data/nutritional_plans.dart +++ b/test_data/nutritional_plans.dart @@ -175,13 +175,17 @@ NutritionalPlan getNutritionalPlan() { id: 1, description: 'Less fat, more protein', creationDate: DateTime(2021, 5, 23), + startDate: DateTime(2021, 5, 23), ); plan.meals = [meal1, meal2]; // Add logs - plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1))); - plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1))); - plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10))); + plan.diaryEntries + .add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1))); + plan.diaryEntries + .add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1))); + plan.diaryEntries + .add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10))); return plan; }