main
1import 'package:blood_pressure_app/features/statistics/blood_pressure_distribution.dart';
2import 'package:blood_pressure_app/features/statistics/value_distribution.dart';
3import 'package:blood_pressure_app/model/storage/settings_store.dart';
4import 'package:flutter/material.dart';
5import 'package:blood_pressure_app/l10n/app_localizations.dart';
6import 'package:flutter_test/flutter_test.dart';
7
8import '../../model/analyzer_test.dart';
9import '../../util.dart';
10
11void main() {
12 testWidgets('should show allow navigation to view all widgets', (tester) async {
13 await tester.pumpWidget(materialApp(BloodPressureDistribution(records: [])));
14
15 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
16
17 expect(find.text(localizations.sysLong), findsOneWidget);
18 expect(find.text(localizations.diaLong), findsOneWidget);
19 expect(find.text(localizations.pulLong), findsOneWidget);
20
21 expect(find.byKey(const Key('sys-dist')), findsOneWidget);
22 expect(find.byKey(const Key('dia-dist')), findsNothing);
23 expect(find.byKey(const Key('pul-dist')), findsNothing);
24
25 await tester.tap(find.text(localizations.diaLong));
26 await tester.pumpAndSettle();
27 expect(find.byKey(const Key('sys-dist')), findsNothing);
28 expect(find.byKey(const Key('dia-dist')), findsOneWidget);
29 expect(find.byKey(const Key('pul-dist')), findsNothing);
30
31 await tester.tap(find.text(localizations.pulLong));
32 await tester.pumpAndSettle();
33 expect(find.byKey(const Key('sys-dist')), findsNothing);
34 expect(find.byKey(const Key('dia-dist')), findsNothing);
35 expect(find.byKey(const Key('pul-dist')), findsOneWidget);
36 });
37 testWidgets('should report records to ValueDistribution', (tester) async {
38 await tester.pumpWidget(materialApp(
39 BloodPressureDistribution(
40 records: [
41 mockRecord(sys: 123),
42 mockRecord(dia: 123),
43 mockRecord(dia: 124),
44 mockRecord(pul: 123),
45 mockRecord(pul: 124),
46 mockRecord(pul: 125),
47 ],
48 ),
49 settings: Settings(
50 sysColor: Colors.red,
51 diaColor: Colors.green,
52 pulColor: Colors.blue,
53 ),
54 ),);
55
56 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
57
58 await tester.tap(find.text(localizations.sysLong));
59 await tester.pumpAndSettle();
60 expect(find.byType(ValueDistribution), paints
61 ..line(color: Colors.red.shade500)
62 ..line(color: Colors.white70),
63 );
64
65 await tester.tap(find.text(localizations.diaLong));
66 await tester.pumpAndSettle();
67 expect(find.byType(ValueDistribution), paints
68 ..line(color: Colors.green.shade500)
69 ..line(color: Colors.green.shade500)
70 ..line(color: Colors.white70),
71 );
72
73 await tester.tap(find.text(localizations.pulLong));
74 await tester.pumpAndSettle();
75 expect(find.byType(ValueDistribution), paints
76 ..line(color: Colors.blue.shade500)
77 ..line(color: Colors.blue.shade500)
78 ..line(color: Colors.blue.shade500)
79 ..line(color: Colors.white70),
80 );
81 });
82}