Commit b94d872
Changed files (2)
test
test/ui/components/add_measurement_dialoge_test.dart
@@ -0,0 +1,98 @@
+import 'package:blood_pressure_app/components/dialoges/add_measurement.dart';
+import 'package:blood_pressure_app/model/blood_pressure.dart';
+import 'package:blood_pressure_app/model/storage/settings_store.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ group('AddMeasurementDialoge', () {
+ testWidgets('should show everything on initial page', (widgetTester) async {
+ await widgetTester.pumpWidget(_materialApp(
+ AddMeasurementDialoge(
+ settings: Settings(),
+ )
+ ));
+ expect(find.text('SAVE'), findsOneWidget);
+ expect(find.byIcon(Icons.close), findsOneWidget);
+ expect(find.text('Systolic'), findsAny);
+ expect(find.text('Diastolic'), findsAny);
+ expect(find.text('Pulse'), findsAny);
+ });
+ testWidgets('should prefill initialRecord values', (widgetTester) async {
+ await widgetTester.pumpWidget(_materialApp(
+ AddMeasurementDialoge(
+ settings: Settings(),
+ initialRecord: BloodPressureRecord(
+ DateTime.now(), 123, 56, 43, 'Test note',
+ needlePin: const MeasurementNeedlePin(Colors.teal)
+ ),
+ )
+ ));
+ await widgetTester.pumpAndSettle();
+ expect(find.text('SAVE'), findsOneWidget);
+ expect(find.byIcon(Icons.close), findsOneWidget);
+ expect(find.text('Test note'), findsOneWidget);
+ expect(find.text('123'), findsOneWidget);
+ expect(find.text('56'), findsOneWidget);
+ expect(find.text('43'), findsOneWidget);
+ });
+ });
+ 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();
+
+ expect(find.byType(AddMeasurementDialoge), findsOneWidget);
+ await widgetTester.tap(find.byIcon(Icons.close));
+ await widgetTester.pumpAndSettle();
+ expect(find.byType(AddMeasurementDialoge), findsNothing);
+
+ expect(result, null);
+ });
+ 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();
+
+ expect(find.byType(AddMeasurementDialoge), findsOneWidget);
+ await widgetTester.tap(find.text('SAVE'));
+ await widgetTester.pumpAndSettle();
+ expect(find.byType(AddMeasurementDialoge), findsNothing);
+
+ expect(result, isA<BloodPressureRecord>().having(
+ (p0) => (p0.creationTime, p0.systolic, p0.diastolic, p0.pulse, p0.notes, p0.needlePin!.color),
+ 'should return initial values as they were not modified',
+ (record.creationTime, record.systolic, record.diastolic, record.pulse, record.notes, record.needlePin!.color)));
+ });
+ });
+}
+
+Widget _materialApp(Widget child) {
+ return MaterialApp(
+ localizationsDelegates: const [AppLocalizations.delegate,],
+ locale: const Locale('en'),
+ home: Scaffold(body:child),
+ );
+}
\ No newline at end of file
test/ui/add_measurement_test.dart
@@ -1,169 +0,0 @@
-import 'package:blood_pressure_app/model/blood_pressure.dart';
-import 'package:blood_pressure_app/model/ram_only_implementations.dart';
-import 'package:blood_pressure_app/model/storage/export_csv_settings_store.dart';
-import 'package:blood_pressure_app/model/storage/export_pdf_settings_store.dart';
-import 'package:blood_pressure_app/model/storage/export_settings_store.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/add_measurement.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter_gen/gen_l10n/app_localizations.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:provider/provider.dart';
-
-void main() {
- group("Add measurements page", () {
- group('normal mode', () {
- testWidgets('smoke test', (tester) async {
- await _initPage(tester, const AddMeasurementPage());
- expect(find.text('Systolic'), findsOneWidget);
- expect(find.text('SAVE'), findsOneWidget);
- });
- testWidgets('should start empty', (tester) async {
- await _initPage(tester, const AddMeasurementPage());
- final sysInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtSys')), matching: find.byType(TextFormField)));
- expect(sysInput.initialValue, '');
- final diaInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtDia')), matching: find.byType(TextFormField)));
- expect(diaInput.initialValue, '');
- final pulInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtPul')), matching: find.byType(TextFormField)));
- expect(pulInput.initialValue, '');
- final noteInput = tester.widget<TextFormField>(find.byKey(const Key('txtNote')));
- expect(noteInput.initialValue, '');
- });
- testWidgets('should not save on cancel', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- final model = RamBloodPressureModel.fromEntries([record]);
- await _initPage(tester, const AddMeasurementPage(), model: model);
- expect((await model.all).length, 1);
-
- expect(find.byKey(const Key ('txtNote')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtNote')), 'edited text');
-
- expect(find.byKey(const Key('btnCancel')), findsOneWidget);
- await tester.tap(find.byKey(const Key('btnCancel')));
- await tester.pumpAndSettle();
- expect((await model.all).length, 1);
- });
- testWidgets('should save changes', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- final model = RamBloodPressureModel.fromEntries([record]);
- await _initPage(tester, const AddMeasurementPage(), model: model);
- expect((await model.all).first, record);
-
- expect(find.byKey(const Key ('txtSys')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtSys')), '120');
- expect(find.byKey(const Key ('txtDia')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtDia')), '70');
- expect(find.byKey(const Key ('txtPul')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtPul')), '60');
- expect(find.byKey(const Key ('txtNote')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtNote')), 'entered text');
-
- expect(find.byKey(const Key('btnSave')), findsOneWidget);
- await tester.tap(find.byKey(const Key('btnSave')));
- await tester.pumpAndSettle();
- expect((await model.all).length, 2);
- expect((await model.all)[1].notes, 'entered text');
- expect((await model.all)[1].diastolic, 70);
- });
- });
- group('edit mode', () {
- testWidgets('smoke test', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- await _initPage(tester, AddMeasurementPage.edit(record),
- model: RamBloodPressureModel.fromEntries([record])
- );
- expect(find.text('Systolic'), findsOneWidget);
- expect(find.text('SAVE'), findsOneWidget);
- });
- testWidgets('should prefill', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- await _initPage(tester, AddMeasurementPage.edit(record),
- model: RamBloodPressureModel.fromEntries([record])
- );
-
- final sysInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtSys')), matching: find.byType(TextFormField)));
- expect(sysInput.initialValue, record.systolic.toString());
- final diaInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtDia')), matching: find.byType(TextFormField)));
- expect(diaInput.initialValue, record.diastolic.toString());
- final pulInput = tester.widget<TextFormField>(
- find.descendant(of: find.byKey(const Key('txtPul')), matching: find.byType(TextFormField)));
- expect(pulInput.initialValue, record.pulse.toString());
- final noteInput = tester.widget<TextFormField>(find.byKey(const Key('txtNote')));
- expect(noteInput.initialValue, record.notes);
- });
- testWidgets('should not delete on cancel', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- final model = RamBloodPressureModel.fromEntries([record]);
- await _initPage(tester, AddMeasurementPage.edit(record), model: model);
- expect((await model.all).first, record);
-
- expect(find.byKey(const Key ('txtNote')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtNote')), 'edited text');
-
- expect(find.byKey(const Key('btnCancel')), findsOneWidget);
- await tester.tap(find.byKey(const Key('btnCancel')));
- await tester.pumpAndSettle();
- expect((await model.all).first.notes, 'simple test note');
- expect((await model.all).first, record);
- });
- testWidgets('should save changes', (tester) async {
- final record = BloodPressureRecord(DateTime.now(), 123, 89, 56, 'simple test note');
- final model = RamBloodPressureModel.fromEntries([record]);
- await _initPage(tester, AddMeasurementPage.edit(record), model: model);
- expect((await model.all).first, record);
-
- expect(find.byKey(const Key ('txtNote')), findsOneWidget);
- await tester.enterText(find.byKey(const Key ('txtNote')), 'edited text');
-
- expect(find.byKey(const Key('btnSave')), findsOneWidget);
- await tester.tap(find.byKey(const Key('btnSave')));
- await tester.pumpAndSettle();
- expect((await model.all).first.notes, 'edited text');
- });
- });
- });
-}
-
-Future<void> _initPage(WidgetTester widgetTester, Widget pageWidget, {
- Settings? settings,
- ExportSettings? exportSettings,
- CsvExportSettings? csvExportSettings,
- PdfExportSettings? pdfExportSettings,
- IntervallStoreManager? intervallStoreManager,
- BloodPressureModel? model,
-}) async {
- model ??= RamBloodPressureModel();
- settings ??= Settings();
- exportSettings ??= ExportSettings();
- csvExportSettings ??= CsvExportSettings();
- pdfExportSettings ??= PdfExportSettings();
- intervallStoreManager ??= IntervallStoreManager(IntervallStorage(), IntervallStorage(), IntervallStorage());
- await widgetTester.pumpWidget(
- MaterialApp(
- home: MultiProvider(
- providers: [
- ChangeNotifierProvider(create: (_) => settings),
- ChangeNotifierProvider(create: (_) => exportSettings),
- ChangeNotifierProvider(create: (_) => csvExportSettings),
- ChangeNotifierProvider(create: (_) => pdfExportSettings),
- ChangeNotifierProvider(create: (_) => intervallStoreManager),
- ChangeNotifierProvider<BloodPressureModel>(create: (_) => model!),
- ],
- child: Localizations(
- delegates: AppLocalizations.localizationsDelegates,
- locale: const Locale('en'),
- child: pageWidget,
- )
- )
- ),
- );
-
- await widgetTester.pumpAndSettle();
-}
-