Commit e1461f7
Changed files (2)
lib
components
dialoges
test
ui
components
lib/components/dialoges/add_measurement_dialoge.dart
@@ -301,9 +301,12 @@ class _AddEntryDialogeState extends State<AddEntryDialoge> {
child: Row(
children: [
Expanded(
- child: ListTile(
- shape: buildListTileBorder(),
- title: DropdownButton(
+ child: Ink(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4),
+ decoration: ShapeDecoration(
+ shape: buildListTileBorder()
+ ),
+ child: DropdownButton(
isExpanded: true,
value: widget.settings.medications
.where((e) => e.id == medicineId).firstOrNull,
test/ui/components/add_measurement_dialoge_test.dart
@@ -1,5 +1,7 @@
import 'package:blood_pressure_app/components/dialoges/add_measurement_dialoge.dart';
import 'package:blood_pressure_app/components/settings/color_picker_list_tile.dart';
+import 'package:blood_pressure_app/model/blood_pressure/medicine/medicine.dart';
+import 'package:blood_pressure_app/model/blood_pressure/medicine/medicine_intake.dart';
import 'package:blood_pressure_app/model/blood_pressure/needle_pin.dart';
import 'package:blood_pressure_app/model/blood_pressure/record.dart';
import 'package:blood_pressure_app/model/storage/settings_store.dart';
@@ -9,6 +11,7 @@ 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 '../../model/medicine/medicine_test.dart';
import 'settings/color_picker_list_tile_test.dart';
import 'util.dart';
@@ -21,6 +24,8 @@ void main() {
)
));
expect(widgetTester.takeException(), isNull);
+
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
expect(find.text('SAVE'), findsOneWidget);
expect(find.byIcon(Icons.close), findsOneWidget);
expect(find.text('Systolic'), findsWidgets);
@@ -39,6 +44,7 @@ void main() {
)
));
await widgetTester.pumpAndSettle();
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
expect(find.text('SAVE'), findsOneWidget);
expect(find.byIcon(Icons.close), findsOneWidget);
expect(find.text('Test note'), findsOneWidget);
@@ -49,6 +55,75 @@ void main() {
expect(find.byType(ColorSelectionListTile).evaluate().first.widget, isA<ColorSelectionListTile>().
having((p0) => p0.initialColor, 'ColorSelectionListTile should have correct initial color', Colors.teal));
});
+ testWidgets('should show medication picker when medications available', (widgetTester) async {
+ await widgetTester.pumpWidget(materialApp(
+ AddEntryDialoge(
+ settings: Settings(
+ medications: [mockMedicine(designation: 'testmed')]
+ ),
+ )
+ ));
+ await widgetTester.pumpAndSettle();
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ expect(find.byType(DropdownButton<Medicine?>), findsOneWidget);
+ expect(find.text(localizations.noMedication), findsOneWidget);
+ expect(find.text('testmed'), findsNothing);
+
+ await widgetTester.tap(find.byType(DropdownButton<Medicine?>));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.text('testmed'), findsOneWidget);
+ });
+ testWidgets('should reveal dosis on medication selection', (widgetTester) async {
+ await widgetTester.pumpWidget(materialApp(
+ AddEntryDialoge(
+ settings: Settings(
+ medications: [mockMedicine(designation: 'testmed')]
+ ),
+ )
+ ));
+ await widgetTester.pumpAndSettle();
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ expect(find.byType(DropdownButton<Medicine?>), findsOneWidget);
+ expect(find.text(localizations.noMedication), findsOneWidget);
+ expect(find.text('testmed'), findsNothing);
+
+ await widgetTester.tap(find.byType(DropdownButton<Medicine?>));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.text(localizations.dosis), findsNothing);
+ expect(find.text('testmed'), findsOneWidget);
+ await widgetTester.tap(find.text('testmed'));
+ await widgetTester.pumpAndSettle();
+
+ expect(
+ find.ancestor(
+ of: find.text(localizations.dosis,).first,
+ matching: find.byType(TextFormField)
+ ),
+ findsOneWidget,
+ );
+ });
+ testWidgets('should enter default dosis if available', (widgetTester) async {
+ await widgetTester.pumpWidget(materialApp(
+ AddEntryDialoge(
+ settings: Settings(
+ medications: [mockMedicine(designation: 'testmed', defaultDosis: 3.1415)]
+ ),
+ )
+ ));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.tap(find.byType(DropdownButton<Medicine?>));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.tap(find.text('testmed'));
+ await widgetTester.pumpAndSettle();
+
+ expect(find.text('3.1415'), findsOneWidget);
+ });
});
group('showAddEntryDialoge', () {
testWidgets('should return null on cancel', (widgetTester) async {
@@ -56,6 +131,7 @@ void main() {
await loadDialoge(widgetTester, (context) async
=> result = await showAddEntryDialoge(context, Settings(),
mockRecord(sys: 123, dia: 56, pul: 43, note: 'Test note', pin: Colors.teal)));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
expect(find.byType(AddEntryDialoge), findsOneWidget);
await widgetTester.tap(find.byIcon(Icons.close));
@@ -69,21 +145,24 @@ void main() {
final record = mockRecord(sys: 123, dia: 56, pul: 43, note: 'Test note', pin: Colors.teal);
await loadDialoge(widgetTester, (context) async
=> result = await showAddEntryDialoge(context, Settings(), record));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
expect(find.byType(AddEntryDialoge), findsOneWidget);
await widgetTester.tap(find.text('SAVE'));
await widgetTester.pumpAndSettle();
expect(find.byType(AddEntryDialoge), findsNothing);
+ expect(result?.$2, isNull);
expect(result?.$1, 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)));
});
- testWidgets('should be able to input values', (WidgetTester widgetTester) async {
+ testWidgets('should be able to input records', (WidgetTester widgetTester) async {
dynamic result = 'not null';
await loadDialoge(widgetTester, (context) async
=> result = await showAddEntryDialoge(context, Settings()));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in 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');
@@ -99,6 +178,7 @@ void main() {
await widgetTester.tap(find.text('SAVE'));
await widgetTester.pumpAndSettle();
+ expect(result?.$2, isNull);
expect(result?.$1, isA<BloodPressureRecord>()
.having((p0) => p0.systolic, 'systolic', 123)
.having((p0) => p0.diastolic, 'diastolic', 67)
@@ -107,10 +187,53 @@ void main() {
.having((p0) => p0.needlePin?.color, 'needlePin', Colors.red)
);
});
+ testWidgets('should be able to input medicines', (WidgetTester widgetTester) async {
+ final med2 = mockMedicine(designation: 'medication2', defaultDosis: 31.415);
+
+ dynamic result = 'not null';
+ await loadDialoge(widgetTester, (context) async
+ => result = await showAddEntryDialoge(context, Settings(
+ medications: [
+ mockMedicine(designation: 'medication1'),
+ med2,
+ ]
+ )));
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ await widgetTester.tap(find.byType(DropdownButton<Medicine?>));
+ final openDialogeTimeStamp = DateTime.now();
+ await widgetTester.pumpAndSettle();
+
+ expect(find.text('medication1'), findsOneWidget);
+ expect(find.text('medication2'), findsOneWidget);
+ await widgetTester.tap(find.text('medication2'));
+ await widgetTester.pumpAndSettle();
+
+ await widgetTester.enterText(
+ find.ancestor(
+ of: find.text(localizations.dosis).first,
+ matching: find.byType(TextFormField)
+ ),
+ '123.456'
+ );
+
+ expect(find.text(localizations.btnSave), findsOneWidget);
+ await widgetTester.tap(find.text(localizations.btnSave));
+ await widgetTester.pumpAndSettle();
+
+ expect(result?.$1, isNull);
+ expect(result?.$2, isA<MedicineIntake>()
+ .having((p0) => p0.timestamp.millisecondsSinceEpoch ~/ 1000, 'timestamp', openDialogeTimeStamp.millisecondsSinceEpoch ~/ 1000)
+ .having((p0) => p0.medicine, 'medicine', med2)
+ .having((p0) => p0.dosis, 'dosis', 123.456)
+ );
+ });
testWidgets('should not allow invalid values', (widgetTester) async {
await loadDialoge(widgetTester, (context) => showAddEntryDialoge(context, Settings()));
final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
+
expect(find.byType(AddEntryDialoge), findsOneWidget);
expect(find.text(localizations.errNaN), findsNothing);
expect(find.text(localizations.errLt30), findsNothing);
@@ -171,6 +294,7 @@ void main() {
testWidgets('should allow invalid values when setting is set', (widgetTester) async {
await loadDialoge(widgetTester, (context) =>
showAddEntryDialoge(context, Settings(validateInputs: false, allowMissingValues: true)));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
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');
@@ -181,12 +305,14 @@ void main() {
testWidgets('should respect settings.allowManualTimeInput', (widgetTester) async {
await loadDialoge(widgetTester, (context) =>
showAddEntryDialoge(context, Settings(allowManualTimeInput: false)));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
expect(find.byIcon(Icons.edit), findsNothing);
});
testWidgets('should start with sys input focused', (widgetTester) async {
await loadDialoge(widgetTester, (context) =>
showAddEntryDialoge(context, Settings(), mockRecord(sys: 12)));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
final primaryFocus = FocusManager.instance.primaryFocus;
expect(primaryFocus?.context?.widget, isNotNull);
@@ -201,6 +327,7 @@ void main() {
testWidgets('should focus next on input finished', (widgetTester) async {
await loadDialoge(widgetTester, (context) =>
showAddEntryDialoge(context, Settings(), mockRecord(sys: 12, dia: 3, pul: 4, note: 'note')));
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
await widgetTester.enterText(find.ancestor(of: find.text('Systolic').first, matching: find.byType(TextFormField)), '123');
@@ -242,7 +369,7 @@ void main() {
testWidgets('should focus last input field on backspace pressed in empty input field', (widgetTester) async {
await loadDialoge(widgetTester, (context) =>
showAddEntryDialoge(context, Settings(), mockRecord(sys: 12, dia: 3, pul: 4, note: 'note')));
-
+ expect(find.byType(DropdownButton<Medicine?>), findsNothing, reason: 'No medication in settings.');
await widgetTester.enterText(find.ancestor(of: find.text('note').first, matching: find.byType(TextFormField)), '');
await widgetTester.sendKeyEvent(LogicalKeyboardKey.backspace);