Commit 2a93d69

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2023-12-25 14:21:54
simplify repetitive test code
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 8badde6
test/ui/components/add_export_column_dialoge_test.dart
@@ -66,22 +66,13 @@ void main() {
   });
   group('showAddExportColumnDialoge', () {
     testWidgets('should open AddExportColumnDialoge', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(Builder(builder: (context) => TextButton(onPressed: () =>
-          showAddExportColumnDialoge(context, Settings()), child: const Text('X')))));
-
-      expect(find.byType(AddExportColumnDialoge), findsNothing);
-      expect(find.text('X'), findsOneWidget);
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) => showAddExportColumnDialoge(context, Settings()));
 
       expect(find.byType(AddExportColumnDialoge), findsOneWidget);
     });
     testWidgets('should return null on cancel', (widgetTester) async {
       dynamic returnedValue = false;
-      await widgetTester.pumpWidget(materialApp(Builder(builder: (context) => TextButton(onPressed: () async =>
-          returnedValue = await showAddExportColumnDialoge(context, Settings()), child: const Text('X')))));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) async => returnedValue = await showAddExportColumnDialoge(context, Settings()));
 
       expect(returnedValue, false);
       expect(find.byIcon(Icons.close), findsOneWidget);
@@ -93,12 +84,10 @@ void main() {
     });
     testWidgets('should save entered values', (widgetTester) async {
       dynamic returnedValue = false;
-      await widgetTester.pumpWidget(materialApp(Builder(builder: (context) => TextButton(onPressed: () async =>
-        returnedValue = await showAddExportColumnDialoge(context, Settings()), child: const Text('X')))));
+      await loadDialoge(widgetTester, (context) async => returnedValue = await showAddExportColumnDialoge(context, Settings()));
+
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
       expect(returnedValue, false);
 
       expect(find.ancestor(of: find.text(localizations.csvTitle).first, matching: find.byType(TextFormField)),
@@ -123,15 +112,14 @@ void main() {
           .having((p0) => p0.formatter.formatPattern, 'formatter', r'test$SYSformat'));
     });
     testWidgets('should keep internalIdentifier on edit', (widgetTester) async {
-      dynamic returnedValue = false;
-      await widgetTester.pumpWidget(materialApp(Builder(builder: (context) => TextButton(onPressed: () async =>
-        returnedValue = await showAddExportColumnDialoge(context, Settings(),
-            UserColumn('initialInternalIdentifier', 'csvTitle', 'formatPattern')
-      ), child: const Text('X')))));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
+      dynamic returnedValue = false;
+      await loadDialoge(widgetTester, (context) async => returnedValue =
+        await showAddExportColumnDialoge(context, Settings(),
+          UserColumn('initialInternalIdentifier', 'csvTitle', 'formatPattern')
+      ));
+
       expect(returnedValue, false);
 
       expect(find.ancestor(of: find.text(localizations.csvTitle).first, matching: find.byType(TextFormField)),
test/ui/components/add_measurement_dialoge_test.dart
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
 import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 import 'package:flutter_test/flutter_test.dart';
 
+import '../../model/export_import/record_formatter_test.dart';
 import 'settings/color_picker_list_tile_test.dart';
 import 'util.dart';
 
@@ -51,18 +52,9 @@ void main() {
   group('showAddMeasurementDialoge', () {
     testWidgets('should return null on cancel', (widgetTester) async {
       dynamic result = 'not null';
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              result = await showAddMeasurementDialoge(context, Settings(),
-                  BloodPressureRecord(
-                      DateTime.now(), 123, 56, 43, 'Test note',
-                      needlePin: const MeasurementNeedlePin(Colors.teal)
-                  ));
-            }, child: const Text('TEST')),
-      )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) async
+        => result = await showAddMeasurementDialoge(context, Settings(),
+          mockRecord(sys: 123, dia: 56, pul: 43, note: 'Test note', pin: Colors.teal)));
 
       expect(find.byType(AddMeasurementDialoge), findsOneWidget);
       await widgetTester.tap(find.byIcon(Icons.close));
@@ -73,18 +65,9 @@ void main() {
     });
     testWidgets('should return values on cancel', (widgetTester) async {
       dynamic result = 'not null';
-      final record = BloodPressureRecord(
-          DateTime.now(), 123, 56, 43, 'Test note',
-          needlePin: const MeasurementNeedlePin(Colors.teal)
-      );
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              result = await showAddMeasurementDialoge(context, Settings(), record);
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      final record = mockRecord(sys: 123, dia: 56, pul: 43, note: 'Test note', pin: Colors.teal);
+      await loadDialoge(widgetTester, (context) async
+        => result = await showAddMeasurementDialoge(context, Settings(), record));
 
       expect(find.byType(AddMeasurementDialoge), findsOneWidget);
       await widgetTester.tap(find.text('SAVE'));
@@ -98,14 +81,8 @@ void main() {
     });
     testWidgets('should be able to input values', (WidgetTester widgetTester) async {
       dynamic result = 'not null';
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              result = await showAddMeasurementDialoge(context, Settings());
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) async
+        => result = await showAddMeasurementDialoge(context, Settings()));
 
       await widgetTester.enterText(find.ancestor(of: find.text('Systolic').first, matching: find.byType(TextFormField)), '123');
       await widgetTester.enterText(find.ancestor(of: find.text('Diastolic').first, matching: find.byType(TextFormField)), '67');
@@ -130,21 +107,8 @@ void main() {
       expect(castResult.needlePin?.color, Colors.red);
     });
     testWidgets('should not allow invalid values', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(Container()));
-      late final BuildContext buildContext;
-
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) {
-              buildContext = context;
-              return TextButton(onPressed: () async {
-                await showAddMeasurementDialoge(context, Settings());
-              }, child: const Text('TEST'));
-            },
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
-      final localizations = AppLocalizations.of(buildContext)!;
+      await loadDialoge(widgetTester, (context) => showAddMeasurementDialoge(context, Settings()));
+      final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 
       expect(find.byType(AddMeasurementDialoge), findsOneWidget);
       expect(find.text(localizations.errNaN), findsNothing);
@@ -152,7 +116,6 @@ void main() {
       expect(find.text(localizations.errUnrealistic), findsNothing);
       expect(find.text(localizations.errDiaGtSys), findsNothing);
 
-
       await widgetTester.enterText(find.ancestor(of: find.text('Systolic').first, matching: find.byType(TextFormField)), '123');
       await widgetTester.enterText(find.ancestor(of: find.text('Diastolic').first, matching: find.byType(TextFormField)), '67');
 
@@ -205,14 +168,8 @@ void main() {
       expect(find.text(localizations.errDiaGtSys), findsNothing);
     });
     testWidgets('should allow invalid values when setting is set', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              await showAddMeasurementDialoge(context, Settings(validateInputs: false, allowMissingValues: true));
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) =>
+          showAddMeasurementDialoge(context, Settings(validateInputs: false, allowMissingValues: true)));
 
       await widgetTester.enterText(find.ancestor(of: find.text('Systolic').first, matching: find.byType(TextFormField)), '2');
       await widgetTester.enterText(find.ancestor(of: find.text('Diastolic').first, matching: find.byType(TextFormField)), '500');
@@ -221,27 +178,14 @@ void main() {
       expect(find.byType(AddMeasurementDialoge), findsNothing);
     });
     testWidgets('should respect settings.allowManualTimeInput', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              await showAddMeasurementDialoge(context, Settings(allowManualTimeInput: false));
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) =>
+          showAddMeasurementDialoge(context, Settings(allowManualTimeInput: false)));
 
       expect(find.byIcon(Icons.edit), findsNothing);
     });
     testWidgets('should start with sys input focused', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              await showAddMeasurementDialoge(context, Settings(allowManualTimeInput: false),
-                  BloodPressureRecord(DateTime.now(), 12, 3, 4, 'note'));
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) =>
+          showAddMeasurementDialoge(context, Settings(), mockRecord(sys: 12)));
 
       final primaryFocus = FocusManager.instance.primaryFocus;
       expect(primaryFocus?.context?.widget, isNotNull);
@@ -251,18 +195,11 @@ void main() {
       );
       expect(focusedTextFormField, findsOneWidget);
       expect(focusedTextFormField.evaluate().first.widget, isA<TextFormField>()
-          .having((p0) => p0.initialValue, 'expecting systolic field to be selected', '12'));
+          .having((p0) => p0.initialValue, 'systolic content', '12'));
     });
     testWidgets('should focus next on input finished', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              await showAddMeasurementDialoge(context, Settings(allowManualTimeInput: false),
-                  BloodPressureRecord(DateTime.now(), 12, 3, 4, 'note'));
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) =>
+          showAddMeasurementDialoge(context, Settings(), mockRecord(sys: 12, dia: 3, pul: 4, note: 'note')));
 
       await widgetTester.enterText(find.ancestor(of: find.text('Systolic').first, matching: find.byType(TextFormField)), '123');
 
@@ -274,7 +211,7 @@ void main() {
       );
       expect(focusedTextFormField, findsOneWidget);
       expect(focusedTextFormField.evaluate().first.widget, isA<TextFormField>()
-          .having((p0) => p0.initialValue, 'expecting diastolic field to be selected second', '3'));
+          .having((p0) => p0.initialValue, 'diastolic content', '3'));
 
       await widgetTester.enterText(find.ancestor(of: find.text('Diastolic').first, matching: find.byType(TextFormField)), '78');
 
@@ -286,7 +223,7 @@ void main() {
       );
       expect(secondFocusedTextFormField, findsOneWidget);
       expect(secondFocusedTextFormField.evaluate().first.widget, isA<TextFormField>()
-          .having((p0) => p0.initialValue, 'expecting pulse field to be selected third', '4'));
+          .having((p0) => p0.initialValue, 'pulse content', '4'));
 
       await widgetTester.enterText(find.ancestor(of: find.text('Pulse').first, matching: find.byType(TextFormField)), '60');
 
@@ -298,19 +235,12 @@ void main() {
       );
       expect(thirdFocusedTextFormField, findsOneWidget);
       expect(thirdFocusedTextFormField.evaluate().first.widget, isA<TextFormField>()
-          .having((p0) => p0.initialValue, 'expecting note field to be selected third', 'note'));
+          .having((p0) => p0.initialValue, 'note input content', 'note'));
     });
 
     testWidgets('should focus last input field on backspace pressed in empty input field', (widgetTester) async {
-      await widgetTester.pumpWidget(materialApp(
-          Builder(
-            builder: (BuildContext context) => TextButton(onPressed: () async {
-              await showAddMeasurementDialoge(context, Settings(allowManualTimeInput: false),
-                  BloodPressureRecord(DateTime.now(), 12, 3, 4, 'note'));
-            }, child: const Text('TEST')),
-          )));
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) =>
+          showAddMeasurementDialoge(context, Settings(), mockRecord(sys: 12, dia: 3, pul: 4, note: 'note')));
 
 
       await widgetTester.enterText(find.ancestor(of: find.text('note').first, matching: find.byType(TextFormField)), '');
test/ui/components/enter_timeformat_dialoge_test.dart
@@ -1,37 +1,27 @@
 import 'package:blood_pressure_app/components/dialoges/enter_timeformat.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() {
   group('EnterTimeFormatDialoge', () {
     testWidgets('should initialize without errors', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-        localizationsDelegates: [AppLocalizations.delegate,],
-        locale: Locale('en'),
-        home: EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)
-      ));
+      await widgetTester.pumpWidget(materialApp(const EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)));
       expect(widgetTester.takeException(), isNull);
       expect(find.byType(EnterTimeFormatDialoge), findsOneWidget);
     });
     testWidgets('should prefill time format', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-          localizationsDelegates: [AppLocalizations.delegate,],
-          locale: Locale('en'),
-          home: EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)
-      ));
+      await widgetTester.pumpWidget(materialApp( const EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)));
       final textField = find.byType(TextField);
       expect(textField, findsOneWidget);
       expect(find.descendant(of: textField, matching: find.text('yyyy-MM-dd HH:mm')), findsOneWidget);
     });
     testWidgets('should show preview', (widgetTester) async {
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,],
-          locale: const Locale('en'),
-          home: EnterTimeFormatDialoge(
-            initialValue: 'yyyy-MM-dd HH:mm',
-            previewTime: DateTime(2023, 7, 23, 8, 20),
-          )
+      await widgetTester.pumpWidget(materialApp(EnterTimeFormatDialoge(
+          initialValue: 'yyyy-MM-dd HH:mm',
+          previewTime: DateTime(2023, 7, 23, 8, 20),
+        )
       ));
       expect(find.text('2023-07-23 08:20'), findsOneWidget);
       
@@ -42,13 +32,7 @@ void main() {
       expect(find.text('3rd quarter + July'), findsOneWidget);
     });
     testWidgets('should close page on close button pressed', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-          localizationsDelegates: [AppLocalizations.delegate,],
-          locale: Locale('en'),
-          home: EnterTimeFormatDialoge(
-            initialValue: 'yyyy-MM-dd HH:mm',
-          )
-      ));
+      await widgetTester.pumpWidget(materialApp(const EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)));
 
       expect(find.byType(EnterTimeFormatDialoge), findsOneWidget);
       expect(find.byIcon(Icons.close), findsOneWidget);
@@ -57,13 +41,7 @@ void main() {
       expect(find.byType(EnterTimeFormatDialoge), findsNothing);
     });
     testWidgets('should not allow saving empty time formats', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-          localizationsDelegates: [AppLocalizations.delegate,],
-          locale: Locale('en'),
-          home: EnterTimeFormatDialoge(
-            initialValue: 'yyyy-MM-dd HH:mm',
-          )
-      ));
+      await widgetTester.pumpWidget(materialApp(const EnterTimeFormatDialoge(initialValue: 'yyyy-MM-dd HH:mm',)));
 
       await widgetTester.enterText(find.byType(TextField), '');
       await widgetTester.pumpAndSettle();
@@ -78,18 +56,8 @@ void main() {
   group('showTimeFormatPickerDialoge', () {
     testWidgets('should return null on close', (widgetTester) async {
       String? result = 'notnull';
-      await widgetTester.pumpWidget(MaterialApp(
-        localizationsDelegates: const [AppLocalizations.delegate,],
-        locale: const Locale('en'),
-        home: Builder(
-          builder: (BuildContext context) => TextButton(onPressed: () async {
-            result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm');
-          }, child: const Text('TEST')),
-        ),
-      ));
-
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester,
+              (context) async => result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm'));
 
       expect(find.byIcon(Icons.close), findsOneWidget);
       await widgetTester.tap(find.byIcon(Icons.close));
@@ -99,18 +67,8 @@ void main() {
     });
     testWidgets('should return value on save', (widgetTester) async {
       String? result;
-      await widgetTester.pumpWidget(MaterialApp(
-        localizationsDelegates: const [AppLocalizations.delegate,],
-        locale: const Locale('en'),
-        home: Builder(
-          builder: (BuildContext context) => TextButton(onPressed: () async {
-            result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm');
-          }, child: const Text('TEST')),
-        ),
-      ));
-
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester,
+              (context) async => result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm'));
 
       expect(find.text('SAVE'), findsOneWidget);
       await widgetTester.tap(find.text('SAVE'));
@@ -120,18 +78,8 @@ void main() {
     });
     testWidgets('should return modified value on save', (widgetTester) async {
       String? result;
-      await widgetTester.pumpWidget(MaterialApp(
-        localizationsDelegates: const [AppLocalizations.delegate,],
-        locale: const Locale('en'),
-        home: Builder(
-          builder: (BuildContext context) => TextButton(onPressed: () async {
-            result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm');
-          }, child: const Text('TEST')),
-        ),
-      ));
-
-      await widgetTester.tap(find.text('TEST'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester,
+              (context) async => result = await showTimeFormatPickerDialoge(context, 'yyyy-MM-dd HH:mm'));
 
       await widgetTester.enterText(find.byType(TextField), 'test text!');
       await widgetTester.pumpAndSettle();
test/ui/components/input_dialoge_test.dart
@@ -3,14 +3,12 @@ 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() {
   group('InputDialoge', () {
     testWidgets('should initialize without errors', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-          localizationsDelegates: [AppLocalizations.delegate,],
-          locale: Locale('en'),
-          home: InputDialoge()
-      ));
+      await widgetTester.pumpWidget(materialApp(const InputDialoge()));
       expect(widgetTester.takeException(), isNull);
       await widgetTester.pumpWidget(const MaterialApp(
           localizationsDelegates: [AppLocalizations.delegate,], locale: Locale('en'),
@@ -23,24 +21,18 @@ void main() {
       expect(find.byType(InputDialoge), findsOneWidget);
     });
     testWidgets('should show prefilled text', (widgetTester) async {
-      await widgetTester.pumpWidget(const MaterialApp(
-          localizationsDelegates: [AppLocalizations.delegate,], locale: Locale('en'),
-          home: InputDialoge(
-            hintText: 'test hint',
-            initialValue: 'initial text',
-          )
-      ));
+      await widgetTester.pumpWidget(materialApp(const InputDialoge(
+        hintText: 'test hint',
+        initialValue: 'initial text',
+      )));
       expect(find.text('initial text'), findsOneWidget);
       expect(find.text('test hint'), findsNWidgets(2));
     });
     testWidgets('should show validator errors', (widgetTester) async {
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: InputDialoge(
-            initialValue: 'initial text',
-            validator: (_) => 'test error',
-          )
-      ));
+      await widgetTester.pumpWidget(materialApp(InputDialoge(
+        initialValue: 'initial text',
+        validator: (_) => 'test error',
+      )));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 
       expect(find.text(localizations.btnConfirm), findsOneWidget);
@@ -52,17 +44,14 @@ void main() {
     });
     testWidgets('should send current text to validator', (widgetTester) async {
       int validatorCalls = 0;
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: InputDialoge(
-            initialValue: 'initial text',
-            validator: (value) {
-              expect(value, 'initial text');
-              validatorCalls += 1;
-              return null;
-            },
-          )
-      ));
+      await widgetTester.pumpWidget(materialApp(InputDialoge(
+        initialValue: 'initial text',
+        validator: (value) {
+          expect(value, 'initial text');
+          validatorCalls += 1;
+          return null;
+        },
+      )));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 
       expect(validatorCalls, 0);
@@ -78,13 +67,7 @@ void main() {
   });
   group('showInputDialoge', () {
     testWidgets('should start with input focused', (widgetTester) async {
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () => showInputDialoge(context, initialValue: 'testval'), child: const Text('X')))
-      ));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) => showInputDialoge(context, initialValue: 'testval'));
 
       expect(find.byType(InputDialoge), findsOneWidget);
       final primaryFocus = FocusManager.instance.primaryFocus;
@@ -97,16 +80,8 @@ void main() {
     });
     testWidgets('should allow entering a value', (widgetTester) async {
       String? result = 'init';
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () async {
-                result = await showInputDialoge(context);
-              }, child: const Text('X')))
-      ));
+      await loadDialoge(widgetTester, (context) async => result = await showInputDialoge(context));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
 
       expect(find.byType(InputDialoge), findsOneWidget);
       expect(find.byType(TextField), findsOneWidget);
@@ -120,16 +95,8 @@ void main() {
     });
     testWidgets('should not return value on cancel', (widgetTester) async {
       String? result = 'init';
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () async {
-            result = await showInputDialoge(context, initialValue: 'test');
-          }, child: const Text('X')))
-      ));
+      await loadDialoge(widgetTester, (context) async => result = await showInputDialoge(context, initialValue: 'test'));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
 
       expect(find.byType(InputDialoge), findsOneWidget);
       expect(find.byType(TextField), findsOneWidget);
@@ -144,13 +111,7 @@ void main() {
   });
   group('showNumberInputDialoge', () {
     testWidgets('should start with input focused', (widgetTester) async {
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () => showNumberInputDialoge(context, initialValue: 123), child: const Text('X')))
-      ));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
+      await loadDialoge(widgetTester, (context) => showNumberInputDialoge(context, initialValue: 123));
 
       expect(find.byType(InputDialoge), findsOneWidget);
       expect(find.text('123'), findsOneWidget);
@@ -165,16 +126,8 @@ void main() {
     });
     testWidgets('should allow entering a number', (widgetTester) async {
       double? result = -1;
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () async {
-            result = await showNumberInputDialoge(context);
-          }, child: const Text('X')))
-      ));
+      await loadDialoge(widgetTester, (context) async => result = await showNumberInputDialoge(context));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
 
       expect(find.byType(InputDialoge), findsOneWidget);
       expect(find.byType(TextField), findsOneWidget);
@@ -188,16 +141,8 @@ void main() {
     });
     testWidgets('should not allow entering text', (widgetTester) async {
       double? result = -1;
-      await widgetTester.pumpWidget(MaterialApp(
-          localizationsDelegates: const [AppLocalizations.delegate,], locale: const Locale('en'),
-          home: Builder(builder: (BuildContext context) => TextButton(onPressed:
-              () async {
-            result = await showNumberInputDialoge(context);
-          }, child: const Text('X')))
-      ));
+      await loadDialoge(widgetTester, (context) async => result = await showNumberInputDialoge(context));
       final localizations = await AppLocalizations.delegate.load(const Locale('en'));
-      await widgetTester.tap(find.text('X'));
-      await widgetTester.pumpAndSettle();
 
       expect(find.byType(InputDialoge), findsOneWidget);
 
test/ui/components/measurement_list_entry_test.dart
@@ -4,6 +4,7 @@ import 'package:blood_pressure_app/model/storage/settings_store.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_test/flutter_test.dart';
 
+import '../../model/export_import/record_formatter_test.dart';
 import 'util.dart';
 
 void main() {
@@ -52,8 +53,7 @@ void main() {
     });
     testWidgets('should not display null values', (widgetTester) async {
       await widgetTester.pumpWidget(materialApp(MeasurementListRow(
-          settings: Settings(),
-          record: BloodPressureRecord(DateTime(2023), null, null, null, ''))));
+        settings: Settings(), record: mockRecord(time: DateTime(2023)))));
       expect(find.text('null'), findsNothing);
       expect(find.byIcon(Icons.expand_more), findsOneWidget);
       await widgetTester.tap(find.byIcon(Icons.expand_more));
test/ui/components/util.dart
@@ -1,5 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
 
 Widget materialApp(Widget child) {
   return MaterialApp(
@@ -7,4 +9,21 @@ Widget materialApp(Widget child) {
     locale: const Locale('en'),
     home: Scaffold(body:child),
   );
+}
+
+/// Open a dialoge through a button press.
+///
+/// Example usage:
+/// ```dart
+/// dynamic returnedValue = false;
+/// await loadDialoge(widgetTester, (context) async => returnedValue =
+///    await showAddExportColumnDialoge(context, Settings(),
+///      UserColumn('initialInternalIdentifier', 'csvTitle', 'formatPattern')
+/// ));
+/// ```
+Future<void> loadDialoge(WidgetTester tester, void Function(BuildContext context) dialogeStarter, { String dialogeStarterText = 'X' }) async {
+  await tester.pumpWidget(materialApp(Builder(builder: (context) =>
+      TextButton(onPressed: () => dialogeStarter(context), child: Text(dialogeStarterText)))));
+  await tester.tap(find.text(dialogeStarterText));
+  await tester.pumpAndSettle();
 }
\ No newline at end of file