-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional "default browser" prompts: variant 2
- Loading branch information
1 parent
9e34116
commit 4a97b9f
Showing
23 changed files
with
2,317 additions
and
17 deletions.
There are no files selected for viewing
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
134 changes: 134 additions & 0 deletions
134
.../app/browser/defaultbrowsing/prompts/store/DefaultBrowserPromptsPrefsDataStoreImplTest.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,134 @@ | ||
/* | ||
* 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.browser.defaultbrowsing.prompts.store | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.duckduckgo.app.browser.defaultbrowsing.prompts.store.DefaultBrowserPromptsDataStore.ExperimentStage | ||
import com.duckduckgo.common.test.CoroutineTestRule | ||
import java.io.File | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.toList | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
private const val DATA_STORE_NAME: String = "default_browser_prompts_test_data_store" | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class DefaultBrowserPromptsPrefsDataStoreImplTest { | ||
|
||
@get:Rule | ||
var coroutinesTestRule = CoroutineTestRule() | ||
|
||
private lateinit var testDataStoreFile: File | ||
private lateinit var testDataStore: DataStore<Preferences> | ||
|
||
@Before | ||
fun setUp() { | ||
testDataStoreFile = File.createTempFile(DATA_STORE_NAME, ".preferences_pb") | ||
testDataStore = PreferenceDataStoreFactory.create( | ||
scope = coroutinesTestRule.testScope, | ||
produceFile = { testDataStoreFile }, | ||
) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
testDataStoreFile.delete() | ||
} | ||
|
||
@Test | ||
fun whenExperimentInitializedThenDefaultValueIsNotEnrolled() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
|
||
assertEquals(testee.experimentStage.first(), ExperimentStage.NOT_ENROLLED) | ||
} | ||
|
||
@Test | ||
fun whenExperimentStageIsUpdatedThenValueIsPropagated() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
val expectedUpdates = listOf( | ||
ExperimentStage.NOT_ENROLLED, | ||
ExperimentStage.STAGE_1, | ||
) | ||
val actualUpdates = mutableListOf<ExperimentStage>() | ||
coroutinesTestRule.testScope.launch { | ||
testee.experimentStage.toList(actualUpdates) | ||
} | ||
|
||
testee.storeExperimentStage(ExperimentStage.STAGE_1) | ||
|
||
assertEquals(expectedUpdates, actualUpdates) | ||
} | ||
|
||
@Test | ||
fun whenExperimentInitializedThenShowOverflowMenuItemIsDisabled() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
|
||
assertFalse(testee.showOverflowMenuItem.first()) | ||
} | ||
|
||
@Test | ||
fun whenShowOverflowMenuItemIsUpdatedThenValueIsPropagated() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
val expectedUpdates = listOf( | ||
false, // initial value | ||
true, | ||
) | ||
val actualUpdates = mutableListOf<Boolean>() | ||
coroutinesTestRule.testScope.launch { | ||
testee.showOverflowMenuItem.toList(actualUpdates) | ||
} | ||
|
||
testee.storeShowOverflowMenuItemState(show = true) | ||
|
||
assertEquals(expectedUpdates, actualUpdates) | ||
} | ||
|
||
@Test | ||
fun whenExperimentInitializedThenHighlightOverflowMenuIconIsDisabled() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
|
||
assertFalse(testee.highlightOverflowMenuIcon.first()) | ||
} | ||
|
||
@Test | ||
fun whenHighlightOverflowMenuIconIsUpdatedThenValueIsPropagated() = runTest { | ||
val testee = DefaultBrowserPromptsPrefsDataStoreImpl(testDataStore) | ||
val expectedUpdates = listOf( | ||
false, // initial value | ||
true, | ||
) | ||
val actualUpdates = mutableListOf<Boolean>() | ||
coroutinesTestRule.testScope.launch { | ||
testee.highlightOverflowMenuIcon.toList(actualUpdates) | ||
} | ||
|
||
testee.storeHighlightOverflowMenuIconState(highlight = true) | ||
|
||
assertEquals(expectedUpdates, actualUpdates) | ||
} | ||
} |
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
Oops, something went wrong.