fix tests part 1

This commit is contained in:
Dieter Plaetinck
2025-06-27 23:09:10 +02:00
parent 450b4da046
commit 1e5b44c0f5
4 changed files with 45 additions and 19 deletions

View File

@@ -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

View File

@@ -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);
});
});
}

View File

@@ -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);

View File

@@ -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;
}