mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 12:42:22 +01:00
chore: add tests for changes related to brand field
This commit is contained in:
@@ -174,6 +174,27 @@ void main() {
|
||||
expect(find.text('Vegan'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Shows brand inline in search result tile', (WidgetTester tester) async {
|
||||
// ingredient3 (Broccoli cake) has brand 'Weightwatchers'
|
||||
when(
|
||||
mockNutrition.searchIngredient(
|
||||
any,
|
||||
languageCode: anyNamed('languageCode'),
|
||||
searchLanguage: anyNamed('searchLanguage'),
|
||||
isVegan: anyNamed('isVegan'),
|
||||
isVegetarian: anyNamed('isVegetarian'),
|
||||
nutriscoreMax: anyNamed('nutriscoreMax'),
|
||||
),
|
||||
).thenAnswer((_) => Future.value([ingredient3]));
|
||||
|
||||
await tester.pumpWidget(createWidgetUnderTest());
|
||||
await tester.enterText(find.byType(TextFormField), 'Broccoli');
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Weightwatchers'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Shows no dietary chips when ingredient has no info', (WidgetTester tester) async {
|
||||
// ingredient2 (Burger soup) has no dietary info
|
||||
when(
|
||||
|
||||
@@ -22,6 +22,34 @@ import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.dart';
|
||||
import 'package:wger/widgets/nutrition/ingredient_dialogs.dart';
|
||||
|
||||
import '../../../test_data/nutritional_plans.dart';
|
||||
|
||||
Future<void> pumpIngredientDetailsDialog(
|
||||
WidgetTester tester, {
|
||||
required AsyncSnapshot<Ingredient> snapshot,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => IngredientDetails(snapshot),
|
||||
);
|
||||
},
|
||||
child: const Text('Show Dialog'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpIngredientScanDialog(
|
||||
WidgetTester tester, {
|
||||
required AsyncSnapshot<Ingredient?> snapshot,
|
||||
@@ -54,6 +82,39 @@ Future<void> pumpIngredientScanDialog(
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('IngredientDetails tests', () {
|
||||
testWidgets('shows brand below name in title when ingredient has a brand', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// ingredient3 (Broccoli cake, brand: 'Weightwatchers')
|
||||
final snapshot = AsyncSnapshot<Ingredient>.withData(ConnectionState.done, ingredient3);
|
||||
|
||||
await pumpIngredientDetailsDialog(tester, snapshot: snapshot);
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('Broccoli cake'), findsOneWidget);
|
||||
expect(find.text('Weightwatchers'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('does not show brand in title when ingredient has no brand', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// ingredient1 (Water, brand: null)
|
||||
final snapshot = AsyncSnapshot<Ingredient>.withData(ConnectionState.done, ingredient1);
|
||||
|
||||
await pumpIngredientDetailsDialog(tester, snapshot: snapshot);
|
||||
await tester.tap(find.text('Show Dialog'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('Water'), findsOneWidget);
|
||||
// brand: null must not render as the literal string "null"
|
||||
expect(find.text('null'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
group('IngredientScanResultDialog tests', () {
|
||||
const testBarcode = '1234567890123';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user