Skip to content

Commit

Permalink
Merge pull request #16282 from wordpress-mobile/fix/site-intent-quest…
Browse files Browse the repository at this point in the history
…ion-fixes

[Site Intent Question] String corrections and input sanitisation
  • Loading branch information
mkevins authored Apr 11, 2022
2 parents 7733ca6 + f181548 commit ad8cf9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class SiteCreationIntentsViewModel @Inject constructor(
}
}

fun onSearchTextChanged(query: String) {
fun onSearchTextChanged(userInput: String) {
val query = userInput.trim()
val searchResults = searchResultsProvider.search(fullItemsList.items, query).toMutableList().apply {
val isAnExactMatch = query.isNotEmpty() && !(size == 1 && this[0].verticalText.equals(query, true))
if (isAnExactMatch) {
Expand Down
4 changes: 2 additions & 2 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3206,8 +3206,8 @@
<string name="site_creation_error_generic_subtitle">Error communicating with the server, please try again</string>
<string name="new_site_creation_intents_title">Site topic</string>
<string name="new_site_creation_intents_header_title">What’s your website about?</string>
<string name="new_site_creation_intents_header_subtitle">Choose a topic from the list below or type your own</string>
<string name="new_site_creation_intents_input_hint">Eg. Fashion, Poetry, Politics</string>
<string name="new_site_creation_intents_header_subtitle">Choose a topic from the list below or type your own.</string>
<string name="new_site_creation_intents_input_hint">E.g. Fashion, Poetry, Politics</string>
<string name="new_site_creation_empty_domain_list_message">No available addresses matching your search</string>
<string name="new_site_creation_empty_domain_list_message_invalid_query">Your search includes characters not supported in WordPress.com domains. The following characters are allowed: A–Z, a–z, 0–9.</string>
<string name="new_site_creation_unavailable_domain">This domain is unavailable</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ class SiteCreationIntentsViewModelTest {
}

@Test
fun `when there are matching search results but not exact the custom vertical is not visible`() {
fun `when the user types white spaces at the beginning or the end of the input those are ignored`() {
val valueOfSearchInput = " \n test1 \n"
val matchingItem = "Test1"
whenever(resources.getStringArray(any())).thenReturn(arrayOf(matchingItem, "Test2", "Test3"))
viewModel.initializeFromResources(resources)
viewModel.onSearchTextChanged(valueOfSearchInput)
assertThat(viewModel.uiState.value?.content?.items?.size).isEqualTo(1)
assertThat(viewModel.uiState.value?.content?.items?.firstOrNull()?.verticalText).isEqualTo("Test1")
}

@Test
fun `when there are matching search results but not exact the custom vertical is visible`() {
val valueOfSearchInput = "test"
val matchingItem = "Test1"
whenever(resources.getStringArray(any())).thenReturn(arrayOf(matchingItem, "Test2", "Test3"))
Expand All @@ -120,6 +131,15 @@ class SiteCreationIntentsViewModelTest {
.isEqualTo(valueOfSearchInput)
}

@Test
fun `when the user types white spaces the custom vertical is not visible`() {
val valueOfSearchInput = " \n "
whenever(resources.getStringArray(any())).thenReturn(arrayOf("Test1", "Test2", "Test3"))
viewModel.initializeFromResources(resources)
viewModel.onSearchTextChanged(valueOfSearchInput)
assertThat(viewModel.uiState.value?.content?.items?.size).isEqualTo(3)
}

@Test
fun `when there are no search results the custom vertical is visible`() {
val valueOfSearchInput = "test1"
Expand Down

0 comments on commit ad8cf9e

Please sign in to comment.