@@ -37,24 +37,47 @@ void main() {
37
37
}
38
38
39
39
testWidgets ('when no accounts, go to choose account' , (tester) async {
40
+ check (testBinding.globalStore).accounts.isEmpty ();
41
+ check (testBinding.globalStore).lastVisitedAccount.isNull ();
40
42
await prepare (tester);
41
43
check (pushedRoutes).deepEquals (< Condition <Object ?>> [
42
44
(it) => it.isA <WidgetRoute >().page.isA <ChooseAccountPage >(),
43
45
]);
44
46
});
45
47
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
+ });
52
64
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
+ });
58
81
});
59
82
});
60
83
@@ -99,6 +122,7 @@ void main() {
99
122
testWidgets ('push route when popping last route on stack' , (tester) async {
100
123
// Set up the loading of per-account data to fail.
101
124
await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
125
+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
102
126
testBinding.globalStore.loadPerAccountDuration = Duration .zero;
103
127
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
104
128
await prepare (tester);
@@ -133,6 +157,7 @@ void main() {
133
157
const loadPerAccountDuration = Duration (seconds: 30 );
134
158
assert (loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135
159
await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
160
+ await testBinding.globalStore.setLastVisitedAccount (eg.selfAccount.id);
136
161
testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137
162
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
138
163
await prepare (tester);
@@ -281,8 +306,9 @@ void main() {
281
306
testWidgets ('choosing an account clears the navigator stack' , (tester) async {
282
307
addTearDown (testBinding.reset);
283
308
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 );
286
312
287
313
final pushedRoutes = < Route <void >> [];
288
314
final poppedRoutes = < Route <void >> [];
0 commit comments