Skip to content

Commit

Permalink
Add idilingResource to event tests (#3550)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmr authored Mar 19, 2024
1 parent 2ecf45d commit 09e9b58
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.dhis2.commons.idlingresource.SearchIdlingResourceSingleton
import org.dhis2.commons.prefs.Preference
import org.dhis2.form.ui.idling.FormCountingIdlingResource
import org.dhis2.usescases.eventsWithoutRegistration.EventIdlingResourceSingleton
import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.ui.EventDetailIdlingResourceSingleton
import org.dhis2.usescases.programEventDetail.eventList.EventListIdlingResourceSingleton
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.TeiDataIdlingResourceSingleton
import org.junit.After
Expand Down Expand Up @@ -86,6 +87,7 @@ open class BaseTest {
SearchIdlingResourceSingleton.countingIdlingResource,
TeiDataIdlingResourceSingleton.countingIdlingResource,
EventIdlingResourceSingleton.countingIdlingResource,
EventDetailIdlingResourceSingleton.countingIdlingResource,
)
}

Expand All @@ -98,6 +100,7 @@ open class BaseTest {
SearchIdlingResourceSingleton.countingIdlingResource,
TeiDataIdlingResourceSingleton.countingIdlingResource,
EventIdlingResourceSingleton.countingIdlingResource,
EventDetailIdlingResourceSingleton.countingIdlingResource,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.dhis2.commons.prefs.PreferenceProvider
import org.dhis2.commons.schedulers.SchedulerProvider
import org.dhis2.commons.schedulers.defaultSubscribe
import org.dhis2.ui.dialogs.bottomsheet.FieldWithIssue
import org.dhis2.usescases.eventsWithoutRegistration.EventIdlingResourceSingleton
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.EventCaptureContract.EventCaptureRepository
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.domain.ConfigureEventCompletionDialog
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.model.EventCaptureInitialInfo
Expand Down Expand Up @@ -181,17 +182,25 @@ class EventCapturePresenterImpl(

override fun deleteEvent() {
val programStage = programStage()
EventIdlingResourceSingleton.increment()
compositeDisposable.add(
eventCaptureRepository.deleteEvent()
.defaultSubscribe(
schedulerProvider,
{ result ->
onNext = { result ->
EventIdlingResourceSingleton.decrement()
if (result) {
view.showSnackBar(R.string.event_label_was_deleted, programStage)
}
},
Timber::e,
view::finishDataEntry,
onError = {
EventIdlingResourceSingleton.decrement()
Timber.e(it)
},
onComplete = {
EventIdlingResourceSingleton.decrement()
view.finishDataEntry()
},
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ class EventDetailsViewModel(
return if (eventDate.allowFutureDates) {
SelectableDates(DEFAULT_MIN_DATE, DEFAULT_MAX_DATE)
} else {
val currentDate = SimpleDateFormat("ddMMyyyy", Locale.US).format(Date(System.currentTimeMillis()))
val currentDate =
SimpleDateFormat("ddMMyyyy", Locale.US).format(Date(System.currentTimeMillis()))
SelectableDates(DEFAULT_MIN_DATE, currentDate)
}
}
Expand Down Expand Up @@ -289,7 +290,7 @@ class EventDetailsViewModel(

fun onOrgUnitClick() {
if (!eventOrgUnit.value.fixed) {
if (eventOrgUnit.value.orgUnits.isNullOrEmpty()) {
if (eventOrgUnit.value.orgUnits.isEmpty()) {
showNoOrgUnits?.invoke()
} else {
showOrgUnits?.invoke()
Expand Down Expand Up @@ -387,16 +388,16 @@ inline fun <R, reified T> Result<T>.mockSafeFold(
if ((value as Result<*>).isSuccess) {
valueNotNull::class.java.getDeclaredField("value").let {
it.isAccessible = true
it.get(value) as T
it[value] as T
}.let(onSuccess)
} else {
valueNotNull::class.java.getDeclaredField("value").let {
it.isAccessible = true
it.get(value)
it[value]
}.let { failure ->
failure!!::class.java.getDeclaredField("exception").let {
it.isAccessible = true
it.get(failure) as Exception
it[failure] as Exception
}
}.let(onFailure)
}
Expand Down

0 comments on commit 09e9b58

Please sign in to comment.