@@ -21,7 +21,6 @@ import 'dart:io';
21
21
import 'package:drift/native.dart' ;
22
22
import 'package:flutter/material.dart' ;
23
23
import 'package:flutter_test/flutter_test.dart' ;
24
- import 'package:golden_toolkit/golden_toolkit.dart' ;
25
24
import 'package:http/http.dart' as http;
26
25
import 'package:mockito/annotations.dart' ;
27
26
import 'package:provider/provider.dart' ;
@@ -67,6 +66,7 @@ void main() {
67
66
),
68
67
],
69
68
child: MaterialApp (
69
+ key: GlobalKey (),
70
70
locale: Locale (locale),
71
71
localizationsDelegates: AppLocalizations .localizationsDelegates,
72
72
supportedLocales: AppLocalizations .supportedLocales,
@@ -84,23 +84,22 @@ void main() {
84
84
);
85
85
}
86
86
87
- testGoldens (
87
+ testWidgets (
88
88
'Test the widgets on the nutritional plan screen' ,
89
89
(tester) async {
90
- 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
+ tester.view.physicalSize = const Size (500 , 1000 );
91
+ tester.view.devicePixelRatio = 1.0 ; // Ensure correct pixel ratio
92
+
99
93
await tester.pumpWidget (createNutritionalPlan ());
100
94
await tester.tap (find.byType (TextButton ));
101
95
await tester.pumpAndSettle ();
102
96
103
- await screenMatchesGolden (tester, 'nutritional_plan_1_default_view' , skip: ! Platform .isLinux);
97
+ if (Platform .isLinux) {
98
+ await expectLater (
99
+ find.byType (NutritionalPlanScreen ),
100
+ matchesGoldenFile ('goldens/nutritional_plan_1_default_view.png' ),
101
+ );
102
+ }
104
103
105
104
// Default view shows plan description, info button, and no ingredients
106
105
expect (find.text ('Less fat, more protein' ), findsOneWidget);
@@ -113,11 +112,13 @@ void main() {
113
112
var infoOutlineButtons = find.byIcon (Icons .info_outline);
114
113
await tester.tap (infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
115
114
await tester.pumpAndSettle ();
116
- await screenMatchesGolden (
117
- tester,
118
- 'nutritional_plan_2_one_meal_with_ingredients' ,
119
- skip: ! Platform .isLinux,
120
- );
115
+
116
+ if (Platform .isLinux) {
117
+ await expectLater (
118
+ find.byType (NutritionalPlanScreen ),
119
+ matchesGoldenFile ('goldens/nutritional_plan_2_one_meal_with_ingredients.png' ),
120
+ );
121
+ }
121
122
122
123
// Ingredients show up now
123
124
expect (find.text ('100g Water' ), findsOneWidget);
@@ -136,19 +137,27 @@ void main() {
136
137
137
138
await tester.tap (infoOutlineButtons.first);
138
139
await tester.pumpAndSettle ();
139
- await screenMatchesGolden (
140
- tester,
141
- 'nutritional_plan_3_both_meals_with_ingredients' ,
142
- skip: ! Platform .isLinux,
143
- );
140
+
141
+ if (Platform .isLinux) {
142
+ await expectLater (
143
+ find.byType (MaterialApp ),
144
+ matchesGoldenFile ('goldens/nutritional_plan_3_both_meals_with_ingredients.png' ),
145
+ );
146
+ }
147
+
144
148
expect (find.byIcon (Icons .info_outline), findsOneWidget);
145
149
expect (find.byIcon (Icons .info), findsNWidgets (2 ));
146
150
147
151
await tester.scrollUntilVisible (find.text ('300g Broccoli cake' ), 30 );
148
152
expect (find.text ('300g Broccoli cake' ), findsOneWidget);
149
153
150
154
expect (find.byType (Card ), findsNWidgets (3 ));
155
+
156
+ // Restore the original window size.
157
+ tester.view.resetPhysicalSize ();
158
+ tester.view.resetDevicePixelRatio ();
151
159
},
160
+ tags: ['golden' ],
152
161
);
153
162
154
163
testWidgets ('Tests the localization of times - EN' , (WidgetTester tester) async {
0 commit comments