Skip to content

Commit 1e5b44c

Browse files
committed
fix tests part 1
1 parent 450b4da commit 1e5b44c

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

test/nutrition/nutritional_plan_form_test.dart

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void main() {
3737
final plan1 = NutritionalPlan(
3838
id: 1,
3939
creationDate: DateTime(2021, 1, 1),
40+
startDate: DateTime(2021, 1, 1),
4041
description: 'test plan 1',
4142
);
4243
final plan2 = NutritionalPlan.empty();
@@ -60,13 +61,15 @@ void main() {
6061
navigatorKey: key,
6162
home: Scaffold(body: PlanForm(plan)),
6263
routes: {
63-
NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(),
64+
NutritionalPlanScreen.routeName: (ctx) =>
65+
const NutritionalPlanScreen(),
6466
},
6567
),
6668
);
6769
}
6870

69-
testWidgets('Test the widgets on the nutritional plan form', (WidgetTester tester) async {
71+
testWidgets('Test the widgets on the nutritional plan form',
72+
(WidgetTester tester) async {
7073
await tester.pumpWidget(createHomeScreen(plan1));
7174
await tester.pumpAndSettle();
7275

@@ -75,7 +78,8 @@ void main() {
7578
expect(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)), findsOneWidget);
7679
});
7780

78-
testWidgets('Test editing an existing nutritional plan', (WidgetTester tester) async {
81+
testWidgets('Test editing an existing nutritional plan',
82+
(WidgetTester tester) async {
7983
await tester.pumpWidget(createHomeScreen(plan1));
8084
await tester.pumpAndSettle();
8185

@@ -84,7 +88,8 @@ void main() {
8488
findsOneWidget,
8589
reason: 'Description of existing nutritional plan is filled in',
8690
);
87-
await tester.enterText(find.byKey(const Key('field-description')), 'New description');
91+
await tester.enterText(
92+
find.byKey(const Key('field-description')), 'New description');
8893
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
8994

9095
// Correct method was called
@@ -105,12 +110,15 @@ void main() {
105110
//);
106111
});
107112

108-
testWidgets('Test creating a new nutritional plan', (WidgetTester tester) async {
113+
testWidgets('Test creating a new nutritional plan',
114+
(WidgetTester tester) async {
109115
await tester.pumpWidget(createHomeScreen(plan2));
110116
await tester.pumpAndSettle();
111117

112-
expect(find.text(''), findsOneWidget, reason: 'New nutritional plan has no description');
113-
await tester.enterText(find.byKey(const Key('field-description')), 'New cool plan');
118+
expect(find.text(''), findsOneWidget,
119+
reason: 'New nutritional plan has no description');
120+
await tester.enterText(
121+
find.byKey(const Key('field-description')), 'New cool plan');
114122
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
115123

116124
// Correct method was called

test/nutrition/nutritional_plan_model_test.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ void main() {
4646
),
4747
);
4848
});
49-
test('Test NutritionalPlan.nutritionalValues based on 3 macros and energy', () {
49+
test('Test NutritionalPlan.nutritionalValues based on 3 macros and energy',
50+
() {
5051
expect(
5152
NutritionalPlan(
5253
description: '3 macros and energy defined',
5354
creationDate: DateTime(2024, 5, 4),
55+
startDate: DateTime(2024, 5, 4),
5456
goalProtein: 150,
5557
goalCarbohydrates: 100,
5658
goalFat: 100,
@@ -64,11 +66,13 @@ void main() {
6466
),
6567
);
6668
});
67-
test('Test NutritionalPlan.nutritionalValues based on 2 macros and energy', () {
69+
test('Test NutritionalPlan.nutritionalValues based on 2 macros and energy',
70+
() {
6871
expect(
6972
NutritionalPlan(
7073
description: '2 macros and energy defined',
7174
creationDate: DateTime(2024, 5, 4),
75+
startDate: DateTime(2024, 5, 4),
7276
goalProtein: 100,
7377
goalCarbohydrates: 100,
7478
goalEnergy: 1700,
@@ -86,6 +90,7 @@ void main() {
8690
NutritionalPlan(
8791
description: '3 macros defined',
8892
creationDate: DateTime(2024, 5, 4),
93+
startDate: DateTime(2024, 5, 4),
8994
goalProtein: 100,
9095
goalCarbohydrates: 100,
9196
goalFat: 10,
@@ -101,12 +106,14 @@ void main() {
101106

102107
test('Test the nutritionalValues method for meals', () {
103108
final meal = plan.meals.first;
104-
final values = NutritionalValues.values(518.75, 5.75, 17.5, 3.5, 29.0, 13.75, 49.5, 0.5);
109+
final values = NutritionalValues.values(
110+
518.75, 5.75, 17.5, 3.5, 29.0, 13.75, 49.5, 0.5);
105111
expect(meal.plannedNutritionalValues, values);
106112
});
107113

108114
test('Test that the getter returns all meal items for a plan', () {
109-
expect(plan.dedupMealItems, plan.meals[0].mealItems + plan.meals[1].mealItems);
115+
expect(plan.dedupMealItems,
116+
plan.meals[0].mealItems + plan.meals[1].mealItems);
110117
});
111118
});
112119
}

test/nutrition/nutritional_plans_screen_test.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ void main() {
7070
id: 1,
7171
description: 'test plan 1',
7272
creationDate: DateTime(2021, 01, 01),
73+
startDate: DateTime(2021, 01, 01),
7374
),
7475
NutritionalPlan(
7576
id: 2,
7677
description: 'test plan 2',
7778
creationDate: DateTime(2021, 01, 10),
79+
startDate: DateTime(2021, 01, 10),
7880
),
7981
],
8082
database: database,
@@ -89,7 +91,8 @@ void main() {
8991
);
9092
}
9193

92-
testWidgets('Test the widgets on the nutritional plans screen', (WidgetTester tester) async {
94+
testWidgets('Test the widgets on the nutritional plans screen',
95+
(WidgetTester tester) async {
9396
await tester.pumpWidget(createHomeScreen());
9497

9598
//debugDumpApp();
@@ -98,7 +101,8 @@ void main() {
98101
expect(find.byType(ListTile), findsNWidgets(2));
99102
});
100103

101-
testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async {
104+
testWidgets('Test deleting an item using the Delete button',
105+
(WidgetTester tester) async {
102106
await tester.pumpWidget(createHomeScreen());
103107

104108
await tester.tap(find.byIcon(Icons.delete).first);
@@ -114,7 +118,8 @@ void main() {
114118
expect(find.byType(ListTile), findsOneWidget);
115119
});
116120

117-
testWidgets('Test the form on the nutritional plan screen', (WidgetTester tester) async {
121+
testWidgets('Test the form on the nutritional plan screen',
122+
(WidgetTester tester) async {
118123
await tester.pumpWidget(createHomeScreen());
119124

120125
expect(find.byType(PlanForm), findsNothing);
@@ -123,14 +128,16 @@ void main() {
123128
expect(find.byType(PlanForm), findsOneWidget);
124129
});
125130

126-
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
131+
testWidgets('Tests the localization of dates - EN',
132+
(WidgetTester tester) async {
127133
await tester.pumpWidget(createHomeScreen());
128134

129135
expect(find.text('1/1/2021'), findsOneWidget);
130136
expect(find.text('1/10/2021'), findsOneWidget);
131137
});
132138

133-
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
139+
testWidgets('Tests the localization of dates - DE',
140+
(WidgetTester tester) async {
134141
await tester.pumpWidget(createHomeScreen(locale: 'de'));
135142

136143
expect(find.text('1.1.2021'), findsOneWidget);

test_data/nutritional_plans.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ NutritionalPlan getNutritionalPlan() {
175175
id: 1,
176176
description: 'Less fat, more protein',
177177
creationDate: DateTime(2021, 5, 23),
178+
startDate: DateTime(2021, 5, 23),
178179
);
179180
plan.meals = [meal1, meal2];
180181

181182
// Add logs
182-
plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1)));
183-
plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1)));
184-
plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10)));
183+
plan.diaryEntries
184+
.add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1)));
185+
plan.diaryEntries
186+
.add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1)));
187+
plan.diaryEntries
188+
.add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10)));
185189

186190
return plan;
187191
}

0 commit comments

Comments
 (0)