Skip to content

Commit

Permalink
nav: Go straight to an account's home page on launch, when available
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Feb 17, 2024
1 parent 983f32e commit 535f47c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -141,6 +144,10 @@ class ZulipApp extends StatelessWidget {
onGenerateInitialRoutes: (_) {
return [
MaterialWidgetRoute(page: const ChooseAccountPage()),
if (initialAccountId != null) ...[
MaterialAccountWidgetRoute(accountId: initialAccountId,
page: const HomePage()),
],
];
});
}));
Expand Down
19 changes: 18 additions & 1 deletion test/widgets/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<WidgetRoute>().page.isA<ChooseAccountPage>(),
]);
});

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<WidgetRoute>().page.isA<ChooseAccountPage>(),
(Subject it) => it.isA<MaterialAccountWidgetRoute>()
..accountId.equals(eg.selfAccount.id)
..page.isA<HomePage>(),
]);
});
});
}
4 changes: 4 additions & 0 deletions test/widgets/page_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ import 'package:zulip/widgets/page.dart';
extension WidgetRouteChecks on Subject<WidgetRoute> {
Subject<Widget> get page => has((x) => x.page, 'page');
}

extension AccountPageRouteMixinChecks on Subject<AccountPageRouteMixin> {
Subject<int> get accountId => has((x) => x.accountId, 'accountId');
}

0 comments on commit 535f47c

Please sign in to comment.