main
 1import 'package:blood_pressure_app/components/fullscreen_dialoge.dart';
 2import 'package:flutter/material.dart';
 3import 'package:flutter_test/flutter_test.dart';
 4
 5import '../util.dart';
 6
 7void main() {
 8  testWidgets('shows passed body and bar', (tester) async {
 9    await tester.pumpWidget(materialApp(const FullscreenDialoge(
10      actionButtonText: 'BTN',
11      closeIcon: Icons.access_time,
12      actions: [Text('ACTION')],
13      body: Text('BODY'),
14      bottomAppBar: false,
15    )));
16    expect(find.text('BTN'), findsOneWidget);
17    expect(find.text('BODY'), findsOneWidget);
18    expect(find.text('ACTION'), findsOneWidget);
19    expect(find.byIcon(Icons.access_time), findsOneWidget);
20    expect(find.byIcon(Icons.close), findsNothing);
21  });
22  testWidgets('close button pops scope', (tester) async {
23    int popInvokedCount = 0;
24    await tester.pumpWidget(materialApp(PopScope(
25      onPopInvoked: (_) => popInvokedCount++,
26      child: const FullscreenDialoge(
27        closeIcon: Icons.add,
28        bottomAppBar: false,
29        actionButtonText: null,
30      ),
31    )));
32
33    expect(popInvokedCount, 0);
34    await tester.tap(find.byIcon(Icons.add));
35    expect(popInvokedCount, 1);
36  });
37  testWidgets('action button callback works', (tester) async {
38    int actionCallbackCount = 0;
39    await tester.pumpWidget(materialApp(FullscreenDialoge(
40      actionButtonText: 'BTN',
41      onActionButtonPressed: () => actionCallbackCount++,
42      bottomAppBar: false,
43    )));
44
45    expect(actionCallbackCount, 0);
46    await tester.tap(find.text('BTN'));
47    expect(actionCallbackCount, 1);
48    await tester.tap(find.text('BTN'));
49    expect(actionCallbackCount, 2);
50  });
51  testWidgets('app bar is positioned according to bottomAppBar', (tester) async {
52    await tester.pumpWidget(materialApp(const FullscreenDialoge(
53      closeIcon: Icons.add,
54      bottomAppBar: false,
55      actionButtonText: null,
56    )));
57    expect(find.byType(BottomAppBar), findsNothing);
58    expect(tester.getTopLeft(find.byType(AppBar)), tester.getTopLeft(find.byType(FullscreenDialoge)));
59    final double topAppBarYPos = tester.getTopLeft(find.byType(AppBar)).dy;
60
61    await tester.pumpWidget(materialApp(const FullscreenDialoge(
62      closeIcon: Icons.add,
63      bottomAppBar: true,
64      actionButtonText: null,
65    )));
66    expect(tester.getBottomRight(find.byType(BottomAppBar)), tester.getBottomRight(find.byType(FullscreenDialoge)));
67    
68    expect(tester.getTopLeft(find.byType(AppBar)).dy, greaterThan(topAppBarYPos));
69  });
70  testWidgets('bottomAppBar adds 4 units of padding to the top', (tester) async {
71    await tester.pumpWidget(materialApp(const FullscreenDialoge(
72      closeIcon: Icons.add,
73      bottomAppBar: false,
74      actionButtonText: null,
75      body: Text('A'),
76    )));
77    final double bodyStart = tester.getTopLeft(find.text('A')).dy - tester.getBottomRight(find.byType(AppBar)).dy;
78
79    await tester.pumpWidget(materialApp(const FullscreenDialoge(
80      closeIcon: Icons.add,
81      bottomAppBar: true,
82      actionButtonText: null,
83      body: Text('A'),
84    )));
85
86    expect(tester.getTopLeft(find.text('A')).dy, greaterThan(bodyStart));
87    expect(tester.getTopLeft(find.text('A')).dy, bodyStart + 4.0);
88  });
89}