Skip to content

Commit 5c7d4cb

Browse files
committed
test(nutrition): update MealWidget test with nutrition provider stub
- Update MealWidget constructor call - Add interaction steps to reveal ingredients section before testing the add button
1 parent 0ca3de3 commit 5c7d4cb

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

test/nutrition/meal_test.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ import 'package:flutter_test/flutter_test.dart';
2222
import 'package:wger/l10n/generated/app_localizations.dart';
2323
import 'package:wger/models/nutrition/meal.dart';
2424
import 'package:wger/providers/network_provider.dart';
25+
import 'package:wger/providers/nutrition_notifier.dart';
2526
import 'package:wger/widgets/nutrition/meal.dart';
2627

28+
class _StubNutritionNotifier extends NutritionNotifier {
29+
@override
30+
Stream<NutritionState> build() async* {
31+
yield const NutritionState();
32+
}
33+
}
34+
2735
void main() {
2836
Meal buildMeal() => Meal(
2937
id: 'aa000000-0000-4000-8000-000000000001',
@@ -37,13 +45,16 @@ void main() {
3745
// The meal widget does not gate its actions on connectivity. Pinning the
3846
// network status to offline makes a re-introduced connectivity gate fail
3947
// this test.
40-
overrides: [networkStatusProvider.overrideWithValue(isOnline)],
48+
overrides: [
49+
networkStatusProvider.overrideWithValue(isOnline),
50+
nutritionProvider.overrideWith(() => _StubNutritionNotifier()),
51+
],
4152
child: MaterialApp(
4253
localizationsDelegates: AppLocalizations.localizationsDelegates,
4354
supportedLocales: AppLocalizations.supportedLocales,
4455
home: Scaffold(
4556
body: SingleChildScrollView(
46-
child: MealWidget(buildMeal(), const [], false, false),
57+
child: MealWidget(buildMeal(), false, false),
4758
),
4859
),
4960
),
@@ -60,12 +71,18 @@ void main() {
6071
await tester.tap(find.byIcon(Icons.edit));
6172
await tester.pumpAndSettle();
6273

74+
// Reveal the ingredients section by entering details view mode.
75+
// The toolbar is hidden in ViewMode.base, so we must toggle it.
76+
await tester.tap(find.byIcon(Icons.info_outline));
77+
await tester.pumpAndSettle();
78+
6379
final addButton = tester.widget<TextButton>(
6480
find.ancestor(
6581
of: find.byIcon(Icons.add),
6682
matching: find.byType(TextButton),
6783
),
6884
);
85+
6986
expect(addButton.onPressed, isNotNull);
7087
});
7188
}

0 commit comments

Comments
 (0)