File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed
Classes/ViewRelated/Orders/Order Details/Address Edit
WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/CountrySelector Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 } )
You can’t perform that action at this time.
0 commit comments