Skip to content

Commit f6cd002

Browse files
committed
(squash) narrate _PreventEmptyStack tests a bit more
1 parent 554aac6 commit f6cd002

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

test/widgets/app_test.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,89 +85,92 @@ void main() {
8585
await prepare(tester);
8686
// The navigator stack should contain only a home page route.
8787

88+
// Log out, causing the home page to be removed from the stack.
8889
final future = logOutAccount(testBinding.globalStore, eg.selfAccount.id);
8990
await tester.pump(TestGlobalStore.removeAccountDuration);
9091
await future;
91-
// The navigator stack should contain only a choose-account page route.
9292
check(testBinding.globalStore.takeDoRemoveAccountCalls())
9393
.single.equals(eg.selfAccount.id);
94+
// The choose-account page should appear.
9495
check(removedRoutes).single.isA<WidgetRoute>().page.isA<HomePage>();
9596
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<ChooseAccountPage>();
9697
});
9798

9899
testWidgets('push route when popping last route on stack', (tester) async {
100+
// Set up the loading of per-account data to fail.
99101
await testBinding.globalStore.insertAccount(eg.selfAccount.toCompanion(false));
100-
101102
testBinding.globalStore.loadPerAccountDuration = Duration.zero;
102103
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized();
103104
await prepare(tester);
104105
// The navigator stack should contain only a home page route.
105106

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);
107110
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.
110111
check(testBinding.globalStore.takeDoRemoveAccountCalls())
111112
.single.equals(eg.selfAccount.id);
112113
check(removedRoutes).single.isA<WidgetRoute>().page.isA<HomePage>();
113114
check(poppedRoutes).isEmpty();
114115
check(pushedRoutes).single.isA<DialogRoute<void>>();
115116
pushedRoutes.clear();
116117

118+
// Dismiss the error dialog, causing it to be popped from the stack.
117119
await tester.tap(find.byWidget(checkErrorDialog(tester,
118120
expectedTitle: 'Could not connect',
119121
expectedMessage:
120122
'Your account at ${eg.selfAccount.realmUrl} could not be authenticated.'
121123
' 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.
125126
check(poppedRoutes).single.isA<DialogRoute<void>>();
126127
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<ChooseAccountPage>();
127128
});
128129

129130
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.
134133
const loadPerAccountDuration = Duration(seconds: 30);
135134
assert(loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
135+
await testBinding.globalStore.insertAccount(eg.selfAccount.toCompanion(false));
136136
testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
137137
testBinding.globalStore.loadPerAccountException = eg.apiExceptionUnauthorized();
138138
await prepare(tester);
139139
// The navigator stack should contain only a home page route.
140140

141+
// Await the "Try another account" button, and tap it.
141142
await tester.pump(kTryAnotherAccountWaitPeriod);
142143
await tester.tap(find.text('Try another account'));
143-
await tester.pump(); // tap the button
144+
await tester.pump();
144145
// The navigator stack should contain the home page route
145146
// and a choose-account page route.
146147
check(removedRoutes).isEmpty();
147148
check(poppedRoutes).isEmpty();
148149
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<ChooseAccountPage>();
149150
pushedRoutes.clear();
150151

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);
152155
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.
156156
check(testBinding.globalStore.takeDoRemoveAccountCalls())
157157
.single.equals(eg.selfAccount.id);
158158
check(removedRoutes).single.isA<WidgetRoute>().page.isA<HomePage>();
159159
check(poppedRoutes).isEmpty();
160160
check(pushedRoutes).single.isA<DialogRoute<void>>();
161161
pushedRoutes.clear();
162+
// The navigator stack should now contain the choose-account page route
163+
// and the dialog route.
162164

165+
// Dismiss the error dialog, causing it to be popped from the stack.
163166
await tester.tap(find.byWidget(checkErrorDialog(tester,
164167
expectedTitle: 'Could not connect',
165168
expectedMessage:
166169
'Your account at ${eg.selfAccount.realmUrl} could not be authenticated.'
167170
' Please try logging in again or use another account.')));
168-
// The navigator stack should contain only the choose-account page route.
169171
// 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).
171174
check(poppedRoutes).single.isA<DialogRoute<void>>();
172175
check(pushedRoutes).isEmpty();
173176
});

0 commit comments

Comments
 (0)