Commit 864f44a
Changed files (4)
lib
components
test
ui
components
lib/components/statistics/blood_pressure_distribution.dart
@@ -76,14 +76,17 @@ class _BloodPressureDistributionState extends State<BloodPressureDistribution>
controller: _controller,
children: [
ValueDistribution(
+ key: const Key('sys-dist'),
values: widget.records.map((e) => e.systolic).whereNotNull(),
color: widget.settings.sysColor,
),
ValueDistribution(
+ key: const Key('dia-dist'),
values: widget.records.map((e) => e.diastolic).whereNotNull(),
color: widget.settings.diaColor,
),
ValueDistribution(
+ key: const Key('pul-dist'),
values: widget.records.map((e) => e.pulse).whereNotNull(),
color: widget.settings.pulColor,
),
lib/components/statistics/value_distribution.dart
@@ -11,6 +11,9 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
/// labels that indicate min, max and average.
///
/// The widgets takes a width of at least 180 units and a height of at least 50.
+///
+/// First draws the graph lines, then draws the decorations in the color
+/// [Colors.white70].
class ValueDistribution extends StatelessWidget {
/// Create a statistic to show how often values occur.
const ValueDistribution({
test/ui/components/statistics/blood_pressure_distribution_test.dart
@@ -1,5 +1,84 @@
+import 'package:blood_pressure_app/components/statistics/blood_pressure_distribution.dart';
+import 'package:blood_pressure_app/components/statistics/value_distribution.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';
+import '../../../model/export_import/record_formatter_test.dart';
+import '../util.dart';
+
void main() {
- testWidgets('should ', (widgetTester) => null)
+ testWidgets('should show allow navigation to view all widgets', (widgetTester) async {
+ await widgetTester.pumpWidget(materialApp(BloodPressureDistribution(
+ records: const [],
+ settings: Settings(),
+ ),),);
+
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ expect(find.text(localizations.sysLong), findsOneWidget);
+ expect(find.text(localizations.diaLong), findsOneWidget);
+ expect(find.text(localizations.pulLong), findsOneWidget);
+
+ expect(find.byKey(const Key('sys-dist')), findsOneWidget);
+ expect(find.byKey(const Key('dia-dist')), findsNothing);
+ expect(find.byKey(const Key('pul-dist')), findsNothing);
+
+ await widgetTester.tap(find.text(localizations.diaLong));
+ await widgetTester.pumpAndSettle();
+ expect(find.byKey(const Key('sys-dist')), findsNothing);
+ expect(find.byKey(const Key('dia-dist')), findsOneWidget);
+ expect(find.byKey(const Key('pul-dist')), findsNothing);
+
+ await widgetTester.tap(find.text(localizations.pulLong));
+ await widgetTester.pumpAndSettle();
+ expect(find.byKey(const Key('sys-dist')), findsNothing);
+ expect(find.byKey(const Key('dia-dist')), findsNothing);
+ expect(find.byKey(const Key('pul-dist')), findsOneWidget);
+ });
+ testWidgets('should report records to ValueDistribution', (widgetTester) async {
+ await widgetTester.pumpWidget(materialApp(BloodPressureDistribution(
+ records: [
+ mockRecord(sys: 123),
+ mockRecord(dia: 123),
+ mockRecord(dia: 124),
+ mockRecord(pul: 123),
+ mockRecord(pul: 124),
+ mockRecord(pul: 125),
+ ],
+ settings: Settings(
+ sysColor: Colors.red,
+ diaColor: Colors.green,
+ pulColor: Colors.blue,
+ ),
+ ),),);
+
+ final localizations = await AppLocalizations.delegate.load(const Locale('en'));
+
+ await widgetTester.tap(find.text(localizations.sysLong));
+ await widgetTester.pumpAndSettle();
+ expect(find.byType(ValueDistribution), paints
+ ..line(color: Colors.red.shade500)
+ ..line(color: Colors.white70),
+ );
+
+ await widgetTester.tap(find.text(localizations.diaLong));
+ await widgetTester.pumpAndSettle();
+ expect(find.byType(ValueDistribution), paints
+ ..line(color: Colors.green.shade500)
+ ..line(color: Colors.green.shade500)
+ ..line(color: Colors.white70),
+ );
+
+ await widgetTester.tap(find.text(localizations.pulLong));
+ await widgetTester.pumpAndSettle();
+ expect(find.byType(ValueDistribution), paints
+ ..line(color: Colors.blue.shade500)
+ ..line(color: Colors.blue.shade500)
+ ..line(color: Colors.blue.shade500)
+ ..line(color: Colors.white70),
+ );
+
+ });
}
test/ui/components/statistics/value_distribution_test.dart
@@ -20,7 +20,7 @@ void main() {
final errorCenter = widgetTester.getCenter(find.byType(Text));
final canvasCenter = widgetTester.getCenter(find.byType(MaterialApp));
- expect(errorCenter, equals(canvasCenter));;
+ expect(errorCenter, equals(canvasCenter));
},);
testWidgets('should draw labels at correct positions', (widgetTester) async {