From 535f47cfa0f80f17d44ce4544cee031d5ff96fd2 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 16 Feb 2024 13:47:04 -0800 Subject: [PATCH] nav: Go straight to an account's home page on launch, when available --- lib/widgets/app.dart | 7 +++++++ test/widgets/app_test.dart | 19 ++++++++++++++++++- test/widgets/page_checks.dart | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/widgets/app.dart b/lib/widgets/app.dart index 88fd9a932e2..f52d0418f75 100644 --- a/lib/widgets/app.dart +++ b/lib/widgets/app.dart @@ -112,6 +112,9 @@ class ZulipApp extends StatelessWidget { return GlobalStoreWidget( child: Builder(builder: (context) { + final globalStore = GlobalStoreWidget.of(context); + // TODO(#524) choose initial account as last one used + final initialAccountId = globalStore.accounts.firstOrNull?.id; return MaterialApp( title: 'Zulip', localizationsDelegates: ZulipLocalizations.localizationsDelegates, @@ -141,6 +144,10 @@ class ZulipApp extends StatelessWidget { onGenerateInitialRoutes: (_) { return [ MaterialWidgetRoute(page: const ChooseAccountPage()), + if (initialAccountId != null) ...[ + MaterialAccountWidgetRoute(accountId: initialAccountId, + page: const HomePage()), + ], ]; }); })); diff --git a/test/widgets/app_test.dart b/test/widgets/app_test.dart index 2f94d82a3dd..6cfe80dd067 100644 --- a/test/widgets/app_test.dart +++ b/test/widgets/app_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:zulip/widgets/app.dart'; import 'package:zulip/widgets/page.dart'; +import '../example_data.dart' as eg; import '../model/binding.dart'; import '../test_navigation.dart'; import 'page_checks.dart'; @@ -23,11 +24,27 @@ void main() { return pushedRoutes; } - testWidgets('go to choose-account page', (tester) async { + testWidgets('when no accounts, go to choose account', (tester) async { addTearDown(testBinding.reset); check(await initialRoutes(tester)).deepEquals([ (Subject it) => it.isA().page.isA(), ]); }); + + testWidgets('when have accounts, go to home page for first account', (tester) async { + addTearDown(testBinding.reset); + + // We'll need per-account data for the account that a page will be opened + // for, but not for the other account. + await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); + await testBinding.globalStore.insertAccount(eg.otherAccount.toCompanion(false)); + + check(await initialRoutes(tester)).deepEquals([ + (Subject it) => it.isA().page.isA(), + (Subject it) => it.isA() + ..accountId.equals(eg.selfAccount.id) + ..page.isA(), + ]); + }); }); } diff --git a/test/widgets/page_checks.dart b/test/widgets/page_checks.dart index 26590df8a50..f6effa2606e 100644 --- a/test/widgets/page_checks.dart +++ b/test/widgets/page_checks.dart @@ -5,3 +5,7 @@ import 'package:zulip/widgets/page.dart'; extension WidgetRouteChecks on Subject { Subject get page => has((x) => x.page, 'page'); } + +extension AccountPageRouteMixinChecks on Subject { + Subject get accountId => has((x) => x.accountId, 'accountId'); +}