Skip to content

Commit 4feb3e8

Browse files
committed
actions test: Use a more realistic setup for logOutAccount
This rewrite ended being a bit more substantial than just switching both accounts initial routes to the result of MessageListPage.buildRoute(). We do not use popUtil because the navigator stack normally should not become empty, so the HomePage route for account1 stays. Additionally, because we are pushing a different page route, we no longer need to set up different messages as the discriminator, further simplifying the test. See also: zulip#1183 (comment) Signed-off-by: Zixuan James Li <[email protected]>
1 parent 8ab7f74 commit 4feb3e8

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

test/widgets/actions_test.dart

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:async';
21
import 'dart:convert';
32

43
import 'package:checks/checks.dart';
@@ -18,7 +17,8 @@ import 'package:zulip/model/store.dart';
1817
import 'package:zulip/notifications/receive.dart';
1918
import 'package:zulip/widgets/actions.dart';
2019
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';
2222
import 'package:zulip/widgets/page.dart';
2323

2424
import '../api/fake_api.dart';
@@ -27,9 +27,11 @@ import '../model/binding.dart';
2727
import '../model/store_checks.dart';
2828
import '../model/test_store.dart';
2929
import '../model/unreads_checks.dart';
30+
import '../notifications/display_test.dart';
3031
import '../stdlib_checks.dart';
3132
import '../test_navigation.dart';
3233
import 'dialog_checks.dart';
34+
import 'page_checks.dart';
3335
import 'test_app.dart';
3436

3537
void main() {
@@ -156,68 +158,67 @@ void main() {
156158
});
157159

158160
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 {
160162
final stream = eg.stream();
161163
final message = eg.streamMessage(stream: stream, topic: topic);
162164
final store = await testBinding.globalStore.perAccount(accountId);
163165
await store.addStream(stream);
164166
await store.addSubscription(eg.subscription(stream));
165167
await store.addMessage(message);
168+
await store.addUser(user);
166169
await tester.pump();
170+
return message;
167171
}
168172

169173
addTearDown(testBinding.reset);
170174

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;
173177
await testBinding.globalStore.add(account1, eg.initialSnapshot());
174178
await testBinding.globalStore.add(account2, eg.initialSnapshot());
175179

176180
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>>[];
184182
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);
198183

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();
201197

202-
final findLoadingPage = find.byType(LoadingPlaceholderPage, skipOffstage: false);
198+
final findAccount1PageContent = find.byType(HomePage, skipOffstage: false);
199+
final findAccount2PageContent = find.byType(MessageListPage, skipOffstage: false);
203200

201+
check(pushedRoutes).deepEquals([
202+
account1Route,
203+
(Subject<Object?> it) => it.isA<MaterialAccountWidgetRoute>()
204+
..accountId.equals(eg.otherAccount.id)
205+
..page.isA<MessageListPage>(),
206+
]);
204207
check(findAccount1PageContent).findsOne();
205-
check(findLoadingPage).findsNothing();
208+
check(findAccount2PageContent).findsOne();
206209

207-
final removedRoutes = <Route<dynamic>>[];
210+
final removedRoutes = <Route<void>>[];
208211
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
209212

210213
final context = tester.element(find.byType(MaterialApp));
211214
final future = logOutAccount(context, account1.id);
212215
await tester.pump(TestGlobalStore.removeAccountDuration);
213216
await future;
217+
await tester.pumpAndSettle(); // wait for animations, if any
214218
check(removedRoutes).single.identicalTo(account1Route);
219+
check(testBinding.globalStore.takeDoRemoveAccountCalls())
220+
.single.equals(account1.id);
215221
check(findAccount1PageContent).findsNothing();
216-
check(findLoadingPage).findsOne();
217-
218-
await tester.pump();
219-
check(findAccount1PageContent).findsNothing();
220-
check(findLoadingPage).findsNothing();
221222
check(findAccount2PageContent).findsOne();
222223
});
223224
});

0 commit comments

Comments
 (0)