Skip to content

Commit

Permalink
fix: [ANDROAPP-6131] fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Jun 13, 2024
1 parent 670944f commit ea3f95b
Showing 1 changed file with 2 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
package org.dhis2.usescases.programEventDetail

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import androidx.paging.PagedList
import com.mapbox.geojson.BoundingBox
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.android.plugins.RxAndroidPlugins
import io.reactivex.schedulers.Schedulers
import org.dhis2.commons.data.EventViewModel
import org.dhis2.commons.data.EventViewModelType
import org.dhis2.commons.data.ProgramEventViewModel
import org.dhis2.commons.data.tuples.Pair
import org.dhis2.commons.filters.DisableHomeFiltersFromSettingsApp
import org.dhis2.commons.filters.FilterItem
import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.Filters
import org.dhis2.commons.filters.data.FilterPresenter
import org.dhis2.commons.filters.data.FilterRepository
import org.dhis2.commons.filters.sorting.SortingItem
import org.dhis2.commons.filters.sorting.SortingStatus
import org.dhis2.commons.filters.workingLists.EventFilterToWorkingListItemMapper
import org.dhis2.commons.matomo.MatomoAnalyticsController
import org.dhis2.data.schedulers.TrampolineSchedulerProvider
import org.dhis2.ui.MetadataIconData
import org.hisp.dhis.android.core.category.CategoryCombo
import org.hisp.dhis.android.core.category.CategoryOptionCombo
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.program.Program
import org.hisp.dhis.android.core.program.ProgramStage
import org.junit.After
import org.junit.Assert.assertTrue
import org.junit.Before
Expand All @@ -54,7 +37,6 @@ class ProgramEventDetailPresenterTest {
private val scheduler = TrampolineSchedulerProvider()
private val filterManager: FilterManager = FilterManager.getInstance()
private val workingListMapper: EventFilterToWorkingListItemMapper = mock()
private val filterPresenter: FilterPresenter = mock()
private val disableHomeFilters: DisableHomeFiltersFromSettingsApp = mock()
private val matomoAnalyticsController: MatomoAnalyticsController = mock()

Expand Down Expand Up @@ -83,49 +65,10 @@ class ProgramEventDetailPresenterTest {
@Test
fun `Should init screen`() {
val program = Program.builder().uid("programUid").build()
val catOptionComboPair = Pair.create(dummyCategoryCombo(), dummyListCatOptionCombo())

val eventViewModel = EventViewModel(
EventViewModelType.EVENT,
ProgramStage.builder().uid("stageUid").build(),
Event.builder().uid("event").build(),
eventCount = 0,
lastUpdate = null,
isSelected = true,
canAddNewEvent = true,
orgUnitName = "orgUnit",
catComboName = "catComboName",
dataElementValues = emptyList(),
groupedByStage = false,
valueListIsOpen = false,
displayDate = "2/01/2021",
nameCategoryOptionCombo = "Category Option Combo",
metadataIconData = MetadataIconData.defaultIcon(),
)
val events =
MutableLiveData<PagedList<EventViewModel>>().also {
it.value?.add(eventViewModel)
}

val mapEvents = Triple<FeatureCollection, BoundingBox, List<ProgramEventViewModel>>(
FeatureCollection.fromFeature(Feature.fromGeometry(null)),
BoundingBox.fromLngLats(0.0, 0.0, 0.0, 0.0),
listOf(),
)
val mapData = ProgramEventMapData(
mutableListOf(),
mutableMapOf("key" to FeatureCollection.fromFeature(Feature.fromGeometry(null))),
BoundingBox.fromLngLats(0.0, 0.0, 0.0, 0.0),
)
filterManager.sortingItem = SortingItem(Filters.ORG_UNIT, SortingStatus.NONE)

whenever(repository.getAccessDataWrite()) doReturn true
whenever(repository.program()) doReturn Single.just(program)
whenever(
repository.filteredProgramEvents(),
) doReturn events
whenever(
repository.filteredEventsForMap(),
) doReturn Flowable.just(mapData)

presenter.init()
verify(view).setWritePermission(true)
verify(view).setProgram(program)
Expand Down

0 comments on commit ea3f95b

Please sign in to comment.