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 input dialoge', (WidgetTester tester) async {
 14    final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 15    const double settingsScrollAmount = 200.0;
 16
 17    await tester.pumpWidget(App());
 18    await tester.pumpAndSettle();
 19    await tester.pumpUntil(() => find.byType(AppHome).hasFound);
 20    // home
 21
 22    await tester.tap(find.byIcon(Icons.settings));
 23    await tester.pumpAndSettle();
 24    // settings
 25
 26    await tester.scrollUntilVisible(find.text(localizations.medications), settingsScrollAmount);
 27    await tester.tap(find.text(localizations.medications));
 28    await tester.pumpAndSettle();
 29    // medication manager
 30    await tester.tap(find.text(localizations.addMedication));
 31    await tester.pumpAndSettle();
 32    // add medication
 33    await tester.enterText(find.byType(TextFormField).at(0), 'Metolazone');
 34    await tester.pumpAndSettle();
 35    await tester.tap(find.text(localizations.color));
 36    await tester.pumpAndSettle();
 37    await tester.tap(find.byElementPredicate(_colored(Colors.teal)));
 38    await tester.pumpAndSettle();
 39
 40    await tester.tap(find.text(localizations.btnSave));
 41    await tester.pumpAndSettle();
 42    // medication manager
 43    await tester.tap(find.byIcon(Icons.arrow_back));
 44    await tester.pumpAndSettle();
 45    // settings
 46    await tester.tap(find.byIcon(Icons.arrow_back));
 47    await tester.pumpAndSettle();
 48    // home
 49
 50    await tester.enterMeasurement(sys: 119, dia: 75, pul: 65,
 51      note: 'Enter measurements faster than anywhere else!',
 52      color: Colors.yellow,
 53      save: false,
 54    );
 55    await tester.tap(find.text(localizations.noMedication));
 56    await tester.pumpAndSettle();
 57    await tester.tap(find.text('Metolazone'));
 58    await tester.pumpAndSettle();
 59    await tester.enterText(find.byType(TextFormField).at(4), '1.5');
 60
 61    await tester.pumpAndSettle();
 62    await binding.convertFlutterSurfaceToImage();
 63    await tester.pump();
 64    await binding.takeScreenshot('01-example_add');
 65  });
 66}
 67
 68extension on WidgetTester {
 69  Future<void> enterMeasurement({
 70    int? sys,
 71    int? dia,
 72    int? pul,
 73    String? note,
 74    Color? color,
 75    bool save = true,
 76  }) async {
 77    final localizations = await AppLocalizations.delegate.load(const Locale('en'));
 78
 79    await tap(find.byIcon(Icons.add));
 80    await pumpAndSettle();
 81    if (sys != null) await enterText(find.byType(TextFormField).at(0), '$sys');
 82    if (dia != null) await enterText(find.byType(TextFormField).at(1), '$dia');
 83    if (pul != null) await enterText(find.byType(TextFormField).at(2), '$pul');
 84    if (note != null) await enterText(find.byType(TextFormField).at(3), '$note');
 85    if (color != null) {
 86      await tap(find.text(localizations.color));
 87      await pumpAndSettle();
 88      await tap(find.byElementPredicate(_colored(color)));
 89      await pumpAndSettle();
 90    }
 91
 92    if (save) {
 93      await tap(find.text(localizations.btnSave));
 94      await pumpAndSettle();
 95    }
 96  }
 97}
 98
 99bool Function(Element e) _colored(Color color) => (e) =>
100  e.widget is Container &&
101    (e.widget as Container).decoration is BoxDecoration &&
102      ((e.widget as Container).decoration as BoxDecoration).color == color;