@@ -37,24 +37,47 @@ 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.insertAccount (eg.otherAccount.toCompanion (false ));
51+ // We'll need per-account data for the account that a page will be opened
52+ // for, but not for the other accounts.
53+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
54+ await testBinding.globalStore.insertAccount (eg.thirdAccount.toCompanion (false ));
55+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
56+ await prepare (tester);
57+
58+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
59+ (it) => it.isA <MaterialAccountWidgetRoute >()
60+ ..accountId.equals (eg.selfAccount.id)
61+ ..page.isA <HomePage >(),
62+ ]);
63+ });
5264
53- check (pushedRoutes).deepEquals (< Condition <Object ?>> [
54- (it) => it.isA <MaterialAccountWidgetRoute >()
55- ..accountId.equals (eg.selfAccount.id)
56- ..page.isA <HomePage >(),
57- ]);
65+ testWidgets ('with last visited account logged out, go to choose account' , (tester) async {
66+ await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
67+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
68+ await testBinding.globalStore.insertAccount (eg.otherAccount.toCompanion (false ));
69+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
70+ final future = logOutAccount (testBinding.globalStore, eg.selfAccount.id);
71+ await tester.pump (TestGlobalStore .removeAccountDuration);
72+ await future;
73+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
74+ check (testBinding.globalStore).accounts.isNotEmpty ();
75+ await prepare (tester);
76+
77+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
78+ (it) => it.isA <WidgetRoute >().page.isA <ChooseAccountPage >(),
79+ ]);
80+ });
5881 });
5982 });
6083
@@ -99,6 +122,7 @@ void main() {
99122 testWidgets ('push route when popping last route on stack' , (tester) async {
100123 // Set up the loading of per-account data to fail.
101124 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
125+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
102126 testBinding.globalStore.loadPerAccountDuration = Duration .zero;
103127 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
104128 await prepare (tester);
@@ -133,6 +157,7 @@ void main() {
133157 const loadPerAccountDuration = Duration (seconds: 30 );
134158 assert (loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135159 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
160+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
136161 testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137162 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
138163 await prepare (tester);
@@ -281,8 +306,9 @@ void main() {
281306 testWidgets ('choosing an account clears the navigator stack' , (tester) async {
282307 addTearDown (testBinding.reset);
283308 await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
284- await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
285- realmUsers: [eg.otherUser]));
309+ await testBinding.globalStore.add (
310+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
311+ markLastVisited: false );
286312
287313 final pushedRoutes = < Route <void >> [];
288314 final poppedRoutes = < Route <void >> [];
0 commit comments