Skip to content

Commit 8159ca7

Browse files
Komal SinghKomal Singh
authored andcommitted
home: Add search button to Inbox page
Fixes-partly: #1854
1 parent 4b0cb10 commit 8159ca7

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

lib/widgets/home.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ class _HomePageState extends State<HomePage> {
8484
}
8585
}
8686

87+
List<Widget>? get _currentTabAppBarActions {
88+
switch(_tab.value) {
89+
case _HomePageTab.inbox:
90+
return [
91+
IconButton(
92+
icon: const Icon(ZulipIcons.search),
93+
tooltip: ZulipLocalizations.of(context).searchMessagesPageTitle,
94+
onPressed: () => Navigator.of(context).push(MessageListPage.buildRoute(
95+
context: context, narrow: KeywordSearchNarrow(''))),
96+
),
97+
];
98+
case _HomePageTab.channels:
99+
case _HomePageTab.directMessages:
100+
return null;
101+
}
102+
}
103+
87104
@override
88105
Widget build(BuildContext context) {
89106
const pageBodies = [
@@ -120,7 +137,9 @@ class _HomePageState extends State<HomePage> {
120137
final designVariables = DesignVariables.of(context);
121138
return Scaffold(
122139
appBar: ZulipAppBar(titleSpacing: 16,
123-
title: Text(_currentTabTitle)),
140+
title: Text(_currentTabTitle),
141+
actions: _currentTabAppBarActions
142+
),
124143
body: Stack(
125144
children: [
126145
for (final (tab, body) in pageBodies)

test/widgets/home_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,31 @@ void main () {
111111
check(find.byIcon(ZulipIcons.arrow_right)).findsExactly(2);
112112
});
113113

114-
testWidgets('update app bar title when switching between views', (tester) async {
114+
testWidgets('update app bar title and actions when switching between views', (tester) async {
115115
await prepare(tester);
116116

117+
final findSearchButton = find.descendant(
118+
of: find.byType(ZulipAppBar),
119+
matching: find.byIcon(ZulipIcons.search));
120+
117121
check(find.descendant(
118122
of: find.byType(ZulipAppBar),
119123
matching: find.text('Inbox'))).findsOne();
124+
check(findSearchButton).findsOne();
120125

121126
await tester.tap(find.byIcon(ZulipIcons.hash_italic));
122127
await tester.pump();
123128
check(find.descendant(
124129
of: find.byType(ZulipAppBar),
125130
matching: find.text('Channels'))).findsOne();
131+
check(findSearchButton).findsNothing();
126132

127133
await tester.tap(find.byIcon(ZulipIcons.two_person));
128134
await tester.pump();
129135
check(find.descendant(
130136
of: find.byType(ZulipAppBar),
131137
matching: find.text('Direct messages'))).findsOne();
138+
check(findSearchButton).findsNothing();
132139
});
133140

134141
testWidgets('combined feed', (tester) async {

test/widgets/inbox_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ import 'package:flutter_checks/flutter_checks.dart';
44
import 'package:flutter_test/flutter_test.dart';
55
import 'package:zulip/api/model/events.dart';
66
import 'package:zulip/api/model/model.dart';
7+
import 'package:zulip/model/narrow.dart';
78
import 'package:zulip/model/store.dart';
9+
import 'package:zulip/widgets/app_bar.dart';
810
import 'package:zulip/widgets/color.dart';
911
import 'package:zulip/widgets/home.dart';
1012
import 'package:zulip/widgets/icons.dart';
1113
import 'package:zulip/widgets/channel_colors.dart';
14+
import 'package:zulip/widgets/message_list.dart';
15+
import 'package:zulip/widgets/page.dart';
1216
import 'package:zulip/widgets/unread_count_badge.dart';
1317

1418
import '../example_data.dart' as eg;
1519
import '../flutter_checks.dart';
1620
import '../model/binding.dart';
1721
import '../model/test_store.dart';
22+
import '../test_navigation.dart';
23+
import 'checks.dart';
1824
import 'test_app.dart';
1925

2026
/// Repeatedly drags `view` by `moveStep` until `finder` is invisible.
@@ -649,5 +655,27 @@ void main() {
649655
// reappear because you unmuted a conversation.)
650656
});
651657
});
658+
659+
testWidgets('tapping search button navigates to search page', (tester) async {
660+
final pushedRoutes = <Route<dynamic>>[];
661+
final testNavObserver = TestNavigatorObserver()
662+
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
663+
664+
await setupPage(tester,
665+
unreadMessages: [],
666+
navigatorObserver: testNavObserver);
667+
668+
assert(pushedRoutes.length == 1);
669+
pushedRoutes.clear();
670+
671+
await tester.tap(find.descendant(
672+
of: find.byType(ZulipAppBar),
673+
matching: find.byIcon(ZulipIcons.search)));
674+
await tester.pump();
675+
676+
check(pushedRoutes).single.isA<WidgetRoute>().page
677+
.isA<MessageListPage>()
678+
.initNarrow.equals(KeywordSearchNarrow(''));
679+
});
652680
});
653681
}

0 commit comments

Comments
 (0)