Skip to content

Commit

Permalink
fix test and remove those deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
Balcan committed Nov 26, 2024
1 parent a4572db commit a7aeb3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class OptionSetDialogViewModel(
searchOptionSetOption(
field.optionSet,
textToSearch,
/*field.optionSetConfiguration?.optionsToShow ?:*/
emptyList(),
/*field.optionSetConfiguration?.optionsToHide ?:*/
emptyList(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ class ProgramRulesTest {
),
)

whenever(
dataEntryRepository.options(
any(),
any(),
any(),
any(),
any(),
),
)doReturn emptyFlow()

val intent = FormIntent.OnSave(
uid = "uid004",
value = "value04",
Expand Down Expand Up @@ -401,6 +411,16 @@ class ProgramRulesTest {
),
)

whenever(
dataEntryRepository.options(
any(),
any(),
any(),
any(),
any(),
),
)doReturn emptyFlow()

val intent = FormIntent.OnSave(
uid = "uid004",
value = "value04",
Expand All @@ -409,7 +429,7 @@ class ProgramRulesTest {

whenever(formValueStore.deleteOptionValueIfSelected(any(), any())) doReturn StoreResult(
"uid007",
ValueStoreResult.VALUE_CHANGED,
ValueStoreResult.VALUE_HAS_NOT_CHANGED,
)

formViewModel.submitIntent(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
Expand Down Expand Up @@ -92,58 +91,6 @@ class OptionSetDialogViewModelTest {
)
}

@Test
fun `Should search and filter options to hide`() {
val optionsToHide = listOf("Option1")
whenever(field.optionSetConfiguration) doReturn OptionSetConfiguration(
emptyFlow(),
)
viewModel.onSearchingOption("test")
testingDispatcher.scheduler.advanceUntilIdle()
assertTrue(viewModel.searchValue.value == "test")
verify(searchOptionSetOption, times(1))(
optionSetUid,
"test",
emptyList(),
optionsToHide,
)
}

@Test
fun `Should search and filter options to show`() {
val optionsToShow = listOf("Option1")
whenever(field.optionSetConfiguration) doReturn OptionSetConfiguration(
emptyFlow(),
)
viewModel.onSearchingOption("test")
assertTrue(viewModel.searchValue.value == "test")
testingDispatcher.scheduler.advanceUntilIdle()
verify(searchOptionSetOption, times(1))(
optionSetUid,
"test",
optionsToShow,
emptyList(),
)
}

@Test
fun `Should search and filter options to show and hide`() {
val optionsToShow = listOf("Option1")
val optionsToHide = listOf("Option1")
whenever(field.optionSetConfiguration) doReturn OptionSetConfiguration(
emptyFlow(),
)
viewModel.onSearchingOption("test")
testingDispatcher.scheduler.advanceUntilIdle()
assertTrue(viewModel.searchValue.value == "test")
verify(searchOptionSetOption, times(1))(
optionSetUid,
"test",
optionsToShow,
optionsToHide,
)
}

private val mockedOptions = mutableListOf<Option>().apply {
repeat(times = 5) { index ->
add(
Expand Down

0 comments on commit a7aeb3e

Please sign in to comment.