From 0db2953a4fff25953664d8284ee52c42cc90954f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manu=20Mu=C3=B1oz?= Date: Tue, 21 May 2024 10:35:51 +0200 Subject: [PATCH] refactor: [ANDROAPP-6029] remove EventDetailIdlingResourceSingleton (#3639) --- .../java/org/dhis2/usescases/BaseTest.kt | 3 --- .../ui/EventDetailIdlingResourceSingleton.kt | 20 ------------------ .../eventDetails/ui/EventDetailsViewModel.kt | 21 ++++++++++--------- 3 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailIdlingResourceSingleton.kt diff --git a/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt b/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt index f94746d2c9..e9d76fa684 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt @@ -24,7 +24,6 @@ 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 @@ -87,7 +86,6 @@ open class BaseTest { SearchIdlingResourceSingleton.countingIdlingResource, TeiDataIdlingResourceSingleton.countingIdlingResource, EventIdlingResourceSingleton.countingIdlingResource, - EventDetailIdlingResourceSingleton.countingIdlingResource, ) } @@ -100,7 +98,6 @@ open class BaseTest { SearchIdlingResourceSingleton.countingIdlingResource, TeiDataIdlingResourceSingleton.countingIdlingResource, EventIdlingResourceSingleton.countingIdlingResource, - EventDetailIdlingResourceSingleton.countingIdlingResource, ) } diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailIdlingResourceSingleton.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailIdlingResourceSingleton.kt deleted file mode 100644 index 5a24fe2882..0000000000 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailIdlingResourceSingleton.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.dhis2.usescases.eventsWithoutRegistration.eventDetails.ui - -import androidx.test.espresso.idling.CountingIdlingResource - -object EventDetailIdlingResourceSingleton { - - private const val RESOURCE = "EVENT_DETAIL" - - @JvmField val countingIdlingResource = CountingIdlingResource(RESOURCE) - - fun increment() { - countingIdlingResource.increment() - } - - fun decrement() { - if (!countingIdlingResource.isIdleNow) { - countingIdlingResource.decrement() - } - } -} diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt index 5d33d4db0b..e7f6233cd0 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.launch import org.dhis2.commons.extensions.truncate import org.dhis2.commons.locationprovider.LocationProvider import org.dhis2.form.data.GeometryController +import org.dhis2.usescases.eventsWithoutRegistration.EventIdlingResourceSingleton import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.domain.ConfigureEventCatCombo import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.domain.ConfigureEventCoordinates import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.domain.ConfigureEventDetails @@ -141,7 +142,7 @@ class EventDetailsViewModel( } private fun setUpEventDetails() { - EventDetailIdlingResourceSingleton.increment() + EventIdlingResourceSingleton.increment() viewModelScope.launch { configureEventDetails( selectedDate = eventDate.value.currentDate, @@ -154,13 +155,13 @@ class EventDetailsViewModel( .flowOn(Dispatchers.IO) .collect { _eventDetails.value = it - EventDetailIdlingResourceSingleton.decrement() + EventIdlingResourceSingleton.decrement() } } } fun setUpEventReportDate(selectedDate: Date? = null) { - EventDetailIdlingResourceSingleton.increment() + EventIdlingResourceSingleton.increment() viewModelScope.launch { configureEventReportDate(selectedDate) .flowOn(Dispatchers.IO) @@ -168,7 +169,7 @@ class EventDetailsViewModel( _eventDate.value = it setUpEventDetails() setUpOrgUnit(selectedDate = it.currentDate) - EventDetailIdlingResourceSingleton.decrement() + EventIdlingResourceSingleton.decrement() } } } @@ -195,14 +196,14 @@ class EventDetailsViewModel( } fun setUpCategoryCombo(categoryOption: Pair? = null) { - EventDetailIdlingResourceSingleton.increment() + EventIdlingResourceSingleton.increment() viewModelScope.launch { configureEventCatCombo(categoryOption) .flowOn(Dispatchers.IO) .collect { _eventCatCombo.value = it setUpEventDetails() - EventDetailIdlingResourceSingleton.decrement() + EventIdlingResourceSingleton.decrement() } } } @@ -213,7 +214,7 @@ class EventDetailsViewModel( } private fun setUpCoordinates(value: String? = "") { - EventDetailIdlingResourceSingleton.increment() + EventIdlingResourceSingleton.increment() viewModelScope.launch { configureEventCoordinates(value) .flowOn(Dispatchers.IO) @@ -233,20 +234,20 @@ class EventDetailsViewModel( ) _eventCoordinates.value = eventCoordinates setUpEventDetails() - EventDetailIdlingResourceSingleton.decrement() + EventIdlingResourceSingleton.decrement() } } } fun setUpEventTemp(status: EventTempStatus? = null, isChecked: Boolean = true) { - EventDetailIdlingResourceSingleton.increment() + EventIdlingResourceSingleton.increment() if (isChecked) { configureEventTemp(status).apply { _eventTemp.value = this setUpEventDetails() } } - EventDetailIdlingResourceSingleton.decrement() + EventIdlingResourceSingleton.decrement() } fun getSelectableDates(eventDate: EventDate): SelectableDates {