-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01cdb4e
commit 1c70aab
Showing
23 changed files
with
686 additions
and
1 deletion.
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
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
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
64 changes: 64 additions & 0 deletions
64
app/src/test/java/com/duckduckgo/duckplayer/impl/DuckPlayerSettingsViewModelTest.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,64 @@ | ||
package com.duckduckgo.duckplayer.impl | ||
|
||
import app.cash.turbine.test | ||
import com.duckduckgo.common.test.CoroutineTestRule | ||
import com.duckduckgo.duckplayer.api.DuckPlayer | ||
import com.duckduckgo.duckplayer.api.DuckPlayer.UserPreferences | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.AlwaysAsk | ||
import com.duckduckgo.duckplayer.api.PrivatePlayerMode.Disabled | ||
import com.duckduckgo.duckplayer.impl.DuckPlayerSettingsViewModel.Command.OpenPlayerModeSelector | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
|
||
@ExperimentalCoroutinesApi | ||
class DuckPlayerSettingsViewModelTest { | ||
|
||
@get:Rule | ||
@Suppress("unused") | ||
val coroutineRule = CoroutineTestRule() | ||
|
||
private val duckPlayer: DuckPlayer = mock() | ||
private lateinit var viewModel: DuckPlayerSettingsViewModel | ||
|
||
@Before | ||
fun setUp() { | ||
runTest { | ||
whenever(duckPlayer.getUserPreferences()).thenReturn(UserPreferences(overlayInteracted = true, privatePlayerMode = AlwaysAsk)) | ||
viewModel = DuckPlayerSettingsViewModel(duckPlayer) | ||
} | ||
} | ||
|
||
@Test | ||
fun whenDuckPlayerModeSelectorIsClichedThenEmitOpenPlayerModeSelector() = runTest { | ||
viewModel.duckPlayerModeSelectorClicked() | ||
|
||
viewModel.commands.test { | ||
assertEquals(OpenPlayerModeSelector(AlwaysAsk), awaitItem()) | ||
} | ||
} | ||
|
||
@Test | ||
fun whenPrivatePlayerModeIsSelectedThenUpdateUserPreferences() = runTest { | ||
viewModel.onPlayerModeSelected(Disabled) | ||
|
||
verify(duckPlayer).setUserPreferences(overlayInteracted = false, privatePlayerMode = Disabled.value) | ||
} | ||
|
||
@Test | ||
fun whenViewModelIsCreatedAndPrivatePlayerModeIsDisabledThenEmitDisabled() = runTest { | ||
whenever(duckPlayer.observeUserPreferences()).thenReturn(flowOf(UserPreferences(overlayInteracted = true, privatePlayerMode = Disabled))) | ||
viewModel = DuckPlayerSettingsViewModel(duckPlayer) | ||
|
||
viewModel.viewState.test { | ||
assertEquals(Disabled, awaitItem().privatePlayerMode) | ||
} | ||
} | ||
} |
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.