1- import 'dart:async' ;
21import 'dart:convert' ;
32
43import 'package:checks/checks.dart' ;
@@ -18,7 +17,7 @@ import 'package:zulip/model/store.dart';
1817import 'package:zulip/notifications/receive.dart' ;
1918import 'package:zulip/widgets/actions.dart' ;
2019import 'package:zulip/widgets/app.dart' ;
21- import 'package:zulip/widgets/inbox .dart' ;
20+ import 'package:zulip/widgets/home .dart' ;
2221import 'package:zulip/widgets/page.dart' ;
2322
2423import '../api/fake_api.dart' ;
@@ -27,9 +26,11 @@ import '../model/binding.dart';
2726import '../model/store_checks.dart' ;
2827import '../model/test_store.dart' ;
2928import '../model/unreads_checks.dart' ;
29+ import '../notifications/display_test.dart' ;
3030import '../stdlib_checks.dart' ;
3131import '../test_navigation.dart' ;
3232import 'dialog_checks.dart' ;
33+ import 'page_checks.dart' ;
3334import 'test_app.dart' ;
3435
3536void main () {
@@ -168,57 +169,46 @@ void main() {
168169
169170 addTearDown (testBinding.reset);
170171
171- final account1 = eg.account (id : 1 , user: eg.user ());
172- final account2 = eg.account (id : 2 , user: eg.user ());
172+ final account1 = eg.account (user: eg.user ());
173+ final account2 = eg.account (user: eg.user ());
173174 await testBinding.globalStore.add (account1, eg.initialSnapshot ());
174- await testBinding.globalStore.add (account2, eg. initialSnapshot ( ));
175+ await testBinding.globalStore.insertAccount (account2. toCompanion ( false ));
175176
176- final testNavObserver = TestNavigatorObserver ();
177+ final pushedRoutes = < Route <void >> [];
178+ final testNavObserver = TestNavigatorObserver ()
179+ ..onPushed = (route, prevRoute) => pushedRoutes.add (route);
177180 await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
178181 await tester.pump ();
179- final navigator = await ZulipApp .navigator;
180- navigator.popUntil ((_) => false ); // clear starting routes
181- await tester.pumpAndSettle ();
182-
183- final pushedRoutes = < Route <dynamic >> [];
184- testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
185- // TODO(#737): switch to a realistic setup:
186- // https://github.com/zulip/zulip-flutter/pull/1076#discussion_r1874124363
187- final account1Route = MaterialAccountWidgetRoute (
188- accountId: account1.id, page: const InboxPageBody ());
189- final account2Route = MaterialAccountWidgetRoute (
190- accountId: account2.id, page: const InboxPageBody ());
191- unawaited (navigator.push (account1Route));
192- unawaited (navigator.push (account2Route));
193- await tester.pumpAndSettle ();
194- check (pushedRoutes).deepEquals ([account1Route, account2Route]);
195182
196183 await makeUnreadTopicInInbox (account1.id, 'topic in account1' );
197- final findAccount1PageContent = find.text ('topic in account1' , skipOffstage: false );
198-
199- await makeUnreadTopicInInbox (account2.id, 'topic in account2' );
200- final findAccount2PageContent = find.text ('topic in account2' , skipOffstage: false );
201-
202- final findLoadingPage = find.byType (LoadingPlaceholderPage , skipOffstage: false );
203-
204- check (findAccount1PageContent).findsOne ();
205- check (findLoadingPage).findsNothing ();
184+ final account1PageContentFinder = find.text ('topic in account1' , skipOffstage: false );
185+
186+ check (pushedRoutes).single.isA <WidgetRoute >().page.isA <HomePage >();
187+ pushedRoutes.clear ();
188+ check (account1PageContentFinder).findsOne ();
189+ check (find.byType (CircularProgressIndicator )).findsNothing ();
190+
191+ testBinding.globalStore.loadPerAccountDuration = const Duration (seconds: 1 );
192+ testBinding.globalStore.loadPerAccountException = ZulipApiException (
193+ routeName: '/register' , code: 'INVALID_API_KEY' , httpStatus: 400 ,
194+ data: {}, message: '' );
195+ await openNotification (tester, account2, eg.streamMessage ());
196+ await tester.pump ();
197+ check (pushedRoutes).single
198+ .isA <MaterialAccountWidgetRoute >().accountId.equals (account2.id);
199+ await tester.pump (const Duration (milliseconds: 250 )); // wait for animation
200+ check (account1PageContentFinder).findsOne ();
201+ check (find.byType (CircularProgressIndicator )).findsOne ();
206202
207- final removedRoutes = < Route <dynamic >> [];
203+ final removedRoutes = < Route <void >> [];
208204 testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add (route);
209-
210- final context = tester.element (find.byType (MaterialApp ));
211- final future = logOutAccount (context, account1.id);
205+ await tester.pump (const Duration (seconds: 1 ));
212206 await tester.pump (TestGlobalStore .removeAccountDuration);
213- await future;
214- check (removedRoutes).single.identicalTo (account1Route);
215- check (findAccount1PageContent).findsNothing ();
216- check (findLoadingPage).findsOne ();
217-
218- await tester.pump ();
219- check (findAccount1PageContent).findsNothing ();
220- check (findLoadingPage).findsNothing ();
221- check (findAccount2PageContent).findsOne ();
207+ check (removedRoutes).single
208+ .isA <MaterialAccountWidgetRoute >().accountId.equals (account2.id);
209+ await tester.pump (const Duration (milliseconds: 250 )); // wait for animation
210+ check (account1PageContentFinder).findsOne ();
211+ check (find.byType (CircularProgressIndicator )).findsNothing ();
222212 });
223213 });
224214
0 commit comments