@@ -329,24 +329,38 @@ void main () {
329
329
330
330
Future <void > prepare (WidgetTester tester) async {
331
331
addTearDown (testBinding.reset);
332
+ topRoute = null ;
333
+ previousTopRoute = null ;
334
+ pushedRoutes = [];
335
+ lastPoppedRoute = null ;
332
336
await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
333
337
await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot ());
334
- await tester.pumpWidget (const ZulipApp ());
338
+ await tester.pumpWidget (ZulipApp (navigatorObservers : [testNavObserver] ));
335
339
await tester.pump (Duration .zero); // wait for the loading page
336
340
checkOnLoadingPage ();
337
341
}
338
342
339
343
Future <void > tapTryAnotherAccount (WidgetTester tester) async {
344
+ final numPushedRoutesBefore = pushedRoutes.length;
340
345
await tester.tap (find.text ('Try another account' ));
341
- await tester.pump (Duration .zero); // tap the button
342
- await tester.pump (const Duration (milliseconds: 250 )); // wait for animation
346
+ await tester.pump ();
347
+ final pushedRoute = pushedRoutes.skip (numPushedRoutesBefore).single;
348
+ check (pushedRoute).isA <MaterialWidgetRoute >().page.isA <ChooseAccountPage >();
349
+ await tester.pump ((pushedRoute as TransitionRoute ).transitionDuration);
343
350
checkOnChooseAccountPage ();
344
351
}
345
352
346
353
Future <void > chooseAccountWithEmail (WidgetTester tester, String email) async {
354
+ lastPoppedRoute = null ;
347
355
await tester.tap (find.text (email));
348
- await tester.pump (Duration .zero); // tap the button
349
- await tester.pump (const Duration (milliseconds: 350 )); // wait for push & pop animations
356
+ await tester.pump ();
357
+ check (topRoute).isA <MaterialAccountWidgetRoute >().page.isA <HomePage >();
358
+ check (lastPoppedRoute).isA <MaterialWidgetRoute >().page.isA <ChooseAccountPage >();
359
+ final popDuration = (lastPoppedRoute as TransitionRoute ).reverseTransitionDuration;
360
+ final pushDuration = (topRoute as TransitionRoute ).transitionDuration;
361
+ final animationDuration = popDuration > pushDuration ? popDuration : pushDuration;
362
+ // TODO not sure why a 1ms fudge is needed; investigate.
363
+ await tester.pump (animationDuration + Duration (milliseconds: 1 ));
350
364
checkOnLoadingPage ();
351
365
}
352
366
@@ -379,9 +393,14 @@ void main () {
379
393
await tester.pump (kTryAnotherAccountWaitPeriod);
380
394
await tapTryAnotherAccount (tester);
381
395
396
+ lastPoppedRoute = null ;
382
397
await tester.tap (find.byType (BackButton ));
383
- await tester.pump (Duration .zero); // tap the button
384
- await tester.pump (const Duration (milliseconds: 350 )); // wait for pop animation
398
+ await tester.pump ();
399
+ check (lastPoppedRoute).isA <MaterialWidgetRoute >().page.isA <ChooseAccountPage >();
400
+ await tester.pump (
401
+ (lastPoppedRoute as TransitionRoute ).reverseTransitionDuration
402
+ // TODO not sure why a 1ms fudge is needed; investigate.
403
+ + Duration (milliseconds: 1 ));
385
404
checkOnLoadingPage ();
386
405
387
406
await tester.pump (loadPerAccountDuration);
@@ -466,9 +485,14 @@ void main () {
466
485
await tester.pump (loadPerAccountDuration);
467
486
checkOnChooseAccountPage ();
468
487
488
+ lastPoppedRoute = null ;
469
489
await tester.tap (find.byType (BackButton ));
470
- await tester.pump (Duration .zero); // tap the button
471
- await tester.pump (const Duration (milliseconds: 350 )); // wait for pop animation
490
+ await tester.pump ();
491
+ check (lastPoppedRoute).isA <MaterialWidgetRoute >().page.isA <ChooseAccountPage >();
492
+ await tester.pump (
493
+ (lastPoppedRoute as TransitionRoute ).reverseTransitionDuration
494
+ // TODO not sure why a 1ms fudge is needed; investigate.
495
+ + Duration (milliseconds: 1 ));
472
496
checkOnHomePage (tester, expectedAccount: eg.selfAccount);
473
497
});
474
498
@@ -483,9 +507,14 @@ void main () {
483
507
checkOnChooseAccountPage ();
484
508
485
509
// Choosing the already loaded account should result in no loading page.
510
+ lastPoppedRoute = null ;
486
511
await tester.tap (find.text (eg.selfAccount.email));
487
- await tester.pump (Duration .zero); // tap the button
488
- await tester.pump (const Duration (milliseconds: 350 )); // wait for push & pop animations
512
+ await tester.pump ();
513
+ check (lastPoppedRoute).isA <MaterialWidgetRoute >().page.isA <ChooseAccountPage >();
514
+ await tester.pump (
515
+ (lastPoppedRoute as TransitionRoute ).reverseTransitionDuration
516
+ // TODO not sure why a 1ms fudge is needed; investigate.
517
+ + Duration (milliseconds: 1 ));
489
518
// No additional wait for loadPerAccount.
490
519
checkOnHomePage (tester, expectedAccount: eg.selfAccount);
491
520
});
0 commit comments