@@ -329,24 +329,38 @@ void main () {
329329
330330 Future <void > prepare (WidgetTester tester) async {
331331 addTearDown (testBinding.reset);
332+ topRoute = null ;
333+ previousTopRoute = null ;
334+ pushedRoutes = [];
335+ lastPoppedRoute = null ;
332336 await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
333337 await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot ());
334- await tester.pumpWidget (const ZulipApp ());
338+ await tester.pumpWidget (ZulipApp (navigatorObservers : [testNavObserver] ));
335339 await tester.pump (Duration .zero); // wait for the loading page
336340 checkOnLoadingPage ();
337341 }
338342
339343 Future <void > tapTryAnotherAccount (WidgetTester tester) async {
344+ final numPushedRoutesBefore = pushedRoutes.length;
340345 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);
343350 checkOnChooseAccountPage ();
344351 }
345352
346353 Future <void > chooseAccountWithEmail (WidgetTester tester, String email) async {
354+ lastPoppedRoute = null ;
347355 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 ));
350364 checkOnLoadingPage ();
351365 }
352366
@@ -379,9 +393,14 @@ void main () {
379393 await tester.pump (kTryAnotherAccountWaitPeriod);
380394 await tapTryAnotherAccount (tester);
381395
396+ lastPoppedRoute = null ;
382397 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 ));
385404 checkOnLoadingPage ();
386405
387406 await tester.pump (loadPerAccountDuration);
@@ -466,9 +485,14 @@ void main () {
466485 await tester.pump (loadPerAccountDuration);
467486 checkOnChooseAccountPage ();
468487
488+ lastPoppedRoute = null ;
469489 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 ));
472496 checkOnHomePage (tester, expectedAccount: eg.selfAccount);
473497 });
474498
@@ -483,9 +507,14 @@ void main () {
483507 checkOnChooseAccountPage ();
484508
485509 // Choosing the already loaded account should result in no loading page.
510+ lastPoppedRoute = null ;
486511 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 ));
489518 // No additional wait for loadPerAccount.
490519 checkOnHomePage (tester, expectedAccount: eg.selfAccount);
491520 });
0 commit comments