Skip to content

Commit 9858089

Browse files
authored
Merge pull request #762 from yashas-hm/yhm/issue-732
golden_toolkit to flutter_test Migration: #732
2 parents 1cd0cab + edc432d commit 9858089

12 files changed

+95
-88
lines changed

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ SPEC CHECKSUMS:
117117
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
118118
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
119119

120-
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
120+
PODFILE CHECKSUM: 775997f741c536251164e3eacf6e34abf2eb7a17
121121

122122
COCOAPODS: 1.16.2

lib/widgets/nutrition/meal.dart

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -301,40 +301,27 @@ class MealHeader extends StatelessWidget {
301301

302302
@override
303303
Widget build(BuildContext context) {
304+
final subtitleTime = _meal.time != null ? '${_meal.time!.format(context)} / ' : '';
305+
final subtitleCalories = _meal.isRealMeal
306+
? getKcalConsumedVsPlanned(_meal, context)
307+
: getKcalConsumed(_meal, context);
308+
final subtitle = '$subtitleTime $subtitleCalories';
309+
304310
return Column(
305311
crossAxisAlignment: CrossAxisAlignment.start,
306312
children: [
307313
ListTile(
308314
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
309-
title: Row(children: [
310-
Expanded(
311-
child: Column(
312-
crossAxisAlignment: CrossAxisAlignment.start,
313-
children: [
314-
Text(
315-
_meal.name,
316-
style: Theme.of(context).textTheme.titleLarge,
317-
),
318-
Row(
319-
children: [
320-
if (_meal.time != null)
321-
Text(
322-
_meal.time!.format(context),
323-
style: Theme.of(context).textTheme.titleSmall,
324-
),
325-
if (_meal.time != null) const SizedBox(width: 12),
326-
Text(
327-
_meal.isRealMeal
328-
? getKcalConsumedVsPlanned(_meal, context)
329-
: getKcalConsumed(_meal, context),
330-
style: Theme.of(context).textTheme.titleSmall,
331-
),
332-
],
333-
),
334-
],
335-
),
336-
),
337-
]),
315+
title: Text(
316+
_meal.name,
317+
style: Theme.of(context).textTheme.titleLarge,
318+
overflow: TextOverflow.ellipsis,
319+
),
320+
subtitle: Text(
321+
subtitle,
322+
style: Theme.of(context).textTheme.titleSmall,
323+
overflow: TextOverflow.ellipsis,
324+
),
338325
trailing: Row(
339326
mainAxisSize: MainAxisSize.min,
340327
children: [

pubspec.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,6 @@ packages:
599599
url: "https://pub.dev"
600600
source: hosted
601601
version: "2.1.3"
602-
golden_toolkit:
603-
dependency: "direct dev"
604-
description:
605-
name: golden_toolkit
606-
sha256: "8f74adab33154fe7b731395782797021f97d2edc52f7bfb85ff4f1b5c4a215f0"
607-
url: "https://pub.dev"
608-
source: hosted
609-
version: "0.15.0"
610602
graphs:
611603
dependency: transitive
612604
description:

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ dev_dependencies:
8383
drift_dev: ^2.26.0
8484
flutter_lints: ^5.0.0
8585
freezed: ^3.0.4
86-
golden_toolkit: ^0.15.0
8786
json_serializable: ^6.9.4
8887
mockito: ^5.4.4
8988
network_image_mock: ^2.1.1
-46.9 KB
Loading
-43.7 KB
Loading
-49.2 KB
Loading

test/nutrition/nutritional_plan_screen_test.dart

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import 'dart:io';
2121
import 'package:drift/native.dart';
2222
import 'package:flutter/material.dart';
2323
import 'package:flutter_test/flutter_test.dart';
24-
import 'package:golden_toolkit/golden_toolkit.dart';
2524
import 'package:http/http.dart' as http;
2625
import 'package:mockito/annotations.dart';
2726
import 'package:provider/provider.dart';
@@ -67,6 +66,7 @@ void main() {
6766
),
6867
],
6968
child: MaterialApp(
69+
key: GlobalKey(),
7070
locale: Locale(locale),
7171
localizationsDelegates: AppLocalizations.localizationsDelegates,
7272
supportedLocales: AppLocalizations.supportedLocales,
@@ -84,23 +84,22 @@ void main() {
8484
);
8585
}
8686

87-
testGoldens(
87+
testWidgets(
8888
'Test the widgets on the nutritional plan screen',
8989
(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+
9993
await tester.pumpWidget(createNutritionalPlan());
10094
await tester.tap(find.byType(TextButton));
10195
await tester.pumpAndSettle();
10296

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+
}
104103

105104
// Default view shows plan description, info button, and no ingredients
106105
expect(find.text('Less fat, more protein'), findsOneWidget);
@@ -113,11 +112,13 @@ void main() {
113112
var infoOutlineButtons = find.byIcon(Icons.info_outline);
114113
await tester.tap(infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
115114
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+
}
121122

122123
// Ingredients show up now
123124
expect(find.text('100g Water'), findsOneWidget);
@@ -136,19 +137,27 @@ void main() {
136137

137138
await tester.tap(infoOutlineButtons.first);
138139
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+
144148
expect(find.byIcon(Icons.info_outline), findsOneWidget);
145149
expect(find.byIcon(Icons.info), findsNWidgets(2));
146150

147151
await tester.scrollUntilVisible(find.text('300g Broccoli cake'), 30);
148152
expect(find.text('300g Broccoli cake'), findsOneWidget);
149153

150154
expect(find.byType(Card), findsNWidgets(3));
155+
156+
// Restore the original window size.
157+
tester.view.resetPhysicalSize();
158+
tester.view.resetDevicePixelRatio();
151159
},
160+
tags: ['golden'],
152161
);
153162

154163
testWidgets('Tests the localization of times - EN', (WidgetTester tester) async {
-167 KB
Loading
-176 KB
Loading

0 commit comments

Comments
 (0)