@@ -209,19 +209,17 @@ import com.duckduckgo.brokensite.api.BrokenSitePrompt
209
209
import com.duckduckgo.brokensite.api.RefreshPattern
210
210
import com.duckduckgo.browser.api.UserBrowserProperties
211
211
import com.duckduckgo.browser.api.autocomplete.AutoComplete
212
- import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteResult
213
212
import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteDefaultSuggestion
214
213
import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteHistoryRelatedSuggestion.AutoCompleteHistorySearchSuggestion
215
214
import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteHistoryRelatedSuggestion.AutoCompleteHistorySuggestion
216
- import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteSearchSuggestion
217
- import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteUrlSuggestion.AutoCompleteBookmarkSuggestion
218
215
import com.duckduckgo.browser.api.autocomplete.AutoComplete.AutoCompleteSuggestion.AutoCompleteUrlSuggestion.AutoCompleteSwitchToTabSuggestion
219
216
import com.duckduckgo.browser.api.autocomplete.AutoCompleteSettings
220
217
import com.duckduckgo.browser.api.brokensite.BrokenSiteContext
221
218
import com.duckduckgo.common.test.CoroutineTestRule
222
219
import com.duckduckgo.common.test.InstantSchedulersRule
223
220
import com.duckduckgo.common.ui.tabs.SwipingTabsFeature
224
221
import com.duckduckgo.common.ui.tabs.SwipingTabsFeatureProvider
222
+ import com.duckduckgo.common.utils.DefaultDispatcherProvider
225
223
import com.duckduckgo.common.utils.DispatcherProvider
226
224
import com.duckduckgo.common.utils.baseHost
227
225
import com.duckduckgo.common.utils.device.DeviceInfo
@@ -551,6 +549,7 @@ class BrowserTabViewModelTest {
551
549
private val swipingTabsFeature = FakeFeatureToggleFactory .create(SwipingTabsFeature ::class .java)
552
550
private val swipingTabsFeatureProvider = SwipingTabsFeatureProvider (swipingTabsFeature)
553
551
private val mockDuckChat: DuckChat = mock()
552
+ private val mockHistory: NavigationHistory = mock()
554
553
555
554
private val defaultBrowserPromptsExperimentShowPopupMenuItemFlow = MutableStateFlow (false )
556
555
private val mockAdditionalDefaultBrowserPrompts: AdditionalDefaultBrowserPrompts = mock()
@@ -615,6 +614,9 @@ class BrowserTabViewModelTest {
615
614
mockUserStageStore,
616
615
mockAutocompleteTabsFeature,
617
616
mockDuckChat,
617
+ mockHistory,
618
+ DefaultDispatcherProvider (),
619
+ mockPixel,
618
620
)
619
621
val fireproofWebsiteRepositoryImpl = FireproofWebsiteRepositoryImpl (
620
622
fireproofWebsiteDao,
@@ -2454,115 +2456,6 @@ class BrowserTabViewModelTest {
2454
2456
assertCommandIssued<Command .ShowWebContent >()
2455
2457
}
2456
2458
2457
- @Test
2458
- fun whenBookmarkSuggestionSubmittedThenAutoCompleteBookmarkSelectionPixelSent () = runTest {
2459
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true )
2460
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2461
- val suggestion = AutoCompleteBookmarkSuggestion (" example" , " Example" , " https://example.com" )
2462
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , listOf (suggestion)))
2463
- testee.fireAutocompletePixel(suggestion)
2464
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2465
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_BOOKMARK_SELECTION ), argumentCaptor.capture(), any(), any())
2466
-
2467
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SHOWED_BOOKMARKS ])
2468
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .BOOKMARK_CAPABLE ])
2469
- }
2470
-
2471
- @Test
2472
- fun whenBookmarkFavoriteSubmittedThenAutoCompleteFavoriteSelectionPixelSent () = runTest {
2473
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true )
2474
- whenever(mockSavedSitesRepository.hasFavorites()).thenReturn(true )
2475
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2476
- val suggestion = AutoCompleteBookmarkSuggestion (" example" , " Example" , " https://example.com" , isFavorite = true )
2477
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , listOf (suggestion)))
2478
- testee.fireAutocompletePixel(suggestion)
2479
-
2480
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2481
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_FAVORITE_SELECTION ), argumentCaptor.capture(), any(), any())
2482
-
2483
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .SHOWED_BOOKMARKS ])
2484
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SHOWED_FAVORITES ])
2485
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .BOOKMARK_CAPABLE ])
2486
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .FAVORITE_CAPABLE ])
2487
- }
2488
-
2489
- @Test
2490
- fun whenHistorySubmittedThenAutoCompleteHistorySelectionPixelSent () = runTest {
2491
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true )
2492
- whenever(mockNavigationHistory.hasHistory()).thenReturn(true )
2493
- val suggestion = AutoCompleteHistorySearchSuggestion (" example" , true )
2494
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , listOf (suggestion)))
2495
- testee.fireAutocompletePixel(suggestion)
2496
-
2497
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2498
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_HISTORY_SEARCH_SELECTION ), argumentCaptor.capture(), any(), any())
2499
-
2500
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .SHOWED_BOOKMARKS ])
2501
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .BOOKMARK_CAPABLE ])
2502
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SHOWED_HISTORY ])
2503
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .HISTORY_CAPABLE ])
2504
- }
2505
-
2506
- @Test
2507
- fun whenSearchSuggestionSubmittedWithBookmarksThenAutoCompleteSearchSelectionPixelSent () = runTest {
2508
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(true )
2509
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2510
- val suggestions = listOf (AutoCompleteSearchSuggestion (" " , false , false ), AutoCompleteBookmarkSuggestion (" " , " " , " " ))
2511
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , suggestions))
2512
- testee.fireAutocompletePixel(AutoCompleteSearchSuggestion (" example" , false , false ))
2513
-
2514
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2515
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_SEARCH_PHRASE_SELECTION ), argumentCaptor.capture(), any(), any())
2516
-
2517
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SHOWED_BOOKMARKS ])
2518
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .BOOKMARK_CAPABLE ])
2519
- }
2520
-
2521
- @Test
2522
- fun whenSearchSuggestionSubmittedWithoutBookmarksThenAutoCompleteSearchSelectionPixelSent () = runTest {
2523
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false )
2524
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2525
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , emptyList()))
2526
- testee.fireAutocompletePixel(AutoCompleteSearchSuggestion (" example" , false , false ))
2527
-
2528
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2529
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_SEARCH_PHRASE_SELECTION ), argumentCaptor.capture(), any(), any())
2530
-
2531
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .SHOWED_BOOKMARKS ])
2532
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .BOOKMARK_CAPABLE ])
2533
- }
2534
-
2535
- @Test
2536
- fun whenSearchSuggestionSubmittedWithTabsThenAutoCompleteSearchSelectionPixelSent () = runTest {
2537
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false )
2538
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2539
- tabsLiveData.value = listOf (TabEntity (" 1" , " https://example.com" , position = 0 ), TabEntity (" 2" , " https://example.com" , position = 1 ))
2540
- val suggestions = listOf (AutoCompleteSwitchToTabSuggestion (" example" , " " , " " , " " ))
2541
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , suggestions))
2542
- testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion (" example" , " " , " " , " " ))
2543
-
2544
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2545
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION ), argumentCaptor.capture(), any(), any())
2546
-
2547
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SHOWED_SWITCH_TO_TAB ])
2548
- assertEquals(" true" , argumentCaptor.firstValue[PixelParameter .SWITCH_TO_TAB_CAPABLE ])
2549
- }
2550
-
2551
- @Test
2552
- fun whenSearchSuggestionSubmittedWithoutTabsThenAutoCompleteSearchSelectionPixelSent () = runTest {
2553
- whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false )
2554
- whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
2555
- tabsLiveData.value = listOf (TabEntity (" 1" , " https://example.com" , position = 0 ))
2556
- testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult (" " , emptyList()))
2557
- testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion (" example" , " " , " " , " " ))
2558
-
2559
- val argumentCaptor = argumentCaptor<Map <String , String >>()
2560
- verify(mockPixel).fire(eq(AppPixelName .AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION ), argumentCaptor.capture(), any(), any())
2561
-
2562
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .SHOWED_SWITCH_TO_TAB ])
2563
- assertEquals(" false" , argumentCaptor.firstValue[PixelParameter .SWITCH_TO_TAB_CAPABLE ])
2564
- }
2565
-
2566
2459
@Test
2567
2460
fun whenUserSelectToEditQueryThenMoveCaretToTheEnd () = runTest {
2568
2461
testee.onUserSelectedToEditQuery(" foo" )
@@ -6029,7 +5922,10 @@ class BrowserTabViewModelTest {
6029
5922
fun whenUserSelectedAutocompleteWithAutoCompleteSwitchToTabSuggestionThenSwitchToTabCommandSentWithTabId () = runTest {
6030
5923
val tabId = " tabId"
6031
5924
val suggestion = AutoCompleteSwitchToTabSuggestion (phrase = " phrase" , title = " title" , url = " https://www.example.com" , tabId = tabId)
5925
+
5926
+ whenever(mockDuckChat.wasOpenedBefore()).thenReturn(true )
6032
5927
whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false )
5928
+ whenever(mockSavedSitesRepository.hasFavorites()).thenReturn(false )
6033
5929
whenever(mockNavigationHistory.hasHistory()).thenReturn(false )
6034
5930
6035
5931
testee.userSelectedAutocomplete(suggestion)
0 commit comments