diff --git a/test/widgets/actions_test.dart b/test/widgets/actions_test.dart index e75bc84df2..43422885e0 100644 --- a/test/widgets/actions_test.dart +++ b/test/widgets/actions_test.dart @@ -18,7 +18,8 @@ import 'package:zulip/model/store.dart'; import 'package:zulip/notifications/receive.dart'; import 'package:zulip/widgets/actions.dart'; import 'package:zulip/widgets/app.dart'; -import 'package:zulip/widgets/inbox.dart'; +import 'package:zulip/widgets/home.dart'; +import 'package:zulip/widgets/message_list.dart'; import 'package:zulip/widgets/page.dart'; import 'package:zulip/widgets/store.dart'; @@ -31,6 +32,7 @@ import '../model/unreads_checks.dart'; import '../stdlib_checks.dart'; import '../test_navigation.dart'; import 'dialog_checks.dart'; +import 'page_checks.dart'; import 'test_app.dart'; void main() { @@ -157,16 +159,6 @@ void main() { }); testWidgets("logged-out account's routes removed from nav; other accounts' remain", (tester) async { - Future makeUnreadTopicInInbox(int accountId, String topic) async { - final stream = eg.stream(); - final message = eg.streamMessage(stream: stream, topic: topic); - final store = await testBinding.globalStore.perAccount(accountId); - await store.addStream(stream); - await store.addSubscription(eg.subscription(stream)); - await store.addMessage(message); - await tester.pump(); - } - addTearDown(testBinding.reset); final account1 = eg.account(id: 1, user: eg.user()); @@ -175,50 +167,42 @@ void main() { await testBinding.globalStore.add(account2, eg.initialSnapshot()); final testNavObserver = TestNavigatorObserver(); + final pushedRoutes = >[]; + testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add(route); + await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver])); await tester.pump(); + final account1Route = pushedRoutes.single; + check(account1Route).isA().page.isA(); + + final account2Connection = + (await testBinding.globalStore.perAccount(account2.id)).connection as FakeApiConnection; + account2Connection.prepare(json: eg.newestGetMessagesResult( + foundOldest: true, messages: []).toJson()); + final account2Route = MessageListPage.buildRoute( + accountId: account2.id, narrow: const CombinedFeedNarrow()); final navigator = await ZulipApp.navigator; - navigator.popUntil((_) => false); // clear starting routes - await tester.pumpAndSettle(); - - final pushedRoutes = >[]; - testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add(route); - // TODO: switch to a realistic setup: - // https://github.com/zulip/zulip-flutter/pull/1076#discussion_r1874124363 - final account1Route = MaterialAccountWidgetRoute( - accountId: account1.id, page: const InboxPageBody()); - final account2Route = MaterialAccountWidgetRoute( - accountId: account2.id, page: const InboxPageBody()); - unawaited(navigator.push(account1Route)); unawaited(navigator.push(account2Route)); - await tester.pumpAndSettle(); - check(pushedRoutes).deepEquals([account1Route, account2Route]); - - await makeUnreadTopicInInbox(account1.id, 'topic in account1'); - final findAccount1PageContent = find.text('topic in account1', skipOffstage: false); - - await makeUnreadTopicInInbox(account2.id, 'topic in account2'); - final findAccount2PageContent = find.text('topic in account2', skipOffstage: false); + await tester.pump(); - final findLoadingPage = find.byType(LoadingPlaceholderPage, skipOffstage: false); + final findAccount1PageContent = find.byType(HomePage, skipOffstage: false); + final findAccount2PageContent = find.byType(MessageListPage, skipOffstage: false); + check(pushedRoutes).deepEquals([account1Route, account2Route]); check(findAccount1PageContent).findsOne(); - check(findLoadingPage).findsNothing(); + check(findAccount2PageContent).findsOne(); - final removedRoutes = >[]; + final removedRoutes = >[]; testNavObserver.onRemoved = (route, prevRoute) => removedRoutes.add(route); - final context = tester.element(find.byType(MaterialApp)); - final future = logOutAccount(GlobalStoreWidget.of(context), account1.id); + final future = logOutAccount(testBinding.globalStore, account1.id); await tester.pump(TestGlobalStore.removeAccountDuration); await future; + await tester.pumpAndSettle(); // wait for animations, if any check(removedRoutes).single.identicalTo(account1Route); + check(testBinding.globalStore.takeDoRemoveAccountCalls()) + .single.equals(account1.id); check(findAccount1PageContent).findsNothing(); - check(findLoadingPage).findsOne(); - - await tester.pump(); - check(findAccount1PageContent).findsNothing(); - check(findLoadingPage).findsNothing(); check(findAccount2PageContent).findsOne(); }); });