main
1
2
3import 'package:blood_pressure_app/components/custom_banner.dart';
4import 'package:flutter/material.dart';
5import 'package:flutter_test/flutter_test.dart';
6
7import '../util.dart';
8
9void main() {
10 testWidgets('should show information and allow interaction', (tester) async {
11 int callCount = 0;
12 await tester.pumpWidget(materialApp(CustomBanner(
13 content: const Text('custom banner text'),
14 action: IconButton(
15 icon: const Icon(Icons.add_circle_outline),
16 onPressed: () {
17 callCount++;
18 },
19 ),
20 ),),);
21 expect(find.text('custom banner text'), findsOneWidget);
22 expect(find.byIcon(Icons.add_circle_outline), findsOneWidget);
23
24 expect(callCount, 0);
25 await tester.tap(find.byIcon(Icons.add_circle_outline));
26 await tester.pumpAndSettle();
27 expect(callCount, 1);
28 });
29 testWidgets('should work after launched as MaterialBanner', (tester) async {
30 int callCount = 0;
31 await tester.pumpWidget(materialApp(Builder(
32 builder: (context) => IconButton(
33 icon: const Icon(Icons.start),
34 onPressed: () {
35 ScaffoldMessenger.of(context).showMaterialBanner(
36 CustomBanner(
37 content: const Text('custom banner text'),
38 action: IconButton(
39 icon: const Icon(Icons.add_circle_outline),
40 onPressed: () {
41 callCount++;
42 },
43 ),
44 ),
45 );
46 },
47 ),
48 ),),);
49 expect(find.byType(CustomBanner), findsNothing);
50 expect(find.byIcon(Icons.start), findsOneWidget);
51 await tester.tap(find.byIcon(Icons.start));
52 await tester.pumpAndSettle();
53 expect(find.byType(CustomBanner), findsOneWidget);
54
55 expect(find.text('custom banner text'), findsOneWidget);
56 expect(find.byIcon(Icons.add_circle_outline), findsOneWidget);
57
58 expect(callCount, 0);
59 await tester.tap(find.byIcon(Icons.add_circle_outline));
60 await tester.pumpAndSettle();
61 expect(callCount, 1);
62 });
63}