|
| 1 | +// This is a basic Flutter widget test. |
| 2 | +// |
| 3 | +// To perform an interaction with a widget in your test, use the WidgetTester |
| 4 | +// utility that Flutter provides. For example, you can send tap and scroll |
| 5 | +// gestures. You can also use WidgetTester to find child widgets in the widget |
| 6 | +// tree, read text, and verify that the values of widget properties are correct. |
| 7 | + |
| 8 | +import 'package:example/app.dart'; |
| 9 | +import 'package:example/router.dart'; |
| 10 | +import 'package:flutter/material.dart'; |
| 11 | +import 'package:flutter_test/flutter_test.dart'; |
| 12 | +import 'package:provider/provider.dart'; |
| 13 | + |
| 14 | +void main() { |
| 15 | + testWidgets('OK Dialog', (tester) async { |
| 16 | + await _setupTester(tester); |
| 17 | + |
| 18 | + await tester.tap(find.widgetWithText(ListTile, 'OK Dialog')); |
| 19 | + await tester.pumpAndSettle(); |
| 20 | + |
| 21 | + expect(find.text('Title'), findsOneWidget); |
| 22 | + expect(find.text('This is message.'), findsOneWidget); |
| 23 | + await tester.tap(find.widgetWithText(FlatButton, 'OK')); |
| 24 | + await tester.pumpAndSettle(); |
| 25 | + |
| 26 | + expect(find.text('Result: OkCancelResult.ok'), findsOneWidget); |
| 27 | + }); |
| 28 | + |
| 29 | + testWidgets('OK Dialog (barrierDismissible: false)', (tester) async { |
| 30 | + await _setupTester(tester); |
| 31 | + |
| 32 | + await tester.tap( |
| 33 | + find.widgetWithText(ListTile, 'OK Dialog (barrierDismissible: false)')); |
| 34 | + await tester.pumpAndSettle(); |
| 35 | + |
| 36 | + expect(find.text('Title'), findsOneWidget); |
| 37 | + expect(find.text('This is message.'), findsOneWidget); |
| 38 | + await tester.tap(find.widgetWithText(FlatButton, 'OK')); |
| 39 | + await tester.pumpAndSettle(); |
| 40 | + |
| 41 | + expect(find.text('Result: OkCancelResult.ok'), findsOneWidget); |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +Future<void> _setupTester(WidgetTester tester) async { |
| 46 | + await tester.pumpWidget(MultiProvider( |
| 47 | + providers: [ |
| 48 | + Provider(create: (context) => Router()), |
| 49 | + ], |
| 50 | + child: const App(), |
| 51 | + )); |
| 52 | + |
| 53 | + await tester.tap(find.widgetWithText(ListTile, 'Alert')); |
| 54 | + await tester.pumpAndSettle(); |
| 55 | +} |
0 commit comments