diff --git a/test/widgets/store_test.dart b/test/widgets/store_test.dart index b5873cfd827..cc1b25758d5 100644 --- a/test/widgets/store_test.dart +++ b/test/widgets/store_test.dart @@ -123,6 +123,50 @@ void main() { .contains('consider MaterialAccountWidgetRoute'); }); + testWidgets('PerAccountStoreWidget when log out, no duplicate choose-account page', (tester) async { + Route? 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 = >[]; + final removedRoutes = >[]; + 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().page.isA(); + 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().page.isA(); + check(oldRoute).isA().page.isA(); + check(testBinding.globalStore.takeDoRemoveAccountCalls()) + .single.equals(eg.selfAccount.id); + }); + testWidgets('PerAccountStoreWidget when log out, replace root level route', (tester) async { Route? newRoute, oldRoute; final testNavObserver = TestNavigatorObserver()