@@ -37,24 +37,52 @@ 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('with no account visited, go to home page for the first account', (tester) async {
64+ // // The database migration step from10To11 ensures that
65+ // // [IntGlobalSetting.lastVisitedAccountId], thus [GlobalStore.lastVisitedAccount],
66+ // // points to the first account in the list. That migration step has its
67+ // // own tests in test/model/database_test.dart.
68+ // });
69+
70+ testWidgets ('with last visited account logged out, go to choose account' , (tester) async {
71+ await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
72+ await testBinding.globalStore.add (
73+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
74+ markLastVisited: false );
75+ check (testBinding.globalStore).lastVisitedAccount.equals (eg.selfAccount);
76+ final future = logOutAccount (testBinding.globalStore, eg.selfAccount.id);
77+ await tester.pump (TestGlobalStore .removeAccountDuration);
78+ await future;
79+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
80+ await prepare (tester);
81+
82+ check (pushedRoutes).deepEquals (< Condition <Object ?>> [
83+ (it) => it.isA <WidgetRoute >().page.isA <ChooseAccountPage >(),
84+ ]);
85+ });
5886 });
5987 });
6088
@@ -99,6 +127,7 @@ void main() {
99127 testWidgets ('push route when popping last route on stack' , (tester) async {
100128 // Set up the loading of per-account data to fail.
101129 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
130+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
102131 testBinding.globalStore.loadPerAccountDuration = Duration .zero;
103132 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
104133 await prepare (tester);
@@ -133,6 +162,7 @@ void main() {
133162 const loadPerAccountDuration = Duration (seconds: 30 );
134163 assert (loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135164 await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
165+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
136166 testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137167 testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
138168 await prepare (tester);
@@ -281,8 +311,9 @@ void main() {
281311 testWidgets ('choosing an account clears the navigator stack' , (tester) async {
282312 addTearDown (testBinding.reset);
283313 await testBinding.globalStore.add (eg.selfAccount, eg.initialSnapshot ());
284- await testBinding.globalStore.add (eg.otherAccount, eg.initialSnapshot (
285- realmUsers: [eg.otherUser]));
314+ await testBinding.globalStore.add (
315+ eg.otherAccount, eg.initialSnapshot (realmUsers: [eg.otherUser]),
316+ markLastVisited: false );
286317
287318 final pushedRoutes = < Route <void >> [];
288319 final poppedRoutes = < Route <void >> [];
0 commit comments