main
1
2import 'package:blood_pressure_app/app.dart';
3import 'package:blood_pressure_app/screens/home_screen.dart';
4import 'package:flutter/material.dart';
5import 'package:blood_pressure_app/l10n/app_localizations.dart';
6import 'package:flutter_test/flutter_test.dart';
7import 'package:integration_test/integration_test.dart';
8
9import 'util.dart';
10
11void main() {
12 final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
13 testWidgets('Screenshot home page', (WidgetTester tester) async {
14 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
15
16 await tester.pumpWidget(App());
17 await tester.pumpAndSettle();
18 await tester.pumpUntil(() => find.byType(AppHome).hasFound);
19
20 await tester.tap(find.text(localizations.last7Days));
21 await tester.pumpAndSettle();
22 await tester.tap(find.text(localizations.day));
23 await tester.pumpAndSettle();
24
25 await tester.enterMeasurement(sys: 119, dia: 75, pul: 65);
26 await tester.enterMeasurement(sys: 114, dia: 83, pul: 70, color: Colors.red);
27 await tester.enterMeasurement(sys: 107, dia: 73, pul: 64);
28 await tester.enterMeasurement(sys: 116, dia: 71, pul: 61, note: 'Add notes and colors!', color: Colors.lightBlue);
29 await tester.enterMeasurement(sys: 105, dia: 74, pul: 60);
30 await tester.pumpUntil(() => find.text('116').hasFound);
31
32 await tester.tap(find.text('116'));
33 await tester.pumpAndSettle();
34
35 await binding.convertFlutterSurfaceToImage();
36 await tester.pump();
37 await binding.takeScreenshot('02-example_home');
38 });
39}
40
41extension on WidgetTester {
42 Future<void> enterMeasurement({
43 int? sys,
44 int? dia,
45 int? pul,
46 String? note,
47 Color? color,
48 bool save = true,
49 }) async {
50 final localizations = await AppLocalizations.delegate.load(const Locale('en'));
51
52 await tap(find.byIcon(Icons.add));
53 await pumpAndSettle();
54 if (sys != null) await enterText(find.byType(TextFormField).at(0), '$sys');
55 if (dia != null) await enterText(find.byType(TextFormField).at(1), '$dia');
56 if (pul != null) await enterText(find.byType(TextFormField).at(2), '$pul');
57 if (note != null) await enterText(find.byType(TextFormField).at(3), '$note');
58 if (color != null) {
59 await tap(find.text(localizations.color));
60 await pumpAndSettle();
61 await tap(find.byElementPredicate(_colored(color)));
62 await pumpAndSettle();
63 }
64
65 if (save) {
66 await tap(find.text(localizations.btnSave));
67 await pumpAndSettle();
68 }
69 }
70}
71
72bool Function(Element e) _colored(Color color) => (e) =>
73 e.widget is Container &&
74 (e.widget as Container).decoration is BoxDecoration &&
75 ((e.widget as Container).decoration as BoxDecoration).color == color;