Commit 07e07b3

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-06-25 13:29:08
extract and test confirm deletion dialoge
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 91c9f89
Changed files (4)
app
app/lib/components/dialoges/confirm_deletion_dialoge.dart
@@ -0,0 +1,33 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+
+/// Show a dialoge that prompts the user to confirm a deletion.
+///
+/// Returns whether it is ok to proceed with deletion.
+Future<bool> showConfirmDeletionDialoge(BuildContext context) async =>
+await showDialog<bool>(context: context,
+  builder: (context) => AlertDialog(
+    title: Text(AppLocalizations.of(context)!.confirmDelete),
+    content: Text(AppLocalizations.of(context)!.confirmDeleteDesc),
+    actions: [
+      TextButton(
+        onPressed: () => Navigator.pop(context, false),
+        child: Text(AppLocalizations.of(context)!.btnCancel),
+      ),
+      Theme(
+        data: ThemeData.from(
+          colorScheme: ColorScheme.fromSeed(
+            seedColor: Colors.red,
+            brightness: Theme.of(context).brightness,
+          ),
+          useMaterial3: true,
+        ),
+        child: ElevatedButton.icon(
+          onPressed: () => Navigator.pop(context, true),
+          icon: const Icon(Icons.delete_forever),
+          label: Text(AppLocalizations.of(context)!.btnConfirm),
+        ),
+      ),
+    ],
+  ),
+) ?? false;
app/lib/components/measurement_list/measurement_list_entry.dart
@@ -1,3 +1,4 @@
+import 'package:blood_pressure_app/components/dialoges/confirm_deletion_dialoge.dart';
 import 'package:blood_pressure_app/model/blood_pressure/pressure_unit.dart';
 import 'package:blood_pressure_app/model/storage/storage.dart';
 import 'package:flutter/material.dart';
@@ -144,31 +145,3 @@ class MeasurementListRow extends StatelessWidget {
     }
   }
 }
-
-/// Show a dialoge that prompts the user to confirm a deletion.
-///
-/// Returns whether it is ok to proceed with deletion.
-Future<bool> showConfirmDeletionDialoge(BuildContext context) async => // TODO: move to own file
-  await showDialog<bool>(context: context,
-    builder: (context) => AlertDialog(
-      title: Text(AppLocalizations.of(context)!.confirmDelete),
-      content: Text(AppLocalizations.of(context)!.confirmDeleteDesc),
-      actions: [
-        ElevatedButton(
-          onPressed: () => Navigator.pop(context, false),
-          child: Text(AppLocalizations.of(context)!.btnCancel),
-        ),
-        Theme(
-          data: ThemeData.from(
-            colorScheme: ColorScheme.fromSeed(seedColor: Colors.red, brightness: Theme.of(context).brightness),
-            useMaterial3: true,
-          ),
-          child: ElevatedButton.icon(
-            onPressed: () => Navigator.pop(context, true),
-            icon: const Icon(Icons.delete_forever),
-            label: Text(AppLocalizations.of(context)!.btnConfirm),
-          ),
-        ),
-      ],
-    ),
-  ) ?? false;
app/lib/screens/elements/legacy_measurement_list.dart
@@ -1,7 +1,7 @@
 import 'dart:collection';
 
 import 'package:blood_pressure_app/components/dialoges/add_measurement_dialoge.dart';
-import 'package:blood_pressure_app/components/measurement_list/measurement_list_entry.dart';
+import 'package:blood_pressure_app/components/dialoges/confirm_deletion_dialoge.dart';
 import 'package:blood_pressure_app/model/storage/intervall_store.dart';
 import 'package:blood_pressure_app/model/storage/settings_store.dart';
 import 'package:blood_pressure_app/screens/elements/blood_pressure_builder.dart';
app/test/ui/components/confirm_deletion_dialoge_test.dart
@@ -0,0 +1,34 @@
+import 'package:blood_pressure_app/components/dialoges/confirm_deletion_dialoge.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import 'util.dart';
+
+void main() {
+  testWidgets('shows entire content', (tester) async {
+    await loadDialoge(tester, showConfirmDeletionDialoge);
+    await tester.pumpAndSettle();
+    expect(find.byType(AlertDialog), findsOneWidget);
+    expect(find.descendant(
+      of: find.byType(AlertDialog),
+      matching: find.byType(TextButton),
+    ), findsOneWidget);
+    expect(find.bySubtype<ElevatedButton>(), findsOneWidget);
+
+    final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+    expect(find.text(localizations.confirmDelete), findsOneWidget);
+    expect(find.text(localizations.confirmDeleteDesc), findsOneWidget);
+    expect(find.text(localizations.btnCancel), findsOneWidget);
+    expect(find.text(localizations.btnConfirm), findsOneWidget);
+
+    expect(find.descendant(
+      of: find.bySubtype<ElevatedButton>(),
+      matching: find.byIcon(Icons.delete_forever),
+    ), findsOneWidget);
+    expect(find.descendant(
+      of: find.bySubtype<ElevatedButton>(),
+      matching: find.text(localizations.btnConfirm),
+    ), findsOneWidget);
+  });
+}