@@ -85,89 +85,92 @@ void main() {
85
85
await prepare (tester);
86
86
// The navigator stack should contain only a home page route.
87
87
88
+ // Log out, causing the home page to be removed from the stack.
88
89
final future = logOutAccount (testBinding.globalStore, eg.selfAccount.id);
89
90
await tester.pump (TestGlobalStore .removeAccountDuration);
90
91
await future;
91
- // The navigator stack should contain only a choose-account page route.
92
92
check (testBinding.globalStore.takeDoRemoveAccountCalls ())
93
93
.single.equals (eg.selfAccount.id);
94
+ // The choose-account page should appear.
94
95
check (removedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
95
96
check (pushedRoutes).single.isA <WidgetRoute >().page.isA <ChooseAccountPage >();
96
97
});
97
98
98
99
testWidgets ('push route when popping last route on stack' , (tester) async {
100
+ // Set up the loading of per-account data to fail.
99
101
await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
100
-
101
102
testBinding.globalStore.loadPerAccountDuration = Duration .zero;
102
103
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
103
104
await prepare (tester);
104
105
// The navigator stack should contain only a home page route.
105
106
106
- await tester.pump (Duration .zero); // got the error
107
+ // Await the failed load, causing the home page to be removed
108
+ // and an error dialog pushed in its place.
109
+ await tester.pump (Duration .zero);
107
110
await tester.pump (TestGlobalStore .removeAccountDuration);
108
- // The navigator stack should contain only a dialog route.
109
- // The home page route was removed because of account logout.
110
111
check (testBinding.globalStore.takeDoRemoveAccountCalls ())
111
112
.single.equals (eg.selfAccount.id);
112
113
check (removedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
113
114
check (poppedRoutes).isEmpty ();
114
115
check (pushedRoutes).single.isA <DialogRoute <void >>();
115
116
pushedRoutes.clear ();
116
117
118
+ // Dismiss the error dialog, causing it to be popped from the stack.
117
119
await tester.tap (find.byWidget (checkErrorDialog (tester,
118
120
expectedTitle: 'Could not connect' ,
119
121
expectedMessage:
120
122
'Your account at ${eg .selfAccount .realmUrl } could not be authenticated.'
121
123
' Please try logging in again or use another account.' )));
122
- // The navigator stack should contain only a choose-account page route.
123
- // After the error dialog is dismissed, it becomes empty,
124
- // so a choose-account page route should be pushed.
124
+ // The choose-account page should appear, because the error dialog
125
+ // was the only route remaining.
125
126
check (poppedRoutes).single.isA <DialogRoute <void >>();
126
127
check (pushedRoutes).single.isA <WidgetRoute >().page.isA <ChooseAccountPage >();
127
128
});
128
129
129
130
testWidgets ('do not push route to non-empty navigator stack' , (tester) async {
130
- await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
131
-
132
- // Set up long enough loading time to later navigate to the choose-account
133
- // page from the loading page via the "Try another account" button.
131
+ // Set up the loading of per-account data to fail, but only after a
132
+ // long enough time for the "Try another account" button to appear.
134
133
const loadPerAccountDuration = Duration (seconds: 30 );
135
134
assert (loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135
+ await testBinding.globalStore.insertAccount (eg.selfAccount.toCompanion (false ));
136
136
testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137
137
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized ();
138
138
await prepare (tester);
139
139
// The navigator stack should contain only a home page route.
140
140
141
+ // Await the "Try another account" button, and tap it.
141
142
await tester.pump (kTryAnotherAccountWaitPeriod);
142
143
await tester.tap (find.text ('Try another account' ));
143
- await tester.pump (); // tap the button
144
+ await tester.pump ();
144
145
// The navigator stack should contain the home page route
145
146
// and a choose-account page route.
146
147
check (removedRoutes).isEmpty ();
147
148
check (poppedRoutes).isEmpty ();
148
149
check (pushedRoutes).single.isA <WidgetRoute >().page.isA <ChooseAccountPage >();
149
150
pushedRoutes.clear ();
150
151
151
- await tester.pump (loadPerAccountDuration); // got the error
152
+ // Now await the failed load, causing the home page to be removed
153
+ // and an error dialog pushed, while the choose-account page remains.
154
+ await tester.pump (loadPerAccountDuration);
152
155
await tester.pump (TestGlobalStore .removeAccountDuration);
153
- // The navigator stack should contain the choose-account page route
154
- // and a dialog route.
155
- // The home page route was removed because of account logout.
156
156
check (testBinding.globalStore.takeDoRemoveAccountCalls ())
157
157
.single.equals (eg.selfAccount.id);
158
158
check (removedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
159
159
check (poppedRoutes).isEmpty ();
160
160
check (pushedRoutes).single.isA <DialogRoute <void >>();
161
161
pushedRoutes.clear ();
162
+ // The navigator stack should now contain the choose-account page route
163
+ // and the dialog route.
162
164
165
+ // Dismiss the error dialog, causing it to be popped from the stack.
163
166
await tester.tap (find.byWidget (checkErrorDialog (tester,
164
167
expectedTitle: 'Could not connect' ,
165
168
expectedMessage:
166
169
'Your account at ${eg .selfAccount .realmUrl } could not be authenticated.'
167
170
' Please try logging in again or use another account.' )));
168
- // The navigator stack should contain only the choose-account page route.
169
171
// No routes should be pushed after dismissing the error dialog,
170
- // because the navigator stack was non-empty.
172
+ // because there was already another route remaining on the stack
173
+ // (namely the choose-account page route).
171
174
check (poppedRoutes).single.isA <DialogRoute <void >>();
172
175
check (pushedRoutes).isEmpty ();
173
176
});
0 commit comments