fix tests

This commit is contained in:
Dieter Plaetinck
2024-05-21 14:13:00 +02:00
parent 74002350ba
commit d4d298ad9e
2 changed files with 11 additions and 8 deletions

View File

@@ -157,10 +157,10 @@ class IngredientForm extends StatefulWidget {
});
@override
State<IngredientForm> createState() => _IngredientFormState();
State<IngredientForm> createState() => IngredientFormState();
}
class _IngredientFormState extends State<IngredientForm> {
class IngredientFormState extends State<IngredientForm> {
final _form = GlobalKey<FormState>();
final _ingredientController = TextEditingController();
final _ingredientIdController = TextEditingController();
@@ -209,7 +209,10 @@ class _IngredientFormState extends State<IngredientForm> {
onFieldSubmitted: (_) {},
onChanged: (value) {
setState(() {
_mealItem.amount = double.tryParse(value) ?? _mealItem.amount;
final v = double.tryParse(value);
if (v != null) {
_mealItem.amount = v;
}
});
},
onSaved: (value) {

View File

@@ -213,7 +213,7 @@ void main() {
testWidgets('confirm found ingredient dialog', (WidgetTester tester) async {
await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true));
final IngredientForm formScreen = tester.widget(find.byType(IngredientForm));
final IngredientFormState formState = tester.state(find.byType(IngredientForm));
await tester.tap(find.byKey(const Key('scan-button')));
await tester.pumpAndSettle();
@@ -223,7 +223,7 @@ void main() {
await tester.tap(find.byKey(const Key('found-dialog-confirm-button')));
await tester.pumpAndSettle();
expect(formScreen.ingredientIdController.text, '1');
expect(formState.ingredientIdController.text, '1');
});
testWidgets('close found ingredient dialog', (WidgetTester tester) async {
@@ -293,7 +293,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(createMealItemFormScreen(meal1, '123', true));
final IngredientForm formScreen = tester.widget(find.byType(IngredientForm));
final IngredientFormState formState = tester.state(find.byType(IngredientForm));
await tester.tap(find.byKey(const Key('scan-button')));
await tester.pumpAndSettle();
@@ -303,7 +303,7 @@ void main() {
await tester.tap(find.byKey(const Key('found-dialog-confirm-button')));
await tester.pumpAndSettle();
expect(formScreen.ingredientIdController.text, '1');
expect(formState.ingredientIdController.text, '1');
await tester.enterText(find.byKey(const Key('field-weight')), '2');
await tester.pumpAndSettle();
@@ -313,7 +313,7 @@ void main() {
await tester.tap(find.byKey(const Key(SUBMIT_BUTTON_KEY_NAME)));
await tester.pumpAndSettle();
expect(formScreen.mealItem.amount, 2);
expect(formState.mealItem.amount, 2);
verify(mockNutrition.addMealItem(any, meal1));
});