16
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
19
- import 'dart:io' ;
20
-
21
19
import 'package:drift/native.dart' ;
22
20
import 'package:flutter/material.dart' ;
23
21
import 'package:flutter_test/flutter_test.dart' ;
24
- import 'package:golden_toolkit/golden_toolkit.dart' ;
25
22
import 'package:http/http.dart' as http;
26
23
import 'package:mockito/annotations.dart' ;
27
24
import 'package:provider/provider.dart' ;
@@ -34,6 +31,7 @@ import 'package:wger/providers/nutrition.dart';
34
31
import 'package:wger/screens/nutritional_plan_screen.dart' ;
35
32
36
33
import '../../test_data/nutritional_plans.dart' ;
34
+ import '../utils.dart' ;
37
35
import 'nutritional_plan_screen_test.mocks.dart' ;
38
36
39
37
@GenerateMocks ([WgerBaseProvider , AuthProvider , http.Client ])
@@ -67,6 +65,7 @@ void main() {
67
65
),
68
66
],
69
67
child: MaterialApp (
68
+ key: GlobalKey (),
70
69
locale: Locale (locale),
71
70
localizationsDelegates: AppLocalizations .localizationsDelegates,
72
71
supportedLocales: AppLocalizations .supportedLocales,
@@ -84,40 +83,38 @@ void main() {
84
83
);
85
84
}
86
85
87
- testGoldens (
86
+ testWidgets (
88
87
'Test the widgets on the nutritional plan screen' ,
89
88
(tester) async {
90
89
await loadAppFonts ();
91
- final globalKey = GlobalKey ();
92
- await tester.pumpWidgetBuilder (
93
- Material (key: globalKey),
94
- wrapper: materialAppWrapper (
95
- localizations: [AppLocalizations .delegate],
96
- ),
97
- surfaceSize: const Size (500 , 1000 ),
98
- );
90
+
91
+ tester.view.physicalSize = const Size (500 , 1000 );
92
+ tester.view.devicePixelRatio = 1.0 ; // Ensure correct pixel ratio
93
+
99
94
await tester.pumpWidget (createNutritionalPlan ());
100
95
await tester.tap (find.byType (TextButton ));
101
96
await tester.pumpAndSettle ();
102
97
103
- await screenMatchesGolden (tester, 'nutritional_plan_1_default_view' , skip: ! Platform .isLinux);
98
+ await expectLater (find.byType (NutritionalPlanScreen ),
99
+ matchesGoldenFile ('goldens/nutritional_plan_1_default_view.png' ));
104
100
105
101
// Default view shows plan description, info button, and no ingredients
106
102
expect (find.text ('Less fat, more protein' ), findsOneWidget);
107
- expect (find.byIcon (Icons .info_outline), findsNWidgets (3 )); // 2 meals, 1 "other logs"
103
+ expect (find.byIcon (Icons .info_outline),
104
+ findsNWidgets (3 )); // 2 meals, 1 "other logs"
108
105
expect (find.byIcon (Icons .info), findsNothing);
109
106
expect (find.text ('100g Water' ), findsNothing);
110
107
expect (find.text ('75g Burger soup' ), findsNothing);
111
108
112
109
// tap the first info button changes it and reveals ingredients for the first meal
113
110
var infoOutlineButtons = find.byIcon (Icons .info_outline);
114
- await tester.tap (infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
111
+ await tester.tap (infoOutlineButtons
112
+ .first); // 2nd button shows up also, but is off-screen
115
113
await tester.pumpAndSettle ();
116
- await screenMatchesGolden (
117
- tester,
118
- 'nutritional_plan_2_one_meal_with_ingredients' ,
119
- skip: ! Platform .isLinux,
120
- );
114
+ await expectLater (
115
+ find.byType (NutritionalPlanScreen ),
116
+ matchesGoldenFile (
117
+ 'goldens/nutritional_plan_2_one_meal_with_ingredients.png' ));
121
118
122
119
// Ingredients show up now
123
120
expect (find.text ('100g Water' ), findsOneWidget);
@@ -136,30 +133,36 @@ void main() {
136
133
137
134
await tester.tap (infoOutlineButtons.first);
138
135
await tester.pumpAndSettle ();
139
- await screenMatchesGolden (
140
- tester ,
141
- 'nutritional_plan_3_both_meals_with_ingredients' ,
142
- skip : ! Platform .isLinux,
143
- );
136
+ await expectLater (
137
+ find. byType ( NutritionalPlanScreen ) ,
138
+ matchesGoldenFile (
139
+ 'goldens/nutritional_plan_3_both_meals_with_ingredients.png' ));
140
+
144
141
expect (find.byIcon (Icons .info_outline), findsOneWidget);
145
142
expect (find.byIcon (Icons .info), findsNWidgets (2 ));
146
143
147
144
await tester.scrollUntilVisible (find.text ('300g Broccoli cake' ), 30 );
148
145
expect (find.text ('300g Broccoli cake' ), findsOneWidget);
149
146
150
147
expect (find.byType (Card ), findsNWidgets (3 ));
148
+
149
+ // Restore the original window size.
150
+ tester.view.resetPhysicalSize ();
151
+ tester.view.resetDevicePixelRatio ();
151
152
},
152
153
);
153
154
154
- testWidgets ('Tests the localization of times - EN' , (WidgetTester tester) async {
155
+ testWidgets ('Tests the localization of times - EN' ,
156
+ (WidgetTester tester) async {
155
157
await tester.pumpWidget (createNutritionalPlan ());
156
158
await tester.tap (find.byType (TextButton ));
157
159
await tester.pumpAndSettle ();
158
160
159
161
expect (find.textContaining ('5:00 PM' ), findsOneWidget);
160
162
});
161
163
162
- testWidgets ('Tests the localization of times - DE' , (WidgetTester tester) async {
164
+ testWidgets ('Tests the localization of times - DE' ,
165
+ (WidgetTester tester) async {
163
166
await tester.pumpWidget (createNutritionalPlan (locale: 'de' ));
164
167
await tester.tap (find.byType (TextButton ));
165
168
await tester.pumpAndSettle ();
0 commit comments