Skip to content

Commit

Permalink
fix:[ANDROAPP-6673] fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xavimolloy committed Dec 17, 2024
1 parent 9328294 commit c10a079
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.setMain
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.data.FilterRepository
import org.dhis2.commons.matomo.Categories.Companion.HOME
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.commons.prefs.Preference.Companion.DEFAULT_CAT_COMBO
Expand Down Expand Up @@ -53,6 +54,8 @@ class MainPresenterTest {
private val preferences: PreferenceProvider = mock()
private val workManagerController: WorkManagerController = mock()
private val filterManager: FilterManager = mock()
private val filterRepository: FilterRepository = mock()

private val matomoAnalyticsController: MatomoAnalyticsController = mock()
private val userManager: UserManager = mock()
private val deleteUserData: DeleteUserData = mock()
Expand Down Expand Up @@ -83,6 +86,7 @@ class MainPresenterTest {
preferences,
workManagerController,
filterManager,
filterRepository,
matomoAnalyticsController,
userManager,
deleteUserData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.dhis2.commons.filters.data.FilterPresenter
import org.dhis2.commons.resources.MetadataIconProvider
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.data.dhislogic.DhisProgramUtils
import org.dhis2.data.dhislogic.DhisTrackedEntityInstanceUtils
import org.dhis2.data.schedulers.TrampolineSchedulerProvider
import org.dhis2.data.service.SyncStatusData
import org.dhis2.ui.MetadataIconData
Expand Down Expand Up @@ -46,6 +47,7 @@ class ProgramRepositoryImplTest {
private val filterPresenter: FilterPresenter =
Mockito.mock(FilterPresenter::class.java, Mockito.RETURNS_DEEP_STUBS)
private val dhisProgramUtils: DhisProgramUtils = mock()
private val dhis2TeiUtils: DhisTrackedEntityInstanceUtils = mock()
private val scheduler = TrampolineSchedulerProvider()
private val resourceManager: ResourceManager = mock()
private val metadataIconProvider: MetadataIconProvider = mock {
Expand All @@ -60,6 +62,7 @@ class ProgramRepositoryImplTest {
d2,
filterPresenter,
dhisProgramUtils,
dhis2TeiUtils,
resourceManager,
metadataIconProvider,
scheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package org.dhis2.usescases.main.program

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import io.reactivex.Flowable
import io.reactivex.processors.FlowableProcessor
import io.reactivex.processors.PublishProcessor
import io.reactivex.schedulers.TestScheduler
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.setMain
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.commons.viewmodel.DispatcherProvider
import org.dhis2.data.schedulers.TestSchedulerProvider
import org.dhis2.data.service.SyncStatusController
import org.dhis2.data.service.SyncStatusData
import org.dhis2.ui.MetadataIconData
Expand Down Expand Up @@ -43,6 +48,8 @@ class ProgramViewModelTest {
private val view: ProgramView = mock()
private val programRepository: ProgramRepository = mock()
private val matomoAnalyticsController: MatomoAnalyticsController = mock()
private val filterManager: FilterManager = mock()
private val schedulerProvider: TestSchedulerProvider = TestSchedulerProvider(TestScheduler())
private val syncStatusController: SyncStatusController = mock()
private val testingDispatcher = UnconfinedTestDispatcher()
private val featureConfigRepository: FeatureConfigRepository = mock {
Expand Down Expand Up @@ -70,16 +77,24 @@ class ProgramViewModelTest {
programRepository,
featureConfigRepository,
dispatcherProvider,

matomoAnalyticsController,
filterManager,
syncStatusController,
schedulerProvider,
)
}

@Test
fun `Should initialize program list`() {
val programs = listOf(programViewModel())
val programsFlowable = Flowable.just(programs)
val filterProcessor: FlowableProcessor<FilterManager> = PublishProcessor.create()

val syncStatusData = SyncStatusData(true)
val filterManagerFlowable = Flowable.just(filterManager).startWith(filterProcessor)

whenever(filterManager.asFlowable()) doReturn filterManagerFlowable

whenever(
syncStatusController.observeDownloadProcess(),
Expand Down Expand Up @@ -149,6 +164,8 @@ class ProgramViewModelTest {
downloadState = ProgramDownloadState.NONE,
stockConfig = null,
lastUpdated = Date(),
hasOverdueEvent = false,
filtersAreActive = false,
)
}

Expand Down Expand Up @@ -176,6 +193,8 @@ class ProgramViewModelTest {
downloadState = ProgramDownloadState.NONE,
stockConfig = null,
lastUpdated = Date(),
hasOverdueEvent = false,
filtersAreActive = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class TeiProgramListPresenterTest {
downloadState = ProgramDownloadState.NONE,
stockConfig = null,
lastUpdated = Date(),
filtersAreActive = false,
hasOverdueEvent = false,
)
}

Expand Down

0 comments on commit c10a079

Please sign in to comment.