Skip to content

Commit 24ed894

Browse files
authored
Merge pull request #6662 from woocommerce/issue/6644-order-country-keyboard-suggestion-bug
[Order Creation] Handle keyboard predictive text entry for country and state selectors
2 parents d5586d2 + fd3d195 commit 24ed894

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/CountrySelectorCommand.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class CountrySelectorCommand: ObservableListSelectorCommand {
4848
return data = countries
4949
}
5050

51-
data = countries.filter { $0.name.localizedCaseInsensitiveContains(term) }
51+
// Trim the search term to remove newlines or whitespaces (e.g added from the keyboard predictive text) from both ends
52+
data = countries.filter { $0.name.localizedCaseInsensitiveContains(term.trim()) }
5253
}
5354
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/StateSelectorCommand.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class StateSelectorCommand: ObservableListSelectorCommand {
4848
return data = states
4949
}
5050

51-
data = states.filter { $0.name.localizedCaseInsensitiveContains(term) }
51+
// Trim the search term to remove newlines or whitespaces (e.g added from the keyboard predictive text) from both ends
52+
data = states.filter { $0.name.localizedCaseInsensitiveContains(term.trim()) }
5253
}
5354
}

WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/CountrySelector/CountrySelectorViewModelTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ final class CountrySelectorViewModelTests: XCTestCase {
4040
])
4141
}
4242

43+
func test_filter_term_with_last_character_whitespace_return_expected_result() {
44+
// Given
45+
let binding = Binding<Country?>(get: { nil }, set: { _ in })
46+
let viewModel = CountrySelectorViewModel(countries: Self.sampleCountries, selected: binding)
47+
48+
// When
49+
viewModel.searchTerm = "Indonesia "
50+
let countries = viewModel.command.data.map { $0.name }
51+
52+
// Then
53+
assertEqual(countries, [
54+
"Indonesia"
55+
])
56+
}
57+
58+
func test_filter_term_with_last_character_newline_return_expected_result() {
59+
// Given
60+
let binding = Binding<Country?>(get: { nil }, set: { _ in })
61+
let viewModel = CountrySelectorViewModel(countries: Self.sampleCountries, selected: binding)
62+
63+
// When
64+
viewModel.searchTerm = "Indonesia\n"
65+
let countries = viewModel.command.data.map { $0.name }
66+
67+
// Then
68+
assertEqual(countries, [
69+
"Indonesia"
70+
])
71+
}
72+
4373
func test_filter_countries_with_uppercase_letters_return_expected_results() {
4474
// Given
4575
let binding = Binding<Country?>(get: { nil }, set: { _ in })

0 commit comments

Comments
 (0)