Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Nov 7, 2024
1 parent dc0ea27 commit 9c1542a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ import com.duckduckgo.app.browser.newtab.FavoritesQuickAccessAdapter
import com.duckduckgo.app.browser.newtab.FavoritesQuickAccessAdapter.QuickAccessFavorite
import com.duckduckgo.app.browser.omnibar.ChangeOmnibarPositionFeature
import com.duckduckgo.app.browser.omnibar.OmnibarEntryConverter
import com.duckduckgo.app.browser.omnibar.QueryOrigin.FromUser
import com.duckduckgo.app.browser.omnibar.model.OmnibarPosition.BOTTOM
import com.duckduckgo.app.browser.omnibar.model.OmnibarPosition.TOP
import com.duckduckgo.app.browser.refreshpixels.RefreshPixelSender
Expand Down Expand Up @@ -748,13 +747,6 @@ class BrowserTabViewModelTest {
assertTrue(commandCaptor.allValues.contains(Command.HideKeyboard))
}

@Test
fun whenViewBecomesVisibleThenc() {
setBrowserShowing(true)
testee.onViewVisible()
verify(mockBrokenSitePrompt).resetRefreshCount()
}

@Test
fun whenViewBecomesVisibleAndHomeShowingThenRefreshCtaIsCalled() {
runTest {
Expand Down Expand Up @@ -792,16 +784,6 @@ class BrowserTabViewModelTest {
assertCommandIssued<Command.ShowErrorWithAction>()
}

@Test
fun whenSubmittedQueryThenResetRefreshCount() {
whenever(mockSpecialUrlDetector.determineType(anyString())).thenReturn(SpecialUrlDetector.UrlType.Web("https://example.com"))
whenever(mockOmnibarConverter.convertQueryToUrl(any(), eq(null), eq(FromUser))).thenReturn("https://example.com")

testee.onUserSubmittedQuery("https://example.com")

verify(mockBrokenSitePrompt).resetRefreshCount()
}

@Test
fun whenSubmittedQueryIsPrivacyProThenSendLaunchPrivacyProComment() {
whenever(mockSpecialUrlDetector.determineType(anyString())).thenReturn(SpecialUrlDetector.UrlType.ShouldLaunchPrivacyProLink)
Expand Down Expand Up @@ -2456,13 +2438,6 @@ class BrowserTabViewModelTest {
verify(mockPixel).fire(AppPixelName.TAB_MANAGER_NEW_TAB_LONG_PRESSED)
}

@Test
fun whenCloseCurrentTabThenResetRefreshCount() = runTest {
givenOneActiveTabSelected()
testee.closeCurrentTab()
verify(mockBrokenSitePrompt).resetRefreshCount()
}

@Test
fun whenCloseCurrentTabSelectedThenTabDeletedFromRepository() = runTest {
givenOneActiveTabSelected()
Expand Down Expand Up @@ -5398,10 +5373,14 @@ class BrowserTabViewModelTest {

@Test
fun whenRefreshIsTriggeredByUserThenIncrementRefreshCount() = runTest {
val url = "http://example.com"
givenCurrentSite(url)

testee.onRefreshRequested(triggeredByUser = false)
verify(mockBrokenSitePrompt, never()).incrementRefreshCount()
verify(mockBrokenSitePrompt, never()).pageLoaded(any())

testee.onRefreshRequested(triggeredByUser = true)
verify(mockBrokenSitePrompt).incrementRefreshCount()
verify(mockBrokenSitePrompt).pageLoaded(url.toUri())
}

@Test
Expand Down Expand Up @@ -6041,14 +6020,6 @@ class BrowserTabViewModelTest {
assertCommandIssued<HideBrokenSitePromptCta>()
}

@Test
fun whenNewPageThenResetRefreshCount() = runTest {
testee.browserViewState.value = browserViewState().copy(browserShowing = true)
testee.navigationStateChanged(buildWebNavigation("https://example.com"))

verify(mockBrokenSitePrompt).resetRefreshCount()
}

@Test
fun whenUrlUpdatedWithUrlYouTubeNoCookieThenReplaceUrlWithDuckPlayer() = runTest {
whenever(mockDuckPlayer.isSimulatedYoutubeNoCookie("https://youtube-nocookie.com/?videoID=1234".toUri())).thenReturn(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.duckduckgo.brokensite.impl

import android.annotation.SuppressLint
import android.net.Uri
import com.duckduckgo.common.utils.CurrentTimeProvider
import com.duckduckgo.feature.toggles.api.FakeFeatureToggleFactory
import com.duckduckgo.feature.toggles.api.Toggle.State
Expand Down Expand Up @@ -114,10 +115,12 @@ class RealBrokenSitePromptTest {
@Test
fun whenIncrementRefreshCountThenAddRefreshCalled() {
val now = LocalDateTime.now()
val url: Uri = org.mockito.kotlin.mock()

whenever(mockCurrentTimeProvider.localDateTimeNow()).thenReturn(now)
testee.incrementRefreshCount()
testee.pageLoaded(url)

verify(mockBrokenSiteReportRepository).addRefresh(any())
verify(mockBrokenSiteReportRepository).addRefresh(url, now)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.brokensite.impl

import android.net.Uri
import com.duckduckgo.brokensite.store.BrokenSiteDao
import com.duckduckgo.brokensite.store.BrokenSiteDatabase
import com.duckduckgo.brokensite.store.BrokenSiteLastSentReportEntity
Expand Down Expand Up @@ -189,10 +190,11 @@ class RealBrokenSiteReportRepositoryTest {
@Test
fun whenAddRefreshCalledThenAddRefreshIsCalled() = runTest {
val localDateTime = LocalDateTime.now()
val url: Uri = mock()

testee.addRefresh(localDateTime)
testee.addRefresh(url, localDateTime)

verify(mockInMemoryStore).addRefresh(localDateTime)
verify(mockInMemoryStore).addRefresh(url, localDateTime)
}

@Test
Expand Down

0 comments on commit 9c1542a

Please sign in to comment.