Skip to content

Commit

Permalink
Removed rxjava from autosuggest.
Browse files Browse the repository at this point in the history
  • Loading branch information
anikiki committed Oct 10, 2024
1 parent 418720f commit 60cab4e
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.duckduckgo.adclick.api.AdClickManager
import com.duckduckgo.app.ValueCaptorObserver
import com.duckduckgo.app.accessibility.data.AccessibilitySettingsDataStore
import com.duckduckgo.app.accessibility.data.AccessibilitySettingsSharedPreferences
import com.duckduckgo.app.autocomplete.AutocompleteTabsFeature
import com.duckduckgo.app.autocomplete.api.AutoComplete
import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteResult
import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion.AutoCompleteDefaultSuggestion
Expand Down Expand Up @@ -231,9 +232,6 @@ import com.duckduckgo.sync.api.favicons.FaviconsFetchingPrompt
import com.duckduckgo.voice.api.VoiceSearchAvailability
import com.duckduckgo.voice.api.VoiceSearchAvailabilityPixelLogger
import dagger.Lazy
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.observers.TestObserver
import java.io.File
import java.math.BigInteger
import java.security.cert.X509Certificate
Expand Down Expand Up @@ -479,6 +477,7 @@ class BrowserTabViewModelTest {
private val mockExtendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles = mock()
private val mockUserBrowserProperties: UserBrowserProperties = mock()
private val mockAutoCompleteRepository: AutoCompleteRepository = mock()
private val mockAutocompleteTabsFeature: AutocompleteTabsFeature = mock()

@Before
fun before() = runTest {
Expand All @@ -498,6 +497,7 @@ class BrowserTabViewModelTest {
mockTabRepository,
mockUserStageStore,
coroutineRule.testDispatcherProvider,
mockAutocompleteTabsFeature,
)
val fireproofWebsiteRepositoryImpl = FireproofWebsiteRepositoryImpl(
fireproofWebsiteDao,
Expand All @@ -524,6 +524,8 @@ class BrowserTabViewModelTest {
whenever(mockDuckPlayer.isSimulatedYoutubeNoCookie(anyString())).thenReturn(false)
whenever(mockDuckPlayer.isDuckPlayerUri(anyString())).thenReturn(false)
whenever(mockDuckPlayer.getDuckPlayerState()).thenReturn(ENABLED)
whenever(mockAutocompleteTabsFeature.self()).thenReturn(mockEnabledToggle)
whenever(mockAutocompleteTabsFeature.self().isEnabled()).thenReturn(true)

remoteMessagingModel = givenRemoteMessagingModel(mockRemoteMessagingRepository, mockPixel, coroutineRule.testDispatcherProvider)

Expand Down Expand Up @@ -1376,8 +1378,8 @@ class BrowserTabViewModelTest {
}

@Test
fun whenTriggeringAutocompleteThenAutoCompleteSuggestionsShown() {
whenever(mockAutoCompleteService.autoComplete("foo")).thenReturn(Observable.just(emptyList()))
fun whenTriggeringAutocompleteThenAutoCompleteSuggestionsShown() = runTest {
whenever(mockAutoCompleteService.autoComplete("foo")).thenReturn(emptyList())
doReturn(true).whenever(mockSettingsStore).autoCompleteSuggestionsEnabled
testee.triggerAutocomplete("foo", true, hasQueryChanged = true)
assertTrue(autoCompleteViewState().showSuggestions)
Expand Down Expand Up @@ -1436,18 +1438,18 @@ class BrowserTabViewModelTest {
@Test
fun wheneverAutoCompleteIsGoneAndHistoryIAMHasBeenShownThenNotifyUserSeenIAM() {
runTest {
whenever(mockAutoCompleteService.autoComplete("title")).thenReturn(Observable.just(emptyList()))
whenever(mockSavedSitesRepository.getBookmarksObservable()).thenReturn(
Single.just(listOf(Bookmark("abc", "title", "https://example.com", lastModified = null))),
whenever(mockAutoCompleteService.autoComplete("title")).thenReturn(emptyList())
whenever(mockSavedSitesRepository.getBookmarks()).thenReturn(
flowOf(listOf(Bookmark("abc", "title", "https://example.com", lastModified = null))),
)
whenever(mockSavedSitesRepository.getFavoritesObservable()).thenReturn(
Single.just(listOf(Favorite("abc", "title", "https://example.com", position = 1, lastModified = null))),
whenever(mockSavedSitesRepository.getFavorites()).thenReturn(
flowOf(listOf(Favorite("abc", "title", "https://example.com", position = 1, lastModified = null))),
)
whenever(mockNavigationHistory.getHistorySingle()).thenReturn(
Single.just(listOf(VisitedPage("https://foo.com".toUri(), "title", listOf(LocalDateTime.now())))),
whenever(mockNavigationHistory.getHistory()).thenReturn(
flowOf(listOf(VisitedPage("https://foo.com".toUri(), "title", listOf(LocalDateTime.now())))),
)
whenever(mockTabRepository.getTabsObservable()).thenReturn(
Single.just(listOf(TabEntity(tabId = "1", position = 1, url = "https://example.com", title = "title"))),
whenever(mockTabRepository.flowTabs).thenReturn(
flowOf(listOf(TabEntity(tabId = "1", position = 1, url = "https://example.com", title = "title"))),
)
doReturn(true).whenever(mockSettingsStore).autoCompleteSuggestionsEnabled

Expand All @@ -1456,7 +1458,7 @@ class BrowserTabViewModelTest {
whenever(mockAutoCompleteScorer.score("title", "https://foo.com".toUri(), 1, "title")).thenReturn(1)
whenever(mockUserStageStore.getUserAppStage()).thenReturn(ESTABLISHED)

testee.autoCompletePublishSubject.accept("title")
testee.autoCompleteStateFlow.value = "title"
testee.autoCompleteSuggestionsGone()
verify(mockAutoCompleteRepository).submitUserSeenHistoryIAM()
verify(mockPixel).fire(AUTOCOMPLETE_BANNER_SHOWN)
Expand All @@ -1466,16 +1468,16 @@ class BrowserTabViewModelTest {
@Test
fun wheneverAutoCompleteIsGoneAndHistoryIAMHasNotBeenShownThenDoNotNotifyUserSeenIAM() {
runTest {
whenever(mockAutoCompleteService.autoComplete("query")).thenReturn(Observable.just(emptyList()))
whenever(mockSavedSitesRepository.getBookmarksObservable()).thenReturn(
Single.just(listOf(Bookmark("abc", "title", "https://example.com", lastModified = null))),
whenever(mockAutoCompleteService.autoComplete("query")).thenReturn(emptyList())
whenever(mockSavedSitesRepository.getBookmarks()).thenReturn(
flowOf(listOf(Bookmark("abc", "title", "https://example.com", lastModified = null))),
)
whenever(mockSavedSitesRepository.getFavoritesObservable()).thenReturn(
Single.just(listOf(Favorite("abc", "title", "https://example.com", position = 1, lastModified = null))),
whenever(mockSavedSitesRepository.getFavorites()).thenReturn(
flowOf(listOf(Favorite("abc", "title", "https://example.com", position = 1, lastModified = null))),
)
whenever(mockNavigationHistory.getHistorySingle()).thenReturn(Single.just(listOf()))
whenever(mockNavigationHistory.getHistory()).thenReturn(flowOf(emptyList()))
doReturn(true).whenever(mockSettingsStore).autoCompleteSuggestionsEnabled
testee.autoCompletePublishSubject.accept("query")
testee.autoCompleteStateFlow.value = "query"
testee.autoCompleteSuggestionsGone()
verify(mockAutoCompleteRepository, never()).submitUserSeenHistoryIAM()
verify(mockPixel, never()).fire(AUTOCOMPLETE_BANNER_SHOWN)
Expand Down Expand Up @@ -5793,14 +5795,10 @@ class BrowserTabViewModelTest {
val suggestion = AutoCompleteHistorySuggestion(phrase = "phrase", title = "title", url = "url", isAllowedInTopHits = false)
val omnibarText = "foo"

val testObserver = TestObserver.create<String>()
testee.autoCompletePublishSubject.subscribe(testObserver)

testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED)
verify(mockNavigationHistory).removeHistoryEntryByUrl(suggestion.url)
testObserver.assertValue(omnibarText)
assertCommandIssued<Command.AutocompleteItemRemoved>()
}

Expand All @@ -5809,14 +5807,10 @@ class BrowserTabViewModelTest {
val suggestion = AutoCompleteHistorySearchSuggestion(phrase = "phrase", isAllowedInTopHits = false)
val omnibarText = "foo"

val testObserver = TestObserver.create<String>()
testee.autoCompletePublishSubject.subscribe(testObserver)

testee.onRemoveSearchSuggestionConfirmed(suggestion, omnibarText)

verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_RESULT_DELETED)
verify(mockNavigationHistory).removeHistoryEntryByQuery(suggestion.phrase)
testObserver.assertValue(omnibarText)
assertCommandIssued<Command.AutocompleteItemRemoved>()
}

Expand Down
Loading

0 comments on commit 60cab4e

Please sign in to comment.