Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.core.net.toUri
import com.duckduckgo.app.autocomplete.AutocompleteTabsFeature
import com.duckduckgo.app.autocomplete.impl.AutoCompletePixelNames
import com.duckduckgo.app.autocomplete.impl.AutoCompleteRepository
import com.duckduckgo.app.autocomplete.impl.AutocompletePixelParams
import com.duckduckgo.app.browser.UriString
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.onboarding.store.AppStage
Expand Down Expand Up @@ -304,7 +303,7 @@ class AutoCompleteApi constructor(
val hasFavoriteResults = suggestions.any { it is AutoCompleteBookmarkSuggestion && it.isFavorite }
val hasHistoryResults = suggestions.any { it is AutoCompleteHistorySuggestion || it is AutoCompleteHistorySearchSuggestion }
val hasSwitchToTabResults = suggestions.any { it is AutoCompleteSwitchToTabSuggestion }
val params = mutableMapOf(
val params = mapOf(
PixelParameter.SHOWED_BOOKMARKS to hasBookmarkResults.toString(),
PixelParameter.SHOWED_FAVORITES to hasFavoriteResults.toString(),
PixelParameter.BOOKMARK_CAPABLE to hasBookmarks.toString(),
Expand Down Expand Up @@ -345,11 +344,6 @@ class AutoCompleteApi constructor(
else -> return
}

if (suggestion is AutoCompleteSearchSuggestion) {
val clickedSearchSuggestionIndex = suggestions.filter { it is AutoCompleteSearchSuggestion }.indexOf(suggestion)
params[AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX] = clickedSearchSuggestionIndex.toString()
}

pixel.fire(pixelName, params)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,3 @@ class AutocompleteParamRemovalPlugin @Inject constructor() : PixelParamRemovalPl
)
}
}

object AutocompletePixelParams {
/**
* Parameter to capture the index of the selected suggestion within the list of search suggestions
* (either [AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_PHRASE_SELECTION] or [AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION]).
*/
const val PARAM_SEARCH_SUGGESTION_INDEX = "search_suggestion_index"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.duckduckgo.app.autocomplete.AutocompleteTabsFeature
import com.duckduckgo.app.autocomplete.impl.AutoCompletePixelNames
import com.duckduckgo.app.autocomplete.impl.AutoCompleteRepository
import com.duckduckgo.app.autocomplete.impl.AutocompletePixelParams
import com.duckduckgo.app.onboarding.store.AppStage
import com.duckduckgo.app.onboarding.store.AppStage.NEW
import com.duckduckgo.app.onboarding.store.UserStageStore
Expand Down Expand Up @@ -1882,120 +1881,6 @@ class AutoCompleteApiTest {
assertEquals("false", argumentCaptor.firstValue[PixelParameter.SWITCH_TO_TAB_CAPABLE])
}

@Test
fun `when search suggestion clicked then search suggestion index parameter is added`() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
whenever(mockHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))

val suggestions = listOf(
AutoCompleteSearchSuggestion("first", isUrl = false, isAllowedInTopHits = false),
AutoCompleteSearchSuggestion("second", isUrl = false, isAllowedInTopHits = false),
AutoCompleteSearchSuggestion("third", isUrl = false, isAllowedInTopHits = false),
)
val clickedSuggestion = suggestions[1] // second suggestion (index 1)

testee.fireAutocompletePixel(suggestions, clickedSuggestion)

val argumentCaptor = argumentCaptor<Map<String, String>>()
Mockito.verify(mockPixel).fire(eq(AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_PHRASE_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("1", argumentCaptor.firstValue[AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX])
}

@Test
fun `when search website suggestion clicked then search suggestion index parameter is added`() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
whenever(mockHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))

val suggestions = listOf(
AutoCompleteSearchSuggestion("first", isUrl = false, isAllowedInTopHits = false),
AutoCompleteSearchSuggestion("second", isUrl = false, isAllowedInTopHits = false),
AutoCompleteSearchSuggestion("third", isUrl = true, isAllowedInTopHits = false), // isUrl = true for website suggestion
)
val clickedSuggestion = suggestions[2] // third suggestion (index 2)

testee.fireAutocompletePixel(suggestions, clickedSuggestion)

val argumentCaptor = argumentCaptor<Map<String, String>>()
Mockito.verify(mockPixel).fire(eq(AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("2", argumentCaptor.firstValue[AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX])
}

@Test
fun `when non search suggestion clicked then search suggestion index parameter is not added`() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
whenever(mockHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))

val suggestions = listOf(
AutoCompleteSearchSuggestion("first", isUrl = false, isAllowedInTopHits = false),
AutoCompleteBookmarkSuggestion("bookmark", "title", "url"),
AutoCompleteSearchSuggestion("second", isUrl = false, isAllowedInTopHits = false),
)
val clickedSuggestion = AutoCompleteBookmarkSuggestion("bookmark", "title", "url")

testee.fireAutocompletePixel(suggestions, clickedSuggestion)

val argumentCaptor = argumentCaptor<Map<String, String>>()
Mockito.verify(mockPixel).fire(eq(AutoCompletePixelNames.AUTOCOMPLETE_BOOKMARK_SELECTION), argumentCaptor.capture(), any(), any())

assertFalse(argumentCaptor.firstValue.containsKey(AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX))
}

@Test
fun `when search suggestion clicked with mixed suggestions then correct index is calculated`() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
whenever(mockHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))

val suggestions = listOf(
AutoCompleteBookmarkSuggestion("bookmark1", "title1", "url1"),
AutoCompleteSearchSuggestion("first", isUrl = false, isAllowedInTopHits = false),
AutoCompleteBookmarkSuggestion("bookmark2", "title2", "url2"),
AutoCompleteSearchSuggestion("second", isUrl = false, isAllowedInTopHits = false),
AutoCompleteSearchSuggestion("third", isUrl = false, isAllowedInTopHits = false),
)
val clickedSuggestion = suggestions[4] // third search suggestion (index 2 among search suggestions)

testee.fireAutocompletePixel(suggestions, clickedSuggestion)

val argumentCaptor = argumentCaptor<Map<String, String>>()
Mockito.verify(mockPixel).fire(eq(AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_PHRASE_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("2", argumentCaptor.firstValue[AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX])
}

@Test
fun `when search website suggestion clicked with mixed suggestions then correct index is calculated`() = runTest {
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true)
whenever(mockNavigationHistory.hasHistory()).thenReturn(false)
whenever(mockHistory.hasHistory()).thenReturn(false)
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))

val suggestions = listOf(
AutoCompleteBookmarkSuggestion("bookmark1", "title1", "url1"),
AutoCompleteSearchSuggestion("first", isUrl = true, isAllowedInTopHits = true), // isUrl = true for website suggestion
AutoCompleteBookmarkSuggestion("bookmark2", "title2", "url2"),
AutoCompleteSearchSuggestion("second", isUrl = true, isAllowedInTopHits = false), // isUrl = true for website suggestion
AutoCompleteSearchSuggestion("third", isUrl = false, isAllowedInTopHits = true),
)
val clickedSuggestion = suggestions[3] // second search suggestion (index 1 among search suggestions)

testee.fireAutocompletePixel(suggestions, clickedSuggestion)

val argumentCaptor = argumentCaptor<Map<String, String>>()
Mockito.verify(mockPixel).fire(eq(AutoCompletePixelNames.AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION), argumentCaptor.capture(), any(), any())

assertEquals("1", argumentCaptor.firstValue[AutocompletePixelParams.PARAM_SEARCH_SUGGESTION_INDEX])
}

@Test
fun whenShowInstalledAppsDisabledThenNoDeviceAppResultsReturned() = runTest {
val testee = createTestee(AutoComplete.Config(showInstalledApps = false))
Expand Down
Loading