mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
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
This commit is contained in:
@@ -22,8 +22,16 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/providers/network_provider.dart';
|
||||
import 'package:wger/providers/nutrition_notifier.dart';
|
||||
import 'package:wger/widgets/nutrition/meal.dart';
|
||||
|
||||
class _StubNutritionNotifier extends NutritionNotifier {
|
||||
@override
|
||||
Stream<NutritionState> build() async* {
|
||||
yield const NutritionState();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Meal buildMeal() => Meal(
|
||||
id: 'aa000000-0000-4000-8000-000000000001',
|
||||
@@ -37,13 +45,16 @@ void main() {
|
||||
// The meal widget does not gate its actions on connectivity. Pinning the
|
||||
// network status to offline makes a re-introduced connectivity gate fail
|
||||
// this test.
|
||||
overrides: [networkStatusProvider.overrideWithValue(isOnline)],
|
||||
overrides: [
|
||||
networkStatusProvider.overrideWithValue(isOnline),
|
||||
nutritionProvider.overrideWith(() => _StubNutritionNotifier()),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: MealWidget(buildMeal(), const [], false, false),
|
||||
child: MealWidget(buildMeal(), false, false),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -60,12 +71,18 @@ void main() {
|
||||
await tester.tap(find.byIcon(Icons.edit));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Reveal the ingredients section by entering details view mode.
|
||||
// The toolbar is hidden in ViewMode.base, so we must toggle it.
|
||||
await tester.tap(find.byIcon(Icons.info_outline));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final addButton = tester.widget<TextButton>(
|
||||
find.ancestor(
|
||||
of: find.byIcon(Icons.add),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
);
|
||||
|
||||
expect(addButton.onPressed, isNotNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user