Skip to content

Commit 0da58df

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. Signed-off-by: Zixuan James Li <[email protected]>
1 parent a7a6d6e commit 0da58df

File tree

1 file changed

+25
-41
lines changed

1 file changed

+25
-41
lines changed

test/widgets/actions_test.dart

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import 'package:zulip/model/store.dart';
1818
import 'package:zulip/notifications/receive.dart';
1919
import 'package:zulip/widgets/actions.dart';
2020
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';
2223
import 'package:zulip/widgets/page.dart';
2324
import 'package:zulip/widgets/store.dart';
2425

@@ -31,6 +32,7 @@ import '../model/unreads_checks.dart';
3132
import '../stdlib_checks.dart';
3233
import '../test_navigation.dart';
3334
import 'dialog_checks.dart';
35+
import 'page_checks.dart';
3436
import 'test_app.dart';
3537

3638
void main() {
@@ -157,16 +159,6 @@ void main() {
157159
});
158160

159161
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-
170162
addTearDown(testBinding.reset);
171163

172164
final account1 = eg.account(id: 1, user: eg.user());
@@ -175,50 +167,42 @@ void main() {
175167
await testBinding.globalStore.add(account2, eg.initialSnapshot());
176168

177169
final testNavObserver = TestNavigatorObserver();
170+
final pushedRoutes = <Route<void>>[];
171+
testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add(route);
172+
178173
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
179174
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());
180184
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));
193185
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();
202187

203-
final findLoadingPage = find.byType(LoadingPlaceholderPage, skipOffstage: false);
188+
final findAccount1PageContent = find.byType(HomePage, skipOffstage: false);
189+
final findAccount2PageContent = find.byType(MessageListPage, skipOffstage: false);
204190

191+
check(pushedRoutes).deepEquals([account1Route, account2Route]);
205192
check(findAccount1PageContent).findsOne();
206-
check(findLoadingPage).findsNothing();
193+
check(findAccount2PageContent).findsOne();
207194

208-
final removedRoutes = <Route<dynamic>>[];
195+
final removedRoutes = <Route<void>>[];
209196
testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route);
210197

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);
213199
await tester.pump(TestGlobalStore.removeAccountDuration);
214200
await future;
201+
await tester.pumpAndSettle(); // wait for animations, if any
215202
check(removedRoutes).single.identicalTo(account1Route);
203+
check(testBinding.globalStore.takeDoRemoveAccountCalls())
204+
.single.equals(account1.id);
216205
check(findAccount1PageContent).findsNothing();
217-
check(findLoadingPage).findsOne();
218-
219-
await tester.pump();
220-
check(findAccount1PageContent).findsNothing();
221-
check(findLoadingPage).findsNothing();
222206
check(findAccount2PageContent).findsOne();
223207
});
224208
});

0 commit comments

Comments
 (0)