@@ -33,13 +33,22 @@ void main () {
33
33
34
34
late PerAccountStore store;
35
35
late FakeApiConnection connection;
36
+
37
+ late Route <dynamic >? topRoute;
38
+ late Route <dynamic >? previousTopRoute;
36
39
late List <Route <dynamic >> pushedRoutes;
37
40
38
41
final testNavObserver = TestNavigatorObserver ()
39
- ..onPushed = (route, prevRoute) => pushedRoutes.add (route);
42
+ ..onChangedTop = ((current, previous) {
43
+ topRoute = current;
44
+ previousTopRoute = previous;
45
+ })
46
+ ..onPushed = ((route, prevRoute) => pushedRoutes.add (route));
40
47
41
48
Future <void > prepare (WidgetTester tester) async {
42
49
addTearDown (testBinding.reset);
50
+ topRoute = null ;
51
+ previousTopRoute = null ;
43
52
pushedRoutes = [];
44
53
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
45
54
store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
@@ -142,10 +151,20 @@ void main () {
142
151
final channelsMenuIconFinder = find.byIcon (ZulipIcons .hash_italic);
143
152
final combinedFeedMenuIconFinder = find.byIcon (ZulipIcons .message_feed);
144
153
145
- Future <void > tapOpenMenu (WidgetTester tester) async {
154
+ Future <void > tapOpenMenuAndAwait (WidgetTester tester) async {
155
+ final topRouteBeforePress = topRoute;
146
156
await tester.tap (find.byIcon (ZulipIcons .menu));
147
- await tester.pump (Duration .zero); // tap the button
148
- await tester.pump (const Duration (milliseconds: 250 )); // wait for animation
157
+ await tester.pump ();
158
+ final topRouteAfterPress = topRoute;
159
+ check (topRouteAfterPress).isA <ModalBottomSheetRoute <void >>();
160
+ await tester.pump ((topRouteAfterPress as ModalBottomSheetRoute <void >).transitionDuration);
161
+
162
+ // This was the only change during the interaction.
163
+ check (topRouteBeforePress).identicalTo (previousTopRoute);
164
+
165
+ // We got to the sheet by pushing, not popping or something else.
166
+ check (pushedRoutes.last).identicalTo (topRouteAfterPress);
167
+
149
168
check (find.byType (BottomSheet )).findsOne ();
150
169
}
151
170
@@ -168,7 +187,7 @@ void main () {
168
187
testWidgets ('navigation states reflect on navigation bar menu buttons' , (tester) async {
169
188
await prepare (tester);
170
189
171
- await tapOpenMenu (tester);
190
+ await tapOpenMenuAndAwait (tester);
172
191
checkIconSelected (tester, inboxMenuIconFinder);
173
192
checkIconNotSelected (tester, channelsMenuIconFinder);
174
193
await tester.tap (find.text ('Cancel' ));
@@ -178,15 +197,15 @@ void main () {
178
197
await tester.tap (find.byIcon (ZulipIcons .hash_italic));
179
198
await tester.pump ();
180
199
181
- await tapOpenMenu (tester);
200
+ await tapOpenMenuAndAwait (tester);
182
201
checkIconNotSelected (tester, inboxMenuIconFinder);
183
202
checkIconSelected (tester, channelsMenuIconFinder);
184
203
});
185
204
186
205
testWidgets ('navigation bar menu buttons control navigation states' , (tester) async {
187
206
await prepare (tester);
188
207
189
- await tapOpenMenu (tester);
208
+ await tapOpenMenuAndAwait (tester);
190
209
checkIconSelected (tester, inboxMenuIconFinder);
191
210
checkIconNotSelected (tester, channelsMenuIconFinder);
192
211
check (find.byType (InboxPageBody )).findsOne ();
@@ -201,14 +220,14 @@ void main () {
201
220
check (find.byType (InboxPageBody )).findsNothing ();
202
221
check (find.byType (SubscriptionListPageBody )).findsOne ();
203
222
204
- await tapOpenMenu (tester);
223
+ await tapOpenMenuAndAwait (tester);
205
224
checkIconNotSelected (tester, inboxMenuIconFinder);
206
225
checkIconSelected (tester, channelsMenuIconFinder);
207
226
});
208
227
209
228
testWidgets ('navigation bar menu buttons dismiss the menu' , (tester) async {
210
229
await prepare (tester);
211
- await tapOpenMenu (tester);
230
+ await tapOpenMenuAndAwait (tester);
212
231
213
232
await tester.tap (find.descendant (
214
233
of: find.byType (BottomSheet ),
@@ -220,7 +239,7 @@ void main () {
220
239
221
240
testWidgets ('cancel button dismisses the menu' , (tester) async {
222
241
await prepare (tester);
223
- await tapOpenMenu (tester);
242
+ await tapOpenMenuAndAwait (tester);
224
243
225
244
await tester.tap (find.text ('Cancel' ));
226
245
await tester.pump (Duration .zero); // tap the button
@@ -230,14 +249,17 @@ void main () {
230
249
231
250
testWidgets ('menu buttons dismiss the menu' , (tester) async {
232
251
addTearDown (testBinding.reset);
252
+ topRoute = null ;
253
+ previousTopRoute = null ;
254
+ pushedRoutes = [];
233
255
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
234
256
235
- await tester.pumpWidget (const ZulipApp ());
257
+ await tester.pumpWidget (ZulipApp (navigatorObservers : [testNavObserver] ));
236
258
final store = await testBinding.globalStore.perAccount (eg.selfAccount.id);
237
259
final connection = store.connection as FakeApiConnection ;
238
260
await tester.pump ();
239
261
240
- await tapOpenMenu (tester);
262
+ await tapOpenMenuAndAwait (tester);
241
263
242
264
connection.prepare (json: eg.newestGetMessagesResult (
243
265
foundOldest: true , messages: [eg.streamMessage ()]).toJson ());
@@ -255,7 +277,7 @@ void main () {
255
277
256
278
testWidgets ('_MyProfileButton' , (tester) async {
257
279
await prepare (tester);
258
- await tapOpenMenu (tester);
280
+ await tapOpenMenuAndAwait (tester);
259
281
260
282
await tester.tap (find.text ('My profile' ));
261
283
await tester.pump (Duration .zero); // tap the button
@@ -266,7 +288,7 @@ void main () {
266
288
267
289
testWidgets ('_AboutZulipButton' , (tester) async {
268
290
await prepare (tester);
269
- await tapOpenMenu (tester);
291
+ await tapOpenMenuAndAwait (tester);
270
292
271
293
await tester.tap (find.byIcon (ZulipIcons .info));
272
294
await tester.pump (Duration .zero); // tap the button
0 commit comments