-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support skipping onboarding with gradle build flag
- Loading branch information
Showing
11 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/duckduckgo/app/onboarding/ui/FullOnboardingSkipper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.app.onboarding.ui | ||
|
||
import com.duckduckgo.app.cta.db.DismissedCtaDao | ||
import com.duckduckgo.app.cta.model.CtaId | ||
import com.duckduckgo.app.cta.model.DismissedCta | ||
import com.duckduckgo.app.onboarding.store.AppStage | ||
import com.duckduckgo.app.onboarding.store.UserStageStore | ||
import com.duckduckgo.app.onboarding.ui.FullOnboardingSkipper.ViewState | ||
import com.duckduckgo.app.settings.db.SettingsDataStore | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.SingleInstanceIn | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.withContext | ||
|
||
interface OnboardingSkipper { | ||
suspend fun markOnboardingAsCompleted() | ||
val privacyConfigDownloaded: SharedFlow<ViewState> | ||
} | ||
|
||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = PrivacyConfigCallbackPlugin::class, | ||
) | ||
@ContributesBinding(AppScope::class, OnboardingSkipper::class) | ||
@SingleInstanceIn(AppScope::class) | ||
class FullOnboardingSkipper @Inject constructor( | ||
private val dispatchers: DispatcherProvider, | ||
private val settingsDataStore: SettingsDataStore, | ||
private val dismissedCtaDao: DismissedCtaDao, | ||
private val userStageStore: UserStageStore, | ||
) : OnboardingSkipper, PrivacyConfigCallbackPlugin { | ||
|
||
private val _privacyConfigDownloaded = MutableStateFlow(ViewState()) | ||
override val privacyConfigDownloaded = _privacyConfigDownloaded.asStateFlow() | ||
|
||
@Suppress("DEPRECATION") | ||
override suspend fun markOnboardingAsCompleted() { | ||
withContext(dispatchers.io()) { | ||
settingsDataStore.hideTips = true | ||
dismissedCtaDao.insert(DismissedCta(CtaId.ADD_WIDGET)) | ||
userStageStore.stageCompleted(AppStage.DAX_ONBOARDING) | ||
} | ||
} | ||
|
||
override fun onPrivacyConfigDownloaded() { | ||
_privacyConfigDownloaded.value = ViewState(skipOnboardingPossible = true) | ||
} | ||
|
||
data class ViewState( | ||
val skipOnboardingPossible: Boolean = false, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/src/test/java/com/duckduckgo/app/onboarding/ui/FullOnboardingSkipperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.duckduckgo.app.onboarding.ui | ||
|
||
import app.cash.turbine.test | ||
import com.duckduckgo.app.cta.db.DismissedCtaDao | ||
import com.duckduckgo.app.cta.model.CtaId.ADD_WIDGET | ||
import com.duckduckgo.app.cta.model.DismissedCta | ||
import com.duckduckgo.app.onboarding.store.AppStage.DAX_ONBOARDING | ||
import com.duckduckgo.app.onboarding.store.UserStageStore | ||
import com.duckduckgo.app.settings.db.SettingsDataStore | ||
import com.duckduckgo.common.test.CoroutineTestRule | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.times | ||
import org.mockito.kotlin.verify | ||
|
||
@Suppress("DEPRECATION") | ||
class FullOnboardingSkipperTest { | ||
|
||
@get:Rule | ||
val coroutineTestRule: CoroutineTestRule = CoroutineTestRule() | ||
|
||
private val dismissedCtaDao: DismissedCtaDao = mock() | ||
private val userStageStore: UserStageStore = mock() | ||
private val settingsDataStore: SettingsDataStore = mock() | ||
|
||
private val testee = FullOnboardingSkipper( | ||
dispatchers = coroutineTestRule.testDispatcherProvider, | ||
settingsDataStore = settingsDataStore, | ||
dismissedCtaDao = dismissedCtaDao, | ||
userStageStore = userStageStore, | ||
) | ||
|
||
@Test | ||
fun whenPrivacyConfigNotYetDownloadedThenCannotSkipOnboarding() = runTest { | ||
// checking value before privacy config downloaded | ||
testee.privacyConfigDownloaded.test { | ||
assertFalse(awaitItem().skipOnboardingPossible) | ||
} | ||
} | ||
|
||
@Test | ||
fun whenPrivacyConfigDownloadedThenViewStateUpdated() = runTest { | ||
testee.onPrivacyConfigDownloaded() | ||
testee.privacyConfigDownloaded.test { | ||
assertTrue(awaitItem().skipOnboardingPossible) | ||
} | ||
} | ||
|
||
@Test | ||
fun whenSkipperInvokedToMarkOnboardingDoneThenAllOnboardingStoresUpdated() = runTest { | ||
testee.markOnboardingAsCompleted() | ||
verifyStoreInvocations(expectingToBeCalled = true) | ||
} | ||
|
||
private suspend fun verifyStoreInvocations(expectingToBeCalled: Boolean) { | ||
val verificationMode = if (expectingToBeCalled) times(1) else never() | ||
|
||
verify(settingsDataStore, verificationMode).hideTips = true | ||
verify(dismissedCtaDao, verificationMode).insert(DismissedCta(ADD_WIDGET)) | ||
verify(userStageStore, verificationMode).stageCompleted(DAX_ONBOARDING) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters