From b256899a19f584d2885e58c8b418124200ccd18a Mon Sep 17 00:00:00 2001 From: kenny lopez Date: Thu, 15 Oct 2026 09:04:44 -0400 Subject: [PATCH] Test iOS search filters through the native tap channel Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez --- .../features/search/search_page_test.dart | 103 ++++++++++++++++-- 1 file changed, 94 insertions(+), 9 deletions(-) diff --git a/mobile/test/features/search/search_page_test.dart b/mobile/test/features/search/search_page_test.dart index 6f96873249..8e5d549565 100644 --- a/mobile/test/features/search/search_page_test.dart +++ b/mobile/test/features/search/search_page_test.dart @@ -14,6 +14,7 @@ import 'package:buzz/shared/mentions/agent_identity_provider.dart'; import 'package:buzz/shared/widgets/concentric_sheet_surface.dart'; import 'package:buzz/shared/widgets/ios_glass_navigation_button.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:buzz/shared/theme/buzz_icons.dart'; @@ -82,15 +83,7 @@ void main() { ); await tester.enterText(find.byType(TextField), 'design'); if (platform == TargetPlatform.iOS) { - tester - .widget( - find.byWidgetPredicate( - (widget) => - widget is IosGlassNavigationButton && - widget.label == 'Channels', - ), - ) - .onPressed!(); + await _pressNativeFilter(tester, 'Channels'); } else { await tester.tap(find.text('Channels')); } @@ -116,6 +109,77 @@ void main() { } } + testWidgets('iOS native filter press selects Channels and filters results', ( + tester, + ) async { + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + addTearDown(() => debugDefaultTargetPlatformOverride = null); + final state = SearchState( + query: 'design', + channelResults: [ + Channel( + id: 'design', + name: 'design', + channelType: 'stream', + visibility: 'open', + description: 'Design discussion', + memberCount: 4, + createdBy: 'test', + createdAt: DateTime(2025), + isMember: true, + ), + ], + userResults: const [DirectoryUser(pubkey: 'maya', displayName: 'Maya')], + ); + await tester.pumpWidget( + WidgetHelpers.testable( + overrides: [ + searchProvider.overrideWith(() => _FakeSearchNotifier(state)), + recentSearchesProvider.overrideWith( + () => _FakeRecentSearchesNotifier(const []), + ), + profileProvider.overrideWith(() => _FakeProfileNotifier()), + channelsProvider.overrideWith(() => _FakeChannelsNotifier()), + ], + child: const SearchPage(), + ), + ); + await tester.pumpAndSettle(); + final channel = find.byKey(const ValueKey('search-channel-row-design')); + final person = find.byKey(const ValueKey('search-person-row-maya')); + expect(channel, findsOneWidget); + expect(person, findsOneWidget); + expect( + tester.widget(_nativeFilter('All')).isSelected, + isTrue, + ); + expect( + tester + .widget(_nativeFilter('Channels')) + .isSelected, + isFalse, + ); + + await _pressNativeFilter(tester, 'Channels'); + await tester.pumpAndSettle(); + + expect( + tester + .widget(_nativeFilter('Channels')) + .isSelected, + isTrue, + ); + expect( + tester.widget(_nativeFilter('All')).isSelected, + isFalse, + ); + expect(channel, findsOneWidget); + expect(person, findsNothing); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox.shrink()); + debugDefaultTargetPlatformOverride = null; + }); + testWidgets('X dismisses search while the keyboard is focused', ( tester, ) async { @@ -783,6 +847,27 @@ void main() { }); } +Finder _nativeFilter(String label) => find.byWidgetPredicate( + (widget) => widget is IosGlassNavigationButton && widget.label == label, +); + +Future _pressNativeFilter(WidgetTester tester, String label) async { + final view = tester.widget( + find.descendant(of: _nativeFilter(label), matching: find.byType(UiKitView)), + ); + // Simulate the engine creating this view, then deliver the native tap through + // the same per-view channel used by the production UIKit control. + const viewId = 42; + view.onPlatformViewCreated!(viewId); + await tester.pump(); + const channel = MethodChannel('buzz/navigation_glass/$viewId'); + await tester.binding.defaultBinaryMessenger.handlePlatformMessage( + channel.name, + channel.codec.encodeMethodCall(const MethodCall('pressed')), + (_) {}, + ); +} + class _FakeSearchNotifier extends SearchNotifier { _FakeSearchNotifier(this.initialState);