@@ -43,18 +43,47 @@ void main() {
4343 ]);
4444 });
4545
46- testWidgets ('when have accounts, go to home page for first account' , (tester) async {
47- // We'll need per-account data for the account that a page will be opened
48- // for, but not for the other account.
49- await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
50- await testBinding.globalStore.insertAccount (eg.otherAccount.toCompanion (false ));
51- await prepare (tester);
46+ group ('when have accounts' , () {
47+ testWidgets ('with account(s) visited, go to home page for the last visited account' , (tester) async {
48+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
49+ await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
50+ realmUsers: [eg.otherUser]));
51+ await prepare (tester);
52+
53+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
54+ (it) => it.isA <MaterialAccountWidgetRoute >()
55+ ..accountId.equals (eg.otherAccount.id)
56+ ..page.isA <HomePage >(),
57+ ]);
58+ });
5259
53- check (pushedRoutes).deepEquals (< Condition <Object ?>> [
54- (it) => it.isA <MaterialAccountWidgetRoute >()
55- ..accountId.equals (eg.selfAccount.id)
56- ..page.isA <HomePage >(),
57- ]);
60+ testWidgets ('with no account visited, go to home page for the first account' , (tester) async {
61+ await testBinding.globalStore.add (
62+ eg.selfAccount, eg.initialSnapshot (),
63+ markLastVisited: false );
64+ await testBinding.globalStore.add (
65+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
66+ markLastVisited: false );
67+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
68+ await prepare (tester);
69+
70+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
71+ (it) => it.isA <MaterialAccountWidgetRoute >()
72+ ..accountId.equals (eg.selfAccount.id)
73+ ..page.isA <HomePage >(),
74+ ]);
75+ });
76+
77+ testWidgets ('with last visited account id matching none of the accounts, go to choose account' , (tester) async {
78+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
79+ await testBinding.globalStore.setLastVisitedAccount (eg.otherAccount.id);
80+ check (testBinding.globalStore).getAccount (eg.otherAccount.id).isNull ();
81+ await prepare (tester);
82+
83+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
84+ (it) => it.isA <WidgetRoute >().page.isA <ChooseAccountPage >(),
85+ ]);
86+ });
5887 });
5988 });
6089
@@ -99,6 +128,7 @@ void main() {
99128 testWidgets ('push route when popping last route on stack' , (tester) async {
100129 // Set up the loading of per-account data to fail.
101130 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
131+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
102132 testBinding.globalStore.loadPerAccountDuration = Duration .zero;
103133 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
104134 await prepare (tester);
@@ -133,6 +163,7 @@ void main() {
133163 const loadPerAccountDuration = Duration (seconds: 30 );
134164 assert (loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135165 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
166+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
136167 testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137168 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
138169 await prepare (tester);
@@ -281,8 +312,9 @@ void main() {
281312 testWidgets ('choosing an account clears the navigator stack' , (tester) async {
282313 addTearDown (testBinding.reset);
283314 await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
284- await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
285- realmUsers: [eg.otherUser]));
315+ await testBinding.globalStore.add (
316+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
317+ markLastVisited: false );
286318
287319 final pushedRoutes = < Route <void >> [];
288320 final poppedRoutes = < Route <void >> [];
@@ -319,6 +351,27 @@ void main() {
319351 ..page.isA <HomePage >();
320352 });
321353
354+ testWidgets ('choosing an account changes the last visited account' , (tester) async {
355+ addTearDown (testBinding.reset);
356+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
357+ await testBinding.globalStore.add (
358+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
359+ markLastVisited: false );
360+
361+ await tester.pumpWidget (ZulipApp ());
362+ await tester.pump ();
363+
364+ final navigator = await ZulipApp .navigator;
365+ unawaited (navigator.push (MaterialWidgetRoute (page: const ChooseAccountPage ())));
366+ await tester.pump ();
367+ await tester.pump ();
368+
369+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
370+ await tester.tap (find.text (eg.otherAccount.email));
371+ await tester.pump ();
372+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.otherAccount);
373+ });
374+
322375 group ('log out' , () {
323376 Future <(Widget , Widget )> prepare (WidgetTester tester, {required Account account}) async {
324377 await setupChooseAccountPage (tester, accounts: [account]);
0 commit comments