From 684471377b88230128cb8ee5e53b918c918f0643 Mon Sep 17 00:00:00 2001 From: Pablo Pajuelo Cabezas Date: Tue, 17 Dec 2024 12:39:25 +0100 Subject: [PATCH] fix: [ANDROAPP-6717] Crash when syncing a TEI from map --- .../java/org/dhis2/usescases/BaseTest.kt | 7 +++++-- .../idling/AnalyticsCountingIdlingResource.kt | 19 +++++++++++++++++++ .../charts/ui/GroupAnalyticsFragment.kt | 2 ++ .../charts/ui/GroupAnalyticsViewModel.kt | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/idling/AnalyticsCountingIdlingResource.kt diff --git a/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt b/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt index b08151e87e..fab2d84887 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt @@ -6,6 +6,8 @@ import androidx.test.espresso.IdlingRegistry import androidx.test.espresso.intent.Intents import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule +import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource +import java.util.concurrent.TimeUnit import org.dhis2.AppTest import org.dhis2.AppTest.Companion.DB_TO_IMPORT import org.dhis2.common.BaseRobot @@ -22,16 +24,15 @@ import org.dhis2.commons.idlingresource.CountingIdlingResourceSingleton import org.dhis2.commons.idlingresource.SearchIdlingResourceSingleton import org.dhis2.commons.prefs.Preference import org.dhis2.form.ui.idling.FormCountingIdlingResource +import org.dhis2.maps.utils.OnMapReadyIdlingResourceSingleton import org.dhis2.usescases.eventsWithoutRegistration.EventIdlingResourceSingleton import org.dhis2.usescases.programEventDetail.eventList.EventListIdlingResourceSingleton import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.TeiDataIdlingResourceSingleton -import org.dhis2.maps.utils.OnMapReadyIdlingResourceSingleton import org.junit.After import org.junit.Before import org.junit.ClassRule import org.junit.Rule import org.junit.rules.Timeout -import java.util.concurrent.TimeUnit open class BaseTest { @@ -86,6 +87,7 @@ open class BaseTest { TeiDataIdlingResourceSingleton.countingIdlingResource, EventIdlingResourceSingleton.countingIdlingResource, OnMapReadyIdlingResourceSingleton.countingIdlingResource, + AnalyticsCountingIdlingResource.countingIdlingResource, ) } @@ -98,6 +100,7 @@ open class BaseTest { SearchIdlingResourceSingleton.countingIdlingResource, TeiDataIdlingResourceSingleton.countingIdlingResource, EventIdlingResourceSingleton.countingIdlingResource, + AnalyticsCountingIdlingResource.countingIdlingResource, ) } diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/idling/AnalyticsCountingIdlingResource.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/idling/AnalyticsCountingIdlingResource.kt new file mode 100644 index 0000000000..b8085bd75e --- /dev/null +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/idling/AnalyticsCountingIdlingResource.kt @@ -0,0 +1,19 @@ +package dhis2.org.analytics.charts.idling + +import androidx.test.espresso.idling.CountingIdlingResource + +object AnalyticsCountingIdlingResource { + private const val RESOURCE = "ANALYTICS" + + @JvmField + val countingIdlingResource = CountingIdlingResource(RESOURCE) + fun increment() { + countingIdlingResource.increment() + } + + fun decrement() { + if (!countingIdlingResource.isIdleNow) { + countingIdlingResource.decrement() + } + } +} diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsFragment.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsFragment.kt index 6b785bbbad..71207f1dca 100644 --- a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsFragment.kt +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsFragment.kt @@ -13,6 +13,7 @@ import dhis2.org.R import dhis2.org.analytics.charts.data.AnalyticGroup import dhis2.org.analytics.charts.di.AnalyticsComponentProvider import dhis2.org.analytics.charts.extensions.isNotCurrent +import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource import dhis2.org.analytics.charts.ui.di.AnalyticsFragmentModule import dhis2.org.analytics.charts.ui.dialog.SearchColumnDialog import dhis2.org.databinding.AnalyticsGroupBinding @@ -250,6 +251,7 @@ class GroupAnalyticsFragment : Fragment() { } } } + AnalyticsCountingIdlingResource.decrement() } } diff --git a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsViewModel.kt b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsViewModel.kt index 721130a132..5855281f93 100644 --- a/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsViewModel.kt +++ b/dhis_android_analytics/src/main/java/dhis2/org/analytics/charts/ui/GroupAnalyticsViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dhis2.org.analytics.charts.Charts import dhis2.org.analytics.charts.data.AnalyticGroup +import dhis2.org.analytics.charts.idling.AnalyticsCountingIdlingResource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.launch @@ -119,6 +120,7 @@ class GroupAnalyticsViewModel( } fun fetchAnalytics(groupUid: String?) { + AnalyticsCountingIdlingResource.increment() currentGroup = groupUid viewModelScope.launch { val result = async(context = Dispatchers.IO) {