Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/app_center/lib/search/search_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ class _SearchFieldState extends ConsumerState<SearchField> {
return RawAutocomplete<AutoCompleteOption>(
optionsBuilder: (query) async {
ref.read(queryProvider.notifier).state = query.text;
final options = await ref.watch(autoCompleteProvider.future);
final AutoCompleteOptions options;
try {
options = await ref.watch(autoCompleteProvider.future);
} on Exception {
return <AutoCompleteOption>[];
}
if (options.snaps.isEmpty && options.debs.isEmpty) return [];
_optionsAvailable = true;
final snapOptions = options.snaps
Expand Down
29 changes: 29 additions & 0 deletions packages/app_center/test/search_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,33 @@ void main() {
verifyNever(mockSelectedCallback(any));
});
});

group('error handling', () {
testWidgets('gracefully handles autocomplete error', (tester) async {
await tester.pumpApp(
(_) => ProviderScope(
overrides: [
snapSearchProvider.overrideWith(
(ref, searchParameters) =>
Stream.error(Exception('Network error')),
),
appstreamSearchProvider
.overrideWith((ref, query) => Stream.value([])),
],
child: SearchField(
onSearch: (_) {},
onSnapSelected: (_) {},
onDebSelected: (_) {},
searchFocus: FocusNode(),
),
),
);

final textField = find.byType(TextField);
await tester.enterText(textField, 'test');
await tester.pumpAndSettle();

expect(find.byType(TextField), findsOneWidget);
});
});
}
Loading