Skip to content

Commit

Permalink
test: change test dispatcher
Browse files Browse the repository at this point in the history
Signed-off-by: andresmr <[email protected]>
  • Loading branch information
andresmr committed Sep 6, 2024
1 parent c7a53b9 commit 1b741ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class FilterTest : BaseTest() {
}
}
homeRobot {
waitToDebounce(700)
openFilters()
checkItemsInProgram(composeTestRule, 3, "Child Programme", "0")
checkItemsInProgram(composeTestRule, 41, "XX TEST EVENT FULL", "2")
Expand All @@ -99,7 +100,7 @@ class FilterTest : BaseTest() {
cleanLocalDatabase()
}

@Ignore("Undeterministic")
@Ignore("Flaky test, will be looked up in ANDROAPP-6466")
@Test
fun checkSyncFilter() {
setupCredentials()
Expand Down Expand Up @@ -133,7 +134,7 @@ class FilterTest : BaseTest() {
cleanLocalDatabase()
}

@Ignore("TODO: Review why is failing on browserstack")
@Ignore("Flaky test, will be looked up in ANDROAPP-6466")
@Test
fun checkCombinedFilters() {
setupCredentials()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.setMain
import org.dhis2.android.rtsm.R
import org.dhis2.android.rtsm.commons.Constants
Expand Down Expand Up @@ -63,7 +62,6 @@ class HomeViewModelUnitTest {
private lateinit var viewModel: HomeViewModel
private lateinit var schedulerProvider: BaseSchedulerProvider

@OptIn(ExperimentalCoroutinesApi::class)
@Mock
private lateinit var testSchedulerProvider: TestCoroutineScheduler
private lateinit var facilities: List<OrganisationUnit>
Expand All @@ -81,7 +79,11 @@ class HomeViewModelUnitTest {
TransactionType.CORRECTION,
TransactionType.CORRECTION.name,
)
private val discardItem = TransactionItem(R.drawable.ic_discard, TransactionType.DISCARD, TransactionType.DISCARD.name)
private val discardItem = TransactionItem(
R.drawable.ic_discard,
TransactionType.DISCARD,
TransactionType.DISCARD.name,
)

private val transactionItems = mutableListOf(distributionItem, correctionItem, discardItem)

Expand All @@ -101,8 +103,8 @@ class HomeViewModelUnitTest {
@Mock
private lateinit var destinationsObserver: Observer<OperationState<List<Option>>>

@OptIn(DelicateCoroutinesApi::class)
private val mainThreadSurrogate = newSingleThreadContext("UI thread")
@OptIn(ExperimentalCoroutinesApi::class)
private val mainThreadSurrogate = UnconfinedTestDispatcher()

@OptIn(ExperimentalCoroutinesApi::class)
@Before
Expand All @@ -127,7 +129,8 @@ class HomeViewModelUnitTest {
facilities = FacilityFactory.getListOf(3)
destinations = DestinationFactory.getListOf(5)

val distributionDataSet = DataElementFactory.create(appConfig.stockDistribution, DISTRIBUTION_LABEL)
val distributionDataSet =
DataElementFactory.create(appConfig.stockDistribution, DISTRIBUTION_LABEL)
val correctionDataSet = DataElementFactory.create(appConfig.stockCount, CORRECTION_lABEL)
val discardDataSet = DataElementFactory.create(appConfig.stockDiscarded, DISCARD_LABEL)
val deliverToDataSet = DataElementFactory.create(appConfig.stockDiscarded, DELIVER_TO_LABEL)
Expand Down Expand Up @@ -197,21 +200,30 @@ class HomeViewModelUnitTest {
fun init_shouldLoadDistributionLabel() {
verify(metadataManager).transactionType(appConfig.stockDistribution)

assertEquals(viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.DISTRIBUTION }?.label, DISTRIBUTION_LABEL)
assertEquals(
viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.DISTRIBUTION }?.label,
DISTRIBUTION_LABEL,
)
}

@Test
fun init_shouldLoadCorrectLabel() {
verify(metadataManager).transactionType(appConfig.stockCount)

assertEquals(viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.CORRECTION }?.label, CORRECTION_lABEL)
assertEquals(
viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.CORRECTION }?.label,
CORRECTION_lABEL,
)
}

@Test
fun init_shouldLoadDiscardLabel() {
verify(metadataManager).transactionType(appConfig.stockDiscarded)

assertEquals(viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.DISCARD }?.label, DISCARD_LABEL)
assertEquals(
viewModel.settingsUiState.value.transactionItems.find { it.type == TransactionType.DISCARD }?.label,
DISCARD_LABEL,
)
}

@Test
Expand All @@ -232,7 +244,10 @@ class HomeViewModelUnitTest {
@Test
fun isDistributionIsPositive_whenDistributionIsSet() {
viewModel.selectTransaction(distributionItem)
assertEquals(viewModel.settingsUiState.value.selectedTransactionItem.type, TransactionType.DISTRIBUTION)
assertEquals(
viewModel.settingsUiState.value.selectedTransactionItem.type,
TransactionType.DISTRIBUTION,
)
}

@Test
Expand Down

0 comments on commit 1b741ff

Please sign in to comment.