Commit 76ba8f0
Changed files (6)
lib
components
screens
test
ui
components
statistics
lib/components/statistics/blood_pressure_distribution.dart
@@ -1,5 +1,3 @@
-// TODO: test
-
import 'package:blood_pressure_app/components/statistics/value_distribution.dart';
import 'package:blood_pressure_app/model/blood_pressure/record.dart';
import 'package:blood_pressure_app/model/storage/settings_store.dart';
@@ -92,10 +90,9 @@ class _BloodPressureDistributionState extends State<BloodPressureDistribution>
),
],
),
- )
- // TODO: content
+ ),
],
);
}
-
-}
\ No newline at end of file
+
+}
lib/components/statistics/value_distribution.dart
@@ -1,5 +1,3 @@
-// TODO: test
-
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -64,7 +62,7 @@ class ValueDistribution extends StatelessWidget {
return Container(
constraints: const BoxConstraints(
minWidth: 180,
- minHeight: 50
+ minHeight: 50,
),
child: CustomPaint(
painter: _ValueDistributionPainter(
@@ -196,7 +194,6 @@ class _ValueDistributionPainter extends CustomPainter {
=> distribution == oldDelegate.distribution;
@override
- // TODO: test semanticsBuilder
SemanticsBuilderCallback? get semanticsBuilder => (Size size) {
final oneThird = size.width / 3;
return [
@@ -242,5 +239,4 @@ class _ValueDistributionPainter extends CustomPainter {
}
return (sum / count).round().toString();
}
-// TODO: test averages
}
lib/model/blood_pressure_analyzer.dart
@@ -71,16 +71,16 @@ class BloodPressureAnalyser {
Iterable<int> get _nonNullPul => _records.map((e) => e.pulse).whereNotNull();
/// Average amount of measurements entered per day.
- int get measurementsPerDay {
+ int? get measurementsPerDay {
final c = count;
- if (c <= 1) return -1;
+ if (c <= 1) return null;
final firstDay = this.firstDay;
final lastDay = this.lastDay;
if (firstDay == null || lastDay == null) return -1;
if (firstDay.millisecondsSinceEpoch == -1 || lastDay.millisecondsSinceEpoch == -1) {
- return -1;
+ return null;
}
if (lastDay.difference(firstDay).inDays <= 0) {
return c;
lib/screens/statistics_screen.dart
@@ -46,7 +46,7 @@ class _StatisticsScreenState extends State<StatisticsScreen> {
ListTile(
title: Text(localizations.measurementsPerDay),
trailing: Text(
- analyzer.measurementsPerDay.toString(),
+ analyzer.measurementsPerDay?.toString() ?? '-',
style: Theme.of(context).textTheme.headlineSmall,
),
),
test/ui/components/statistics/blood_pressure_distribution_test.dart
@@ -79,6 +79,5 @@ void main() {
..line(color: Colors.blue.shade500)
..line(color: Colors.white70),
);
-
});
}
test/ui/statistics_test.dart
@@ -11,6 +11,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
+import '../model/export_import/record_formatter_test.dart';
import '../ram_only_implementations.dart';
void main() {
@@ -18,38 +19,59 @@ void main() {
testWidgets('should load page', (widgetTester) async {
await _initStatsPage(widgetTester, []);
expect(widgetTester.takeException(), isNull);
- expect(find.text('Statistics'), findsOneWidget);
+
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+ expect(find.text(localizations.statistics), findsAtLeast(1));
+ expect(find.text(localizations.valueDistribution), findsOneWidget);
+ expect(find.text(localizations.timeResolvedMetrics, skipOffstage: false),
+ findsOneWidget,);
});
testWidgets('should report measurement count', (widgetTester) async {
await _initStatsPage(widgetTester, [
for (int i = 1; i<51; i++) // can't safe entries at or before epoch
- BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(1582991592 + i), 40+i, 60+i, 30+i, 'Test comment $i'),
- ],
- intervallStoreManager: IntervallStoreManager(IntervallStorage(), IntervallStorage(), IntervallStorage(stepSize: TimeStep.lifetime)),
+ mockRecord(time: DateTime.fromMillisecondsSinceEpoch(1582991592 + i),
+ sys: i, dia: 60+i, pul: 110+i,),
+ ], intervallStoreManager: IntervallStoreManager(IntervallStorage(),
+ IntervallStorage(), IntervallStorage(stepSize: TimeStep.lifetime,),),);
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ expect(find.text(localizations.measurementCount), findsOneWidget);
+
+ final measurementCountWidget = find.ancestor(
+ of: find.text(localizations.measurementCount),
+ matching: find.byType(ListTile),
);
- final measurementCountWidget = find.byKey(const Key('measurementCount'));
expect(measurementCountWidget, findsOneWidget);
- expect(find.descendant(of: measurementCountWidget, matching: find.text('49')), findsNothing);
- expect(find.descendant(of: measurementCountWidget, matching: find.text('51')), findsNothing);
- expect(find.descendant(of: measurementCountWidget, matching: find.text('50')), findsOneWidget);
+ expect(find.descendant(
+ of: measurementCountWidget,
+ matching: find.text('49'),
+ ), findsNothing,);
+ expect(find.descendant(
+ of: measurementCountWidget,
+ matching: find.text('51'),
+ ), findsNothing,);
+ expect(find.descendant(
+ of: measurementCountWidget,
+ matching: find.text('50'),
+ ), findsOneWidget,);
});
- testWidgets("should not display 'null' when filled", (widgetTester) async {
+ testWidgets("should not display 'null' or -1", (widgetTester) async {
await _initStatsPage(widgetTester, [
- BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(1), 40, 60, null, ''),
- BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(2), null, null, null, ''),
- for (int i = 1; i<51; i++) // can't safe entries at or before epoch
- BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(1582991592 + i), 40+i, 60+i, 30+i, 'Test comment $i'),
- ],
- intervallStoreManager: IntervallStoreManager(IntervallStorage(), IntervallStorage(), IntervallStorage(stepSize: TimeStep.lifetime)),
- );
- expect(find.text('null',findRichText: true, skipOffstage: false), findsNothing);
+ mockRecord(time: DateTime.fromMillisecondsSinceEpoch(1), sys: 40, dia: 60),
+ mockRecord(time: DateTime.fromMillisecondsSinceEpoch(2),),
+ ], intervallStoreManager: IntervallStoreManager(IntervallStorage(),
+ IntervallStorage(), IntervallStorage(stepSize: TimeStep.lifetime),),);
+ expect(find.textContaining('-1'), findsNothing);
+ expect(find.textContaining('null'), findsNothing);
});
testWidgets("should not display 'null' when empty", (widgetTester) async {
await _initStatsPage(widgetTester, [],
- intervallStoreManager: IntervallStoreManager(IntervallStorage(), IntervallStorage(), IntervallStorage(stepSize: TimeStep.lifetime)),
- );
- expect(find.text('null',findRichText: true, skipOffstage: false), findsNothing);
+ intervallStoreManager: IntervallStoreManager(
+ IntervallStorage(), IntervallStorage(),
+ IntervallStorage(stepSize: TimeStep.lifetime,),),);
+ expect(find.textContaining('-1'), findsNothing);
+ expect(find.textContaining('null'), findsNothing);
});
});
}