Merge "[BiometricsV2] Refine ErrorDialogViewModelTest" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
6e43b13cb8
@@ -24,6 +24,9 @@ import com.google.common.truth.Truth.assertThat
|
|||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||||
|
import kotlinx.coroutines.test.runCurrent
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -56,79 +59,69 @@ class FingerprintEnrollErrorDialogViewModelTest {
|
|||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
@Test
|
@Test
|
||||||
fun testNewDialog() = runTest {
|
fun testNewDialog() = runTest {
|
||||||
backgroundScope.launch {
|
val newDialogs: List<Int> = mutableListOf<Int>().also {
|
||||||
mutableListOf<Any>().let { list ->
|
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
|
||||||
viewModel.newDialogFlow.toList(list)
|
viewModel.newDialogFlow.toList(it)
|
||||||
assertThat(list.size).isEqualTo(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
mutableListOf<FingerprintErrorDialogSetResultAction>().let { list ->
|
|
||||||
val testErrorMsgId = 3456
|
|
||||||
viewModel.newDialog(testErrorMsgId)
|
|
||||||
|
|
||||||
assertThat(viewModel.isDialogShown).isTrue()
|
|
||||||
viewModel.setResultFlow.toList(list)
|
|
||||||
assertThat(list.size).isEqualTo(1)
|
|
||||||
assertThat(list[0]).isEqualTo(testErrorMsgId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runCurrent()
|
||||||
|
|
||||||
|
// Default values
|
||||||
|
assertThat(viewModel.isDialogShown).isFalse()
|
||||||
|
assertThat(newDialogs.size).isEqualTo(0)
|
||||||
|
|
||||||
|
val testErrorMsgId = 3456
|
||||||
|
viewModel.newDialog(testErrorMsgId)
|
||||||
|
runCurrent()
|
||||||
|
|
||||||
|
// verify after emit
|
||||||
|
assertThat(viewModel.isDialogShown).isTrue()
|
||||||
|
assertThat(newDialogs.size).isEqualTo(1)
|
||||||
|
assertThat(newDialogs[0]).isEqualTo(testErrorMsgId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
@Test
|
@Test
|
||||||
fun testTriggerRetry() = runTest {
|
fun testTriggerRetry() = runTest {
|
||||||
backgroundScope.launch {
|
val triggerRetries: List<Any> = mutableListOf<Any>().also {
|
||||||
// triggerRetryFlow shall be empty on begin
|
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
|
||||||
mutableListOf<Any>().let { list ->
|
viewModel.triggerRetryFlow.toList(it)
|
||||||
viewModel.triggerRetryFlow.toList(list)
|
|
||||||
assertThat(list.size).isEqualTo(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emit newDialog
|
|
||||||
mutableListOf<FingerprintErrorDialogSetResultAction>().let { list ->
|
|
||||||
viewModel.newDialog(0)
|
|
||||||
viewModel.triggerRetry()
|
|
||||||
|
|
||||||
assertThat(viewModel.isDialogShown).isFalse()
|
|
||||||
viewModel.setResultFlow.toList(list)
|
|
||||||
assertThat(list.size).isEqualTo(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runCurrent()
|
||||||
|
|
||||||
|
// Default values
|
||||||
|
assertThat(triggerRetries.size).isEqualTo(0)
|
||||||
|
|
||||||
|
viewModel.triggerRetry()
|
||||||
|
runCurrent()
|
||||||
|
|
||||||
|
// verify after emit
|
||||||
|
assertThat(triggerRetries.size).isEqualTo(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
@Test
|
@Test
|
||||||
fun testSetResultFinish() = runTest {
|
fun testSetResultFinish() = runTest {
|
||||||
backgroundScope.launch {
|
val setResults: List<FingerprintErrorDialogSetResultAction> =
|
||||||
// setResultFlow shall be empty on begin
|
mutableListOf<FingerprintErrorDialogSetResultAction>().also {
|
||||||
mutableListOf<FingerprintErrorDialogSetResultAction>().let { list ->
|
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
|
||||||
viewModel.setResultFlow.toList(list)
|
viewModel.setResultFlow.toList(it)
|
||||||
assertThat(list.size).isEqualTo(0)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH
|
runCurrent()
|
||||||
viewModel = FingerprintEnrollErrorDialogViewModel(application, false)
|
|
||||||
mutableListOf<FingerprintErrorDialogSetResultAction>().let { list ->
|
|
||||||
viewModel.newDialog(0)
|
|
||||||
viewModel.setResultAndFinish(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH)
|
|
||||||
|
|
||||||
assertThat(viewModel.isDialogShown).isFalse()
|
// Default values
|
||||||
viewModel.setResultFlow.toList(list)
|
assertThat(setResults.size).isEqualTo(0)
|
||||||
assertThat(list.size).isEqualTo(1)
|
|
||||||
assertThat(list[0]).isEqualTo(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH)
|
|
||||||
}
|
|
||||||
|
|
||||||
// emit FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT
|
viewModel.setResultAndFinish(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH)
|
||||||
viewModel = FingerprintEnrollErrorDialogViewModel(application, false)
|
runCurrent()
|
||||||
mutableListOf<FingerprintErrorDialogSetResultAction>().let { list ->
|
|
||||||
viewModel.newDialog(0)
|
|
||||||
viewModel.setResultAndFinish(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT)
|
|
||||||
|
|
||||||
assertThat(viewModel.isDialogShown).isFalse()
|
// verify after emit
|
||||||
viewModel.setResultFlow.toList(list)
|
assertThat(setResults.size).isEqualTo(1)
|
||||||
assertThat(list.size).isEqualTo(1)
|
assertThat(setResults[0]).isEqualTo(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH)
|
||||||
assertThat(list[0]).isEqualTo(FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user