chore: add tests for changes related to brand field

This commit is contained in:
Anja Klipic
2026-05-23 13:10:16 +02:00
parent 8b5a381694
commit 10cb77cffd
2 changed files with 82 additions and 0 deletions

View File

@@ -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(

View File

@@ -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';