main
1
2import 'package:blood_pressure_app/features/bluetooth/logic/characteristics/ble_measurement_data.dart';
3import 'package:blood_pressure_app/features/bluetooth/logic/characteristics/ble_measurement_status.dart';
4import 'package:blood_pressure_app/features/bluetooth/ui/measurement_success.dart';
5import 'package:flutter/material.dart';
6import 'package:blood_pressure_app/l10n/app_localizations.dart';
7import 'package:flutter_test/flutter_test.dart';
8
9import '../../../util.dart';
10
11
12void main() {
13 testWidgets('should show everything and be interactive', (WidgetTester tester) async {
14 int tapCount = 0;
15 await tester.pumpWidget(materialApp(MeasurementSuccess(
16 onTap: () => tapCount++,
17 data: BleMeasurementData(
18 systolic: 123,
19 diastolic: 456,
20 pulse: 67,
21 meanArterialPressure: 123456,
22 isMMHG: true,
23 userID: 3,
24 status: BleMeasurementStatus(
25 bodyMovementDetected: true,
26 cuffTooLose: true,
27 irregularPulseDetected: true,
28 pulseRateInRange: true,
29 pulseRateExceedsUpperLimit: true,
30 pulseRateIsLessThenLowerLimit: true,
31 improperMeasurementPosition: true,
32 ),
33 timestamp: DateTime.now(),
34 ),
35 )));
36
37 expect(find.byIcon(Icons.done), findsOneWidget);
38 expect(find.byIcon(Icons.close), findsOneWidget);
39 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
40 expect(find.text(localizations.measurementSuccess), findsOneWidget);
41
42 expect(find.text(localizations.meanArterialPressure), findsOneWidget);
43 expect(find.text('123456'), findsOneWidget);
44
45 expect(find.text(localizations.userID), findsOneWidget);
46 expect(find.text(localizations.bodyMovementDetected), findsOneWidget);
47 expect(find.text(localizations.cuffTooLoose), findsOneWidget);
48 expect(find.text(localizations.improperMeasurementPosition), findsOneWidget);
49 expect(find.text(localizations.irregularPulseDetected), findsOneWidget);
50 expect(find.text(localizations.pulseRateExceedsUpperLimit), findsOneWidget);
51 expect(find.text(localizations.pulseRateLessThanLowerLimit), findsOneWidget);
52
53 expect(tapCount, 0);
54 await tester.tap(find.text(localizations.measurementSuccess));
55 await tester.pump();
56 expect(tapCount, 1);
57 await tester.tap(find.byIcon(Icons.close));
58 await tester.pump();
59 expect(tapCount, 2);
60 });
61 testWidgets('hides elements correctly', (WidgetTester tester) async {
62 int tapCount = 0;
63 await tester.pumpWidget(materialApp(MeasurementSuccess(
64 onTap: () => tapCount++,
65 data: BleMeasurementData(
66 systolic: 123,
67 diastolic: 456,
68 pulse: null,
69 meanArterialPressure: 123456,
70 isMMHG: true,
71 userID: null,
72 status: null,
73 timestamp: null,
74 ),
75 )));
76
77 expect(find.byIcon(Icons.done), findsOneWidget);
78 expect(find.byIcon(Icons.close), findsOneWidget);
79 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
80 expect(find.text(localizations.measurementSuccess), findsOneWidget);
81
82 expect(find.text(localizations.meanArterialPressure), findsOneWidget);
83 expect(find.text('123456'), findsOneWidget);
84
85 expect(find.text(localizations.userID), findsNothing);
86 expect(find.text(localizations.bodyMovementDetected), findsNothing);
87 expect(find.text(localizations.cuffTooLoose), findsNothing);
88 expect(find.text(localizations.improperMeasurementPosition), findsNothing);
89 expect(find.text(localizations.irregularPulseDetected), findsNothing);
90 expect(find.text(localizations.pulseRateExceedsUpperLimit), findsNothing);
91 expect(find.text(localizations.pulseRateLessThanLowerLimit), findsNothing);
92 });
93}