Skip to content

Commit

Permalink
Test a bad case when we get duplicates of choose-account route
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Jan 7, 2025
1 parent 10d4b6b commit ab371f7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/widgets/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,50 @@ void main() {
.contains('consider MaterialAccountWidgetRoute');
});

testWidgets('PerAccountStoreWidget when log out, no duplicate choose-account page', (tester) async {
Route<void>? newRoute, oldRoute;
final testNavObserver = TestNavigatorObserver()
..onReplaced = (route, prevRoute) {
assert(newRoute == null && oldRoute == null);
newRoute = route!;
oldRoute = prevRoute!;
};
// A route to remove is a root level home route
const loadPerAccountDuration = Duration(seconds: 30);
assert(loadPerAccountDuration > kTryAnotherAccountWaitPeriod);
testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
testBinding.globalStore.loadPerAccountException = ZulipApiException(
routeName: '/register', code: 'INVALID_API_KEY', httpStatus: 400,
data: {}, message: '');
await testBinding.globalStore.insertAccount(eg.selfAccount.toCompanion(false));
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
await tester.pump(); // start to load account

final pushedRoutes = <Route<void>>[];
final removedRoutes = <Route<void>>[];
testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add(route);
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
await tester.pump(kTryAnotherAccountWaitPeriod);
await tester.tap(find.text('Try another account'));
await tester.pump(); // tap the button
check(pushedRoutes).single.isA<WidgetRoute>().page.isA<ChooseAccountPage>();
pushedRoutes.clear();

await tester.pump(loadPerAccountDuration); // got the error
await tester.pump(TestGlobalStore.removeAccountDuration);

checkErrorDialog(tester,
expectedTitle: 'Could not connect',
expectedMessage:
'Your account at https://chat.example/ could not be authenticated.'
' Please try logging in again or use another account.');
// Ended up with two choose-account page routes on the stack, not good.
check(newRoute).isA<WidgetRoute>().page.isA<ChooseAccountPage>();
check(oldRoute).isA<WidgetRoute>().page.isA<HomePage>();
check(testBinding.globalStore.takeDoRemoveAccountCalls())
.single.equals(eg.selfAccount.id);
});

testWidgets('PerAccountStoreWidget when log out, replace root level route', (tester) async {
Route<void>? newRoute, oldRoute;
final testNavObserver = TestNavigatorObserver()
Expand Down

0 comments on commit ab371f7

Please sign in to comment.