5
5
// gestures. You can also use WidgetTester to find child widgets in the widget
6
6
// tree, read text, and verify that the values of widget properties are correct.
7
7
8
+ import 'package:app/cupertino.dart' ;
8
9
import 'package:app/material.dart' ;
9
10
import 'package:flutter/material.dart' ;
10
11
import 'package:flutter_test/flutter_test.dart' ;
@@ -35,7 +36,7 @@ void main() {
35
36
expect (find.byKey (cupertinoPageKey), findsNothing);
36
37
37
38
// TEST DATE BUTTON ONLY -----------
38
- final dateButton = find.byKey (dateButtonKey );
39
+ final dateButton = find.byKey (materialDateButtonKey );
39
40
40
41
// Tap on `Cupertino` key and page should change
41
42
await tester.tap (dateButton);
@@ -49,7 +50,7 @@ void main() {
49
50
expect (find.byKey (materialPageKey), findsOneWidget);
50
51
51
52
// TEST TIME BUTTON ONLY -----------
52
- final timeButton = find.byKey (timeButtonKey );
53
+ final timeButton = find.byKey (materialTimeButtonKey );
53
54
54
55
// Tap on `Cupertino` key and page should change
55
56
await tester.tap (timeButton);
@@ -63,7 +64,7 @@ void main() {
63
64
expect (find.byKey (materialPageKey), findsOneWidget);
64
65
65
66
// TEST DATE AND TIME BUTTON -----------
66
- final dateTimeButton = find.byKey (dateTimeButtonKey );
67
+ final dateTimeButton = find.byKey (materialDateTimeButtonKey );
67
68
68
69
// Tap on `Cupertino` key and page should change
69
70
await tester.tap (dateTimeButton);
@@ -80,4 +81,70 @@ void main() {
80
81
// Should show page again
81
82
expect (find.byKey (materialPageKey), findsOneWidget);
82
83
});
84
+
85
+ testWidgets ('Test Cupertino page pickers' , (WidgetTester tester) async {
86
+ // Build our app and trigger a frame.
87
+ await tester.pumpWidget (const App ());
88
+
89
+ expect (find.byKey (materialPageKey), findsOneWidget);
90
+ expect (find.byKey (cupertinoPageKey), findsNothing);
91
+
92
+ // Tap on `Cupertino` key and page should change
93
+ await tester.tap (find.byKey (cupertinoButtonKey));
94
+ await tester.pumpAndSettle ();
95
+
96
+ // TEST DATE BUTTON ONLY -----------
97
+ final dateButton = find.byKey (cupertinoDateButtonKey);
98
+
99
+ // Tap on `Cupertino` key and page should change
100
+ await tester.tap (dateButton);
101
+ await tester.pumpAndSettle ();
102
+
103
+ // Tap on Sat 29th and drag
104
+ await tester.drag (find.text (" Sat 29 " ), const Offset (0.0 , - 32.0 ), touchSlopY: 0.0 , warnIfMissed: false );
105
+ await tester.pumpAndSettle ();
106
+
107
+ // Tap outside the picker
108
+ await tester.tapAt (const Offset (0 , 0 ));
109
+ await tester.pumpAndSettle ();
110
+
111
+ // Should show page again
112
+ expect (find.byKey (cupertinoPageKey), findsOneWidget);
113
+
114
+ // TEST TIME BUTTON ONLY -----------
115
+ final timeButton = find.byKey (cupertinoTimeButtonKey);
116
+
117
+ // Tap on `Cupertino` key and page should change
118
+ await tester.tap (timeButton);
119
+ await tester.pumpAndSettle ();
120
+
121
+ // Tap on Sat 29th and drag
122
+ await tester.drag (find.text ("01" ), const Offset (0.0 , - 32.0 ), touchSlopY: 0.0 , warnIfMissed: false );
123
+ await tester.pumpAndSettle ();
124
+
125
+ // Tap outside the picker
126
+ await tester.tapAt (const Offset (0 , 0 ));
127
+ await tester.pumpAndSettle ();
128
+
129
+ // Should show page again
130
+ expect (find.byKey (cupertinoPageKey), findsOneWidget);
131
+
132
+ // TEST DATE AND TIME BUTTON -----------
133
+ final dateTimeButton = find.byKey (cupertinoDateTimeButtonKey);
134
+
135
+ // Tap on `Cupertino` key and page should change
136
+ await tester.tap (dateTimeButton);
137
+ await tester.pumpAndSettle ();
138
+
139
+ // Tap on Sat 29th and drag
140
+ await tester.drag (find.text ("01" ), const Offset (0.0 , - 32.0 ), touchSlopY: 0.0 , warnIfMissed: false );
141
+ await tester.pumpAndSettle ();
142
+
143
+ // Tap outside the picker
144
+ await tester.tapAt (const Offset (0 , 0 ));
145
+ await tester.pumpAndSettle ();
146
+
147
+ // Should show page again
148
+ expect (find.byKey (cupertinoPageKey), findsOneWidget);
149
+ });
83
150
}
0 commit comments