Skip to content

Commit 56dcb48

Browse files
Komal SinghKomal Singh
authored andcommitted
home: Add search button and related tests.
Adds a search icon and tooltip to the icon in the home page app bar that appears on the inbox tab. Uses the same localized 'Search' text for consistency with the message list search button. Also refactors the app bar actions logic by extracting it into a _currentTabAppBarActions getter. Updates the existing bottom nav navigation test inside home_test to verify search button presence across different tabs: present on inbox, absent on channels and direct messages tabs. Also updates the existing InboxPage tests to verify the search button navigates to search page when tapped
1 parent 4b0cb10 commit 56dcb48

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,40 @@ 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+
// Helper to check if search button is present
118+
bool hasSearchButton() {
119+
final appBar = tester.widget<ZulipAppBar>(find.byType(ZulipAppBar));
120+
final actions = appBar.actions ?? [];
121+
return actions.any((widget) =>
122+
widget is IconButton &&
123+
widget.icon is Icon &&
124+
(widget.icon as Icon).icon == ZulipIcons.search);
125+
}
126+
127+
// Inbox tab: should have title "Inbox" and search button
117128
check(find.descendant(
118129
of: find.byType(ZulipAppBar),
119130
matching: find.text('Inbox'))).findsOne();
131+
check(hasSearchButton()).isTrue();
120132

133+
// Channels tab: should have title "Channels" and no search button
121134
await tester.tap(find.byIcon(ZulipIcons.hash_italic));
122135
await tester.pump();
123136
check(find.descendant(
124137
of: find.byType(ZulipAppBar),
125138
matching: find.text('Channels'))).findsOne();
139+
check(hasSearchButton()).isFalse();
126140

141+
// Direct messages tab: should have title "Direct messages" and no search button
127142
await tester.tap(find.byIcon(ZulipIcons.two_person));
128143
await tester.pump();
129144
check(find.descendant(
130145
of: find.byType(ZulipAppBar),
131146
matching: find.text('Direct messages'))).findsOne();
147+
check(hasSearchButton()).isFalse();
132148
});
133149

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

test/widgets/inbox_test.dart

Lines changed: 33 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,32 @@ void main() {
649655
// reappear because you unmuted a conversation.)
650656
});
651657
});
658+
659+
testWidgets('tapping search button navigates to search page', (tester) async {
660+
// Set up navigation tracking
661+
final pushedRoutes = <Route<dynamic>>[];
662+
final testNavObserver = TestNavigatorObserver()
663+
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
664+
665+
// Use existing setupPage function with navigation observer
666+
await setupPage(tester,
667+
unreadMessages: [],
668+
navigatorObserver: testNavObserver);
669+
670+
// Clear the initial route
671+
assert(pushedRoutes.length == 1);
672+
pushedRoutes.clear();
673+
674+
// Tap the search button in the app bar
675+
await tester.tap(find.descendant(
676+
of: find.byType(ZulipAppBar),
677+
matching: find.byIcon(ZulipIcons.search)));
678+
await tester.pump();
679+
680+
// Verify that we navigated to the search page (MessageListPage with KeywordSearchNarrow)
681+
check(pushedRoutes).single.isA<WidgetRoute>().page
682+
.isA<MessageListPage>()
683+
.initNarrow.equals(KeywordSearchNarrow(''));
684+
});
652685
});
653686
}

0 commit comments

Comments
 (0)