@@ -4,6 +4,7 @@ import 'package:checks/checks.dart';
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:flutter_test/flutter_test.dart' ;
6
6
import 'package:zulip/log.dart' ;
7
+ import 'package:zulip/model/actions.dart' ;
7
8
import 'package:zulip/model/database.dart' ;
8
9
import 'package:zulip/widgets/app.dart' ;
9
10
import 'package:zulip/widgets/home.dart' ;
@@ -57,6 +58,42 @@ void main() {
57
58
});
58
59
});
59
60
61
+ group ('_PreventEmptyStack' , () {
62
+ late List <Route <void >> pushedRoutes;
63
+ late List <Route <void >> removedRoutes;
64
+
65
+ Future <void > prepare (WidgetTester tester) async {
66
+ addTearDown (testBinding.reset);
67
+
68
+ pushedRoutes = [];
69
+ removedRoutes = [];
70
+ final testNavObserver = TestNavigatorObserver ();
71
+ testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
72
+ testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add (route);
73
+
74
+ await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
75
+ await tester.pump (); // start to load account
76
+ check (pushedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
77
+ pushedRoutes.clear ();
78
+ }
79
+
80
+ testWidgets ('push route when removing last route on stack' , (tester) async {
81
+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
82
+ await prepare (tester);
83
+ // The navigator stack should contain only a home page route.
84
+
85
+ // Log out, causing the home page to be removed from the stack.
86
+ final future = logOutAccount (testBinding.globalStore, eg.selfAccount.id);
87
+ await tester.pump (TestGlobalStore .removeAccountDuration);
88
+ await future;
89
+ check (testBinding.globalStore.takeDoRemoveAccountCalls ())
90
+ .single.equals (eg.selfAccount.id);
91
+ // The choose-account page should appear.
92
+ check (removedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
93
+ check (pushedRoutes).single.isA <WidgetRoute >().page.isA <ChooseAccountPage >();
94
+ });
95
+ });
96
+
60
97
group ('ChooseAccountPage' , () {
61
98
Future <void > setupChooseAccountPage (WidgetTester tester, {
62
99
required List <Account > accounts,
0 commit comments