From cee2637e7357acf1b5f943b1c0f49eed8668661b Mon Sep 17 00:00:00 2001 From: Lukasz Macionczyk Date: Wed, 28 Aug 2024 17:16:47 +0200 Subject: [PATCH] fix fdroid build --- .../app/browser/BrowserTabViewModelTest.kt | 1 + .../com/duckduckgo/app/cta/ui/CtaViewModelTest.kt | 6 ++++++ .../java/com/duckduckgo/app/cta/ui/CtaViewModel.kt | 13 +++---------- .../app/cta/ui/OnboardingDaxDialogTests.kt | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt b/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt index a9aeb71a9caa..399a84d00f3d 100644 --- a/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt +++ b/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt @@ -536,6 +536,7 @@ class BrowserTabViewModelTest { dispatchers = coroutineRule.testDispatcherProvider, duckDuckGoUrlDetector = DuckDuckGoUrlDetectorImpl(), extendedOnboardingFeatureToggles = mockExtendedOnboardingFeatureToggles, + subscriptions = mock(), ) val siteFactory = SiteFactoryImpl( diff --git a/app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt b/app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt index 9b8565954e48..9c1a09fc94b9 100644 --- a/app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt +++ b/app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt @@ -50,6 +50,7 @@ import com.duckduckgo.app.widget.ui.WidgetCapabilities import com.duckduckgo.common.test.CoroutineTestRule import com.duckduckgo.common.test.InstantSchedulersRule import com.duckduckgo.feature.toggles.api.Toggle +import com.duckduckgo.subscriptions.api.Subscriptions import java.util.concurrent.TimeUnit import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.drop @@ -112,6 +113,9 @@ class CtaViewModelTest { @Mock private lateinit var mockExtendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles + @Mock + private lateinit var mockSubscriptions: Subscriptions + private val requiredDaxOnboardingCtas: List = listOf( CtaId.DAX_INTRO, CtaId.DAX_DIALOG_SERP, @@ -153,6 +157,7 @@ class CtaViewModelTest { dispatchers = coroutineRule.testDispatcherProvider, duckDuckGoUrlDetector = DuckDuckGoUrlDetectorImpl(), extendedOnboardingFeatureToggles = mockExtendedOnboardingFeatureToggles, + subscriptions = mockSubscriptions, ) } @@ -715,6 +720,7 @@ class CtaViewModelTest { @Test fun givenPrivacyProSiteWhenRefreshCtaWhileBrowsingThenReturnNull() = runTest { val privacyProUrl = "https://duckduckgo.com/pro" + whenever(mockSubscriptions.isPrivacyProUrl(privacyProUrl)).thenReturn(true) givenDaxOnboardingActive() val site = site(url = privacyProUrl) diff --git a/app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt b/app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt index 77c7542f11de..844aeda0ea5e 100644 --- a/app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt +++ b/app/src/main/java/com/duckduckgo/app/cta/ui/CtaViewModel.kt @@ -18,7 +18,6 @@ package com.duckduckgo.app.cta.ui import androidx.annotation.VisibleForTesting import androidx.annotation.WorkerThread -import androidx.core.net.toUri import com.duckduckgo.app.browser.DuckDuckGoUrlDetector import com.duckduckgo.app.cta.db.DismissedCtaDao import com.duckduckgo.app.cta.model.CtaId @@ -37,10 +36,8 @@ import com.duckduckgo.app.statistics.pixels.Pixel import com.duckduckgo.app.tabs.model.TabRepository import com.duckduckgo.app.widget.ui.WidgetCapabilities import com.duckduckgo.common.utils.DispatcherProvider -import com.duckduckgo.common.utils.extensions.toTldPlusOne import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.PRIVACY_PRO_ETLD -import com.duckduckgo.subscriptions.impl.SubscriptionsConstants.PRIVACY_PRO_PATH +import com.duckduckgo.subscriptions.api.Subscriptions import dagger.SingleInstanceIn import javax.inject.Inject import kotlin.coroutines.CoroutineContext @@ -64,6 +61,7 @@ class CtaViewModel @Inject constructor( private val dispatchers: DispatcherProvider, private val duckDuckGoUrlDetector: DuckDuckGoUrlDetector, private val extendedOnboardingFeatureToggles: ExtendedOnboardingFeatureToggles, + private val subscriptions: Subscriptions, ) { @ExperimentalCoroutinesApi @VisibleForTesting @@ -291,12 +289,7 @@ class CtaViewModel @Inject constructor( } private fun isSiteNotAllowedForOnboarding(url: String?): Boolean { - val uri = url?.toUri() ?: return true - val eTld = uri.host?.toTldPlusOne() ?: return false - val size = uri.pathSegments.size - val path = uri.pathSegments.firstOrNull() - val isPrivacyProSite = eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH - return isPrivacyProSite + return url == null || subscriptions.isPrivacyProUrl(url) } private fun daxDialogIntroShown(): Boolean = dismissedCtaDao.exists(CtaId.DAX_INTRO) diff --git a/app/src/test/java/com/duckduckgo/app/cta/ui/OnboardingDaxDialogTests.kt b/app/src/test/java/com/duckduckgo/app/cta/ui/OnboardingDaxDialogTests.kt index 1cb063c0608b..da55d36df2cf 100644 --- a/app/src/test/java/com/duckduckgo/app/cta/ui/OnboardingDaxDialogTests.kt +++ b/app/src/test/java/com/duckduckgo/app/cta/ui/OnboardingDaxDialogTests.kt @@ -85,6 +85,7 @@ class OnboardingDaxDialogTests { dismissedCtaDao, userAllowListRepository, settingsDataStore, onboardingStore, userStageStore, tabRepository, dispatchers, duckDuckGoUrlDetector, extendedOnboardingFeatureToggles, + subscriptions = mock(), ) }