/
contacts_test.dart
124 lines (98 loc) · 2.91 KB
/
contacts_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
///
import '../view.dart';
String _location = '========================== contacts_test.dart';
/// Testing the Contacts app
Future<void> contactsTest(WidgetTester tester) async {
//
// Delete the last contact entered
await _deleteContact(tester);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
// Find a list of word pairs
Finder finder = find.byType(TextFormField);
// The text form fields should be available.
expect(finder, findsWidgets, reason: _location);
for (var cnt = 0; cnt < 7; cnt++) {
//
final field = finder.at(cnt);
await tester.tap(field);
await tester.pump();
await tester.pumpAndSettle();
// await tester.showKeyboard(field);
String text = '';
switch (cnt) {
case 0:
text = 'Greg';
break;
case 1:
text = '';
break;
case 2:
text = 'Perry';
break;
case 3:
text = '647 823-3752';
break;
case 4:
text = 'greg.perry@adnrioussolutions.com';
break;
case 5:
text = 'Andrious Solutions Ltd.';
break;
case 6:
text = 'Founder';
break;
}
await tester.enterText(field, text);
}
finder = find.widgetWithIcon(TextButton, Icons.save);
expect(finder, findsOneWidget, reason: _location);
await tester.tap(finder);
await tester.pump();
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpAndSettle();
}
/// Delete a contact if any
Future<void> _deleteContact(WidgetTester tester) async {
//
final con = ContactsController();
// If there are no contacts
if (con.items == null || con.items!.isEmpty) {
return;
}
Finder finder;
if (App.useMaterial) {
//
finder = find.byType(ListTile, skipOffstage: false);
expect(finder, findsWidgets, reason: _location);
await tester.tap(finder.first);
await tester.pump();
} else {
//
finder = find.byWidgetPredicate(
(Widget widget) => widget is GestureDetector && widget.child is Row,
description: 'a CupertinoListTile widget',
skipOffstage: false);
expect(finder, findsWidgets, reason: _location);
// Retrieve the widget
final tile = tester.firstWidget<GestureDetector>(finder);
tile.onTap!();
}
await tester.pumpAndSettle();
final deleteButton = find.widgetWithIcon(
App.useMaterial ? TextButton : IconButton, Icons.delete,
skipOffstage: false);
expect(deleteButton, findsOneWidget, reason: _location);
await tester.tap(deleteButton);
await tester.pump();
await tester.pumpAndSettle();
// Find the appropriate button even if translated.
final button = find.widgetWithText(
App.useMaterial ? TextButton : CupertinoDialogAction, 'OK');
expect(button, findsOneWidget, reason: _location);
await tester.tap(button);
await tester.pump();
await tester.pumpAndSettle();
}