Skip to content

Commit 3608a3e

Browse files
Komal SinghKomal Singh
authored andcommitted
message list: Add search button to app bar and related tests.
Adds a search icon button in the message list app bar that appears on the combined feed narrow. Uses the same localized 'Search' text for consistency with the message list search button. Also adds a focused test in the existing 'app bar' group inside message_list_test that verifies the search button appears on combined feed and navigates correctly to the search page when tapped.
1 parent 56dcb48 commit 3608a3e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/widgets/message_list.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ abstract class _MessageListAppBar {
416416
List<Widget> actions = [];
417417
switch (narrow) {
418418
case CombinedFeedNarrow():
419+
actions.add(IconButton(
420+
icon: const Icon(ZulipIcons.search),
421+
tooltip: zulipLocalizations.searchMessagesPageTitle,
422+
onPressed: () => Navigator.push(context,
423+
MessageListPage.buildRoute(context: context,
424+
narrow: KeywordSearchNarrow('')))));
419425
case MentionsNarrow():
420426
case StarredMessagesNarrow():
421427
case KeywordSearchNarrow():

test/widgets/message_list_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,42 @@ void main() {
363363

364364
check(find.text('DMs with Muted user, User 2, Muted user')).findsOne();
365365
});
366+
367+
testWidgets('search button on combined feed navigates to search page', (tester) async {
368+
// Set up navigation tracking
369+
final pushedRoutes = <Route<dynamic>>[];
370+
final testNavObserver = TestNavigatorObserver()
371+
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
372+
373+
// Set up the combined feed view with navigation observer
374+
await setupMessageListPage(tester,
375+
narrow: const CombinedFeedNarrow(),
376+
messages: [],
377+
navObservers: [testNavObserver]);
378+
379+
// Verify that the search button is present in the app bar
380+
final searchButtonFinder = find.descendant(
381+
of: find.byType(ZulipAppBar),
382+
matching: find.byIcon(ZulipIcons.search));
383+
check(searchButtonFinder).findsOne();
384+
385+
// Clear any initial navigation that happened during setup
386+
pushedRoutes.clear();
387+
388+
// Mock the API call for the search page
389+
connection.prepare(json: eg.newestGetMessagesResult(
390+
foundOldest: true, messages: []).toJson());
391+
392+
// Tap the search button in the app bar
393+
await tester.tap(searchButtonFinder);
394+
await tester.pump();
395+
396+
// Verify that we navigated to the search page with an empty search query
397+
check(pushedRoutes).single.isA<WidgetRoute>().page
398+
.isA<MessageListPage>()
399+
.initNarrow.equals(KeywordSearchNarrow(''));
400+
await tester.pump(Duration.zero); // Allow message list fetch to complete
401+
});
366402
});
367403

368404
group('no-messages placeholder', () {

0 commit comments

Comments
 (0)