Skip to content

Commit cbca1e2

Browse files
gnpricechrisbobbe
authored andcommitted
nav: Go straight to an account's home page on launch, when available
1 parent 9df204d commit cbca1e2

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

lib/widgets/app.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class ZulipApp extends StatelessWidget {
114114

115115
return GlobalStoreWidget(
116116
child: Builder(builder: (context) {
117+
final globalStore = GlobalStoreWidget.of(context);
118+
// TODO(#524) choose initial account as last one used
119+
final initialAccountId = globalStore.accounts.firstOrNull?.id;
117120
return MaterialApp(
118121
title: 'Zulip',
119122
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
@@ -143,6 +146,9 @@ class ZulipApp extends StatelessWidget {
143146
onGenerateInitialRoutes: (_) {
144147
return [
145148
MaterialWidgetRoute(page: const ChooseAccountPage()),
149+
if (initialAccountId != null) ...[
150+
HomePage.buildRoute(accountId: initialAccountId),
151+
],
146152
];
147153
});
148154
}));

test/notifications_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,21 @@ void main() {
191191
group('NotificationDisplayManager open', () {
192192
late List<Route<dynamic>> pushedRoutes;
193193

194-
void takeStartingRoutes() {
194+
void takeStartingRoutes({bool withAccount = true}) {
195195
final expected = [
196196
(Subject it) => it.isA<WidgetRoute>().page.isA<ChooseAccountPage>(),
197+
if (withAccount) ...[
198+
(Subject it) => it.isA<MaterialAccountWidgetRoute>()
199+
..accountId.equals(eg.selfAccount.id)
200+
..page.isA<HomePage>(),
201+
],
197202
];
198203
check(pushedRoutes.take(expected.length)).deepEquals(expected);
199204
pushedRoutes.removeRange(0, expected.length);
200205
}
201206

202-
Future<void> prepare(WidgetTester tester, {bool early = false}) async {
207+
Future<void> prepare(WidgetTester tester,
208+
{bool early = false, bool withAccount = true}) async {
203209
await init();
204210
pushedRoutes = [];
205211
final testNavObserver = TestNavigatorObserver()
@@ -210,7 +216,7 @@ void main() {
210216
return;
211217
}
212218
await tester.pump();
213-
takeStartingRoutes();
219+
takeStartingRoutes(withAccount: withAccount);
214220
check(pushedRoutes).isEmpty();
215221
}
216222

@@ -250,7 +256,7 @@ void main() {
250256
});
251257

252258
testWidgets('no accounts', (tester) async {
253-
await prepare(tester);
259+
await prepare(tester, withAccount: false);
254260
await openNotification(eg.selfAccount, eg.streamMessage());
255261
check(pushedRoutes).isEmpty();
256262
});

test/widgets/app_test.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
44
import 'package:zulip/widgets/app.dart';
55
import 'package:zulip/widgets/page.dart';
66

7+
import '../example_data.dart' as eg;
78
import '../model/binding.dart';
89
import '../test_navigation.dart';
910
import 'page_checks.dart';
@@ -23,11 +24,27 @@ void main() {
2324
return pushedRoutes;
2425
}
2526

26-
testWidgets('go to choose-account page', (tester) async {
27+
testWidgets('when no accounts, go to choose account', (tester) async {
2728
addTearDown(testBinding.reset);
2829
check(await initialRoutes(tester)).deepEquals([
2930
(Subject it) => it.isA<WidgetRoute>().page.isA<ChooseAccountPage>(),
3031
]);
3132
});
33+
34+
testWidgets('when have accounts, go to home page for first account', (tester) async {
35+
addTearDown(testBinding.reset);
36+
37+
// We'll need per-account data for the account that a page will be opened
38+
// for, but not for the other account.
39+
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
40+
await testBinding.globalStore.insertAccount(eg.otherAccount.toCompanion(false));
41+
42+
check(await initialRoutes(tester)).deepEquals([
43+
(Subject it) => it.isA<WidgetRoute>().page.isA<ChooseAccountPage>(),
44+
(Subject it) => it.isA<MaterialAccountWidgetRoute>()
45+
..accountId.equals(eg.selfAccount.id)
46+
..page.isA<HomePage>(),
47+
]);
48+
});
3249
});
3350
}

0 commit comments

Comments
 (0)