@@ -18,7 +18,8 @@ import 'package:zulip/model/store.dart';
18
18
import 'package:zulip/notifications/receive.dart' ;
19
19
import 'package:zulip/widgets/actions.dart' ;
20
20
import 'package:zulip/widgets/app.dart' ;
21
- import 'package:zulip/widgets/inbox.dart' ;
21
+ import 'package:zulip/widgets/home.dart' ;
22
+ import 'package:zulip/widgets/message_list.dart' ;
22
23
import 'package:zulip/widgets/page.dart' ;
23
24
import 'package:zulip/widgets/store.dart' ;
24
25
@@ -31,6 +32,7 @@ import '../model/unreads_checks.dart';
31
32
import '../stdlib_checks.dart' ;
32
33
import '../test_navigation.dart' ;
33
34
import 'dialog_checks.dart' ;
35
+ import 'page_checks.dart' ;
34
36
import 'test_app.dart' ;
35
37
36
38
void main () {
@@ -157,16 +159,6 @@ void main() {
157
159
});
158
160
159
161
testWidgets ("logged-out account's routes removed from nav; other accounts' remain" , (tester) async {
160
- Future <void > makeUnreadTopicInInbox (int accountId, String topic) async {
161
- final stream = eg.stream ();
162
- final message = eg.streamMessage (stream: stream, topic: topic);
163
- final store = await testBinding.globalStore.perAccount (accountId);
164
- await store.addStream (stream);
165
- await store.addSubscription (eg.subscription (stream));
166
- await store.addMessage (message);
167
- await tester.pump ();
168
- }
169
-
170
162
addTearDown (testBinding.reset);
171
163
172
164
final account1 = eg.account (id: 1 , user: eg.user ());
@@ -175,50 +167,42 @@ void main() {
175
167
await testBinding.globalStore.add (account2, eg.initialSnapshot ());
176
168
177
169
final testNavObserver = TestNavigatorObserver ();
170
+ final pushedRoutes = < Route <void >> [];
171
+ testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
172
+
178
173
await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
179
174
await tester.pump ();
175
+ final account1Route = pushedRoutes.single;
176
+ check (account1Route).isA <WidgetRoute >().page.isA <HomePage >();
177
+
178
+ final account2Connection =
179
+ (await testBinding.globalStore.perAccount (account2.id)).connection as FakeApiConnection ;
180
+ account2Connection.prepare (json: eg.newestGetMessagesResult (
181
+ foundOldest: true , messages: []).toJson ());
182
+ final account2Route = MessageListPage .buildRoute (
183
+ accountId: account2.id, narrow: const CombinedFeedNarrow ());
180
184
final navigator = await ZulipApp .navigator;
181
- navigator.popUntil ((_) => false ); // clear starting routes
182
- await tester.pumpAndSettle ();
183
-
184
- final pushedRoutes = < Route <dynamic >> [];
185
- testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
186
- // TODO: switch to a realistic setup:
187
- // https://github.com/zulip/zulip-flutter/pull/1076#discussion_r1874124363
188
- final account1Route = MaterialAccountWidgetRoute (
189
- accountId: account1.id, page: const InboxPageBody ());
190
- final account2Route = MaterialAccountWidgetRoute (
191
- accountId: account2.id, page: const InboxPageBody ());
192
- unawaited (navigator.push (account1Route));
193
185
unawaited (navigator.push (account2Route));
194
- await tester.pumpAndSettle ();
195
- check (pushedRoutes).deepEquals ([account1Route, account2Route]);
196
-
197
- await makeUnreadTopicInInbox (account1.id, 'topic in account1' );
198
- final findAccount1PageContent = find.text ('topic in account1' , skipOffstage: false );
199
-
200
- await makeUnreadTopicInInbox (account2.id, 'topic in account2' );
201
- final findAccount2PageContent = find.text ('topic in account2' , skipOffstage: false );
186
+ await tester.pump ();
202
187
203
- final findLoadingPage = find.byType (LoadingPlaceholderPage , skipOffstage: false );
188
+ final findAccount1PageContent = find.byType (HomePage , skipOffstage: false );
189
+ final findAccount2PageContent = find.byType (MessageListPage , skipOffstage: false );
204
190
191
+ check (pushedRoutes).deepEquals ([account1Route, account2Route]);
205
192
check (findAccount1PageContent).findsOne ();
206
- check (findLoadingPage). findsNothing ();
193
+ check (findAccount2PageContent). findsOne ();
207
194
208
- final removedRoutes = < Route <dynamic >> [];
195
+ final removedRoutes = < Route <void >> [];
209
196
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add (route);
210
197
211
- final context = tester.element (find.byType (MaterialApp ));
212
- final future = logOutAccount (GlobalStoreWidget .of (context), account1.id);
198
+ final future = logOutAccount (testBinding.globalStore, account1.id);
213
199
await tester.pump (TestGlobalStore .removeAccountDuration);
214
200
await future;
201
+ await tester.pumpAndSettle (); // wait for animations, if any
215
202
check (removedRoutes).single.identicalTo (account1Route);
203
+ check (testBinding.globalStore.takeDoRemoveAccountCalls ())
204
+ .single.equals (account1.id);
216
205
check (findAccount1PageContent).findsNothing ();
217
- check (findLoadingPage).findsOne ();
218
-
219
- await tester.pump ();
220
- check (findAccount1PageContent).findsNothing ();
221
- check (findLoadingPage).findsNothing ();
222
206
check (findAccount2PageContent).findsOne ();
223
207
});
224
208
});
0 commit comments