@@ -37,24 +37,53 @@ void main() {
3737 }
3838
3939 testWidgets ('when no accounts, go to choose account' , (tester) async {
40+ check (testBinding.globalStore).accounts.isEmpty ();
41+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
4042 await prepare (tester);
4143 check (pushedRoutes).deepEquals (< Condition <Object ?>> [
4244 (it) => it.isA <WidgetRoute >().page.isA <ChooseAccountPage >(),
4345 ]);
4446 });
4547
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);
48+ group ('when have accounts' , () {
49+ testWidgets ('with account(s) visited, go to home page for the last visited account' , (tester) async {
50+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
51+ await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
52+ realmUsers: [eg.otherUser]));
53+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.otherAccount);
54+ await prepare (tester);
55+
56+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
57+ (it) => it.isA <MaterialAccountWidgetRoute >()
58+ ..accountId.equals (eg.otherAccount.id)
59+ ..page.isA <HomePage >(),
60+ ]);
61+ });
5262
53- check (pushedRoutes).deepEquals (< Condition <Object ?>> [
54- (it) => it.isA <MaterialAccountWidgetRoute >()
55- ..accountId.equals (eg.selfAccount.id)
56- ..page.isA <HomePage >(),
57- ]);
63+ // testWidgets('when just upgraded to get the last-visited-account feature, '
64+ // 'if there is at least one account, open that one, not the choose-account page', (tester) async {
65+ // // The database migration step from9To10 ensures that
66+ // // [IntGlobalSetting.lastVisitedAccountId], thus [GlobalStore.lastVisitedAccount],
67+ // // points to the first account in the list. That migration step has
68+ // // its own tests in test/model/database_test.dart.
69+ // });
70+
71+ testWidgets ('with last visited account logged out, go to choose account' , (tester) async {
72+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
73+ await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
74+ realmUsers: [eg.otherUser]));
75+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.otherAccount);
76+ final future = logOutAccount (testBinding.globalStore, eg.otherAccount.id);
77+ await tester.pump (TestGlobalStore .removeAccountDuration);
78+ await future;
79+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
80+ check (testBinding.globalStore).accounts.isNotEmpty ();
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 >> [];
@@ -322,9 +354,8 @@ void main() {
322354 testWidgets ('choosing an account changes the last visited account' , (tester) async {
323355 addTearDown (testBinding.reset);
324356 await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
325- await testBinding.globalStore.add (
326- eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
327- markLastVisited: false );
357+ await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
358+ realmUsers: [eg.otherUser]));
328359
329360 await tester.pumpWidget (ZulipApp ());
330361 await tester.pump ();
@@ -334,10 +365,10 @@ void main() {
334365 await tester.pump ();
335366 await tester.pump ();
336367
337- check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
338- await tester.tap (find.text (eg.otherAccount.email));
339- await tester.pump ();
340368 check (testBinding.globalStore).lastVisitedAccount.equals (eg.otherAccount);
369+ await tester.tap (find.text (eg.selfAccount.email));
370+ await tester.pump ();
371+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
341372 });
342373
343374 group ('log out' , () {
0 commit comments