1
- import 'dart:async' ;
2
1
import 'dart:convert' ;
3
2
4
3
import 'package:checks/checks.dart' ;
@@ -18,7 +17,7 @@ import 'package:zulip/model/store.dart';
18
17
import 'package:zulip/notifications/receive.dart' ;
19
18
import 'package:zulip/widgets/actions.dart' ;
20
19
import 'package:zulip/widgets/app.dart' ;
21
- import 'package:zulip/widgets/inbox .dart' ;
20
+ import 'package:zulip/widgets/home .dart' ;
22
21
import 'package:zulip/widgets/page.dart' ;
23
22
24
23
import '../api/fake_api.dart' ;
@@ -27,9 +26,11 @@ import '../model/binding.dart';
27
26
import '../model/store_checks.dart' ;
28
27
import '../model/test_store.dart' ;
29
28
import '../model/unreads_checks.dart' ;
29
+ import '../notifications/display_test.dart' ;
30
30
import '../stdlib_checks.dart' ;
31
31
import '../test_navigation.dart' ;
32
32
import 'dialog_checks.dart' ;
33
+ import 'page_checks.dart' ;
33
34
import 'test_app.dart' ;
34
35
35
36
void main () {
@@ -168,57 +169,46 @@ void main() {
168
169
169
170
addTearDown (testBinding.reset);
170
171
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 ());
173
174
await testBinding.globalStore.add (account1, eg.initialSnapshot ());
174
- await testBinding.globalStore.add (account2, eg. initialSnapshot ( ));
175
+ await testBinding.globalStore.insertAccount (account2. toCompanion ( false ));
175
176
176
- final testNavObserver = TestNavigatorObserver ();
177
+ final pushedRoutes = < Route <void >> [];
178
+ final testNavObserver = TestNavigatorObserver ()
179
+ ..onPushed = (route, prevRoute) => pushedRoutes.add (route);
177
180
await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
178
181
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]);
195
182
196
183
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 ();
206
202
207
- final removedRoutes = < Route <dynamic >> [];
203
+ final removedRoutes = < Route <void >> [];
208
204
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 ));
212
206
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 ();
222
212
});
223
213
});
224
214
0 commit comments