Commit 5683d75

derdilla <82763757+derdilla@users.noreply.github.com>
2025-03-17 13:34:43
Fix opening edit tab when there are no intakes (#542)
* Fix opening edit tab when there are no intakes * Fix test case
1 parent 2456a80
Changed files (2)
app
lib
features
test
features
app/lib/features/input/forms/add_entry_form.dart
@@ -68,7 +68,7 @@ class AddEntryFormState extends FormStateBase<AddEntryFormValue, AddEntryForm> {
       if (widget.initialValue!.record == null
           && widget.initialValue!.intake == null
           && widget.initialValue!.weight != null) {
-        _controller.animateTo(2);
+        _controller.animateTo(widget.meds.isEmpty ? 1 : 2);
       } else if (widget.initialValue!.record == null
           && widget.initialValue!.intake != null) {
         _controller.animateTo(1);
app/test/features/input/forms/add_entry_form_test.dart
@@ -417,6 +417,25 @@ void main() {
       matching: find.text(localizations.sysLong)
     ), findsOneWidget);
   });
+
+  testWidgets('opens correct tab on edit', (tester) async {
+    final key = GlobalKey<AddEntryFormState>();
+    await tester.pumpWidget(materialApp(AddEntryForm(key: key,
+      initialValue: (
+        timestamp: DateTime.now(),
+        weight: BodyweightRecord(time:  DateTime.now(), weight: Weight.kg(123.0)),
+        record: null,
+        note: null,
+        intake: null,
+      ),
+    ),
+      settings: Settings(weightInput: true),
+    ));
+    await tester.pumpAndSettle();
+
+    expect(find.byType(BloodPressureForm), findsNothing);
+    expect(find.byType(WeightForm), findsOneWidget);
+  });
 }
 
 class _MockBluetoothCubit extends Fake implements BluetoothCubit {