1
- import 'dart:async' ;
2
1
import 'dart:convert' ;
3
2
4
3
import 'package:checks/checks.dart' ;
@@ -18,7 +17,8 @@ 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' ;
21
+ import 'package:zulip/widgets/message_list.dart' ;
22
22
import 'package:zulip/widgets/page.dart' ;
23
23
24
24
import '../api/fake_api.dart' ;
@@ -27,9 +27,11 @@ import '../model/binding.dart';
27
27
import '../model/store_checks.dart' ;
28
28
import '../model/test_store.dart' ;
29
29
import '../model/unreads_checks.dart' ;
30
+ import '../notifications/display_test.dart' ;
30
31
import '../stdlib_checks.dart' ;
31
32
import '../test_navigation.dart' ;
32
33
import 'dialog_checks.dart' ;
34
+ import 'page_checks.dart' ;
33
35
import 'test_app.dart' ;
34
36
35
37
void main () {
@@ -156,68 +158,67 @@ void main() {
156
158
});
157
159
158
160
testWidgets ("logged-out account's routes removed from nav; other accounts' remain" , (tester) async {
159
- Future <void > makeUnreadTopicInInbox (int accountId, String topic) async {
161
+ Future <StreamMessage > prepareStoreWithMessage (int accountId, User user , String topic) async {
160
162
final stream = eg.stream ();
161
163
final message = eg.streamMessage (stream: stream, topic: topic);
162
164
final store = await testBinding.globalStore.perAccount (accountId);
163
165
await store.addStream (stream);
164
166
await store.addSubscription (eg.subscription (stream));
165
167
await store.addMessage (message);
168
+ await store.addUser (user);
166
169
await tester.pump ();
170
+ return message;
167
171
}
168
172
169
173
addTearDown (testBinding.reset);
170
174
171
- final account1 = eg.account (id : 1 , user : eg. user ()) ;
172
- final account2 = eg.account (id : 2 , user : eg. user ()) ;
175
+ final account1 = eg.selfAccount ;
176
+ final account2 = eg.otherAccount ;
173
177
await testBinding.globalStore.add (account1, eg.initialSnapshot ());
174
178
await testBinding.globalStore.add (account2, eg.initialSnapshot ());
175
179
176
180
final testNavObserver = TestNavigatorObserver ();
177
- await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
178
- 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 >> [];
181
+ final pushedRoutes = < Route <void >> [];
184
182
testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
185
- // TODO: 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
-
196
- await makeUnreadTopicInInbox (account1.id, 'topic in account1' );
197
- final findAccount1PageContent = find.text ('topic in account1' , skipOffstage: false );
198
183
199
- await makeUnreadTopicInInbox (account2.id, 'topic in account2' );
200
- final findAccount2PageContent = find.text ('topic in account2' , skipOffstage: false );
184
+ await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
185
+ await tester.pump ();
186
+ final account1Route = pushedRoutes.single;
187
+ check (account1Route).isA <WidgetRoute >().page.isA <HomePage >();
188
+
189
+ final account2Connection =
190
+ (await testBinding.globalStore.perAccount (account2.id)).connection as FakeApiConnection ;
191
+ account2Connection.prepare (json: eg.newestGetMessagesResult (
192
+ foundOldest: true , messages: []).toJson ());
193
+ final message = await prepareStoreWithMessage (
194
+ account2.id, eg.otherUser, 'topic' );
195
+ await openNotification (tester, account2, message);
196
+ await tester.pump ();
201
197
202
- final findLoadingPage = find.byType (LoadingPlaceholderPage , skipOffstage: false );
198
+ final findAccount1PageContent = find.byType (HomePage , skipOffstage: false );
199
+ final findAccount2PageContent = find.byType (MessageListPage , skipOffstage: false );
203
200
201
+ check (pushedRoutes).deepEquals ([
202
+ account1Route,
203
+ (Subject <Object ?> it) => it.isA <MaterialAccountWidgetRoute >()
204
+ ..accountId.equals (eg.otherAccount.id)
205
+ ..page.isA <MessageListPage >(),
206
+ ]);
204
207
check (findAccount1PageContent).findsOne ();
205
- check (findLoadingPage). findsNothing ();
208
+ check (findAccount2PageContent). findsOne ();
206
209
207
- final removedRoutes = < Route <dynamic >> [];
210
+ final removedRoutes = < Route <void >> [];
208
211
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add (route);
209
212
210
213
final context = tester.element (find.byType (MaterialApp ));
211
214
final future = logOutAccount (context, account1.id);
212
215
await tester.pump (TestGlobalStore .removeAccountDuration);
213
216
await future;
217
+ await tester.pumpAndSettle (); // wait for animations, if any
214
218
check (removedRoutes).single.identicalTo (account1Route);
219
+ check (testBinding.globalStore.takeDoRemoveAccountCalls ())
220
+ .single.equals (account1.id);
215
221
check (findAccount1PageContent).findsNothing ();
216
- check (findLoadingPage).findsOne ();
217
-
218
- await tester.pump ();
219
- check (findAccount1PageContent).findsNothing ();
220
- check (findLoadingPage).findsNothing ();
221
222
check (findAccount2PageContent).findsOne ();
222
223
});
223
224
});
0 commit comments