@@ -22,6 +22,34 @@ import 'package:wger/l10n/generated/app_localizations.dart';
2222import 'package:wger/models/nutrition/ingredient.dart' ;
2323import 'package:wger/widgets/nutrition/ingredient_dialogs.dart' ;
2424
25+ import '../../../test_data/nutritional_plans.dart' ;
26+
27+ Future <void > pumpIngredientDetailsDialog (
28+ WidgetTester tester, {
29+ required AsyncSnapshot <Ingredient > snapshot,
30+ }) async {
31+ await tester.pumpWidget (
32+ MaterialApp (
33+ locale: const Locale ('en' ),
34+ localizationsDelegates: AppLocalizations .localizationsDelegates,
35+ supportedLocales: AppLocalizations .supportedLocales,
36+ home: Scaffold (
37+ body: Builder (
38+ builder: (context) => ElevatedButton (
39+ onPressed: () {
40+ showDialog (
41+ context: context,
42+ builder: (_) => IngredientDetails (snapshot),
43+ );
44+ },
45+ child: const Text ('Show Dialog' ),
46+ ),
47+ ),
48+ ),
49+ ),
50+ );
51+ }
52+
2553Future <void > pumpIngredientScanDialog (
2654 WidgetTester tester, {
2755 required AsyncSnapshot <Ingredient ?> snapshot,
@@ -54,6 +82,39 @@ Future<void> pumpIngredientScanDialog(
5482}
5583
5684void main () {
85+ group ('IngredientDetails tests' , () {
86+ testWidgets ('shows brand below name in title when ingredient has a brand' , (
87+ WidgetTester tester,
88+ ) async {
89+ // ingredient3 (Broccoli cake, brand: 'Weightwatchers')
90+ final snapshot = AsyncSnapshot <Ingredient >.withData (ConnectionState .done, ingredient3);
91+
92+ await pumpIngredientDetailsDialog (tester, snapshot: snapshot);
93+ await tester.tap (find.text ('Show Dialog' ));
94+ await tester.pumpAndSettle ();
95+
96+ expect (find.byType (AlertDialog ), findsOneWidget);
97+ expect (find.text ('Broccoli cake' ), findsOneWidget);
98+ expect (find.text ('Weightwatchers' ), findsOneWidget);
99+ });
100+
101+ testWidgets ('does not show brand in title when ingredient has no brand' , (
102+ WidgetTester tester,
103+ ) async {
104+ // ingredient1 (Water, brand: null)
105+ final snapshot = AsyncSnapshot <Ingredient >.withData (ConnectionState .done, ingredient1);
106+
107+ await pumpIngredientDetailsDialog (tester, snapshot: snapshot);
108+ await tester.tap (find.text ('Show Dialog' ));
109+ await tester.pumpAndSettle ();
110+
111+ expect (find.byType (AlertDialog ), findsOneWidget);
112+ expect (find.text ('Water' ), findsOneWidget);
113+ // brand: null must not render as the literal string "null"
114+ expect (find.text ('null' ), findsNothing);
115+ });
116+ });
117+
57118 group ('IngredientScanResultDialog tests' , () {
58119 const testBarcode = '1234567890123' ;
59120
0 commit comments