Skip to content

Commit

Permalink
fix: [ANDROAPP-6717] Crash when syncing a TEI from map
Browse files Browse the repository at this point in the history
  • Loading branch information
Balcan committed Dec 17, 2024
1 parent e8707ec commit 6844713
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/src/androidTest/java/org/dhis2/usescases/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -86,6 +87,7 @@ open class BaseTest {
TeiDataIdlingResourceSingleton.countingIdlingResource,
EventIdlingResourceSingleton.countingIdlingResource,
OnMapReadyIdlingResourceSingleton.countingIdlingResource,
AnalyticsCountingIdlingResource.countingIdlingResource,
)
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -250,6 +251,7 @@ class GroupAnalyticsFragment : Fragment() {
}
}
}
AnalyticsCountingIdlingResource.decrement()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,6 +120,7 @@ class GroupAnalyticsViewModel(
}

fun fetchAnalytics(groupUid: String?) {
AnalyticsCountingIdlingResource.increment()
currentGroup = groupUid
viewModelScope.launch {
val result = async(context = Dispatchers.IO) {
Expand Down

0 comments on commit 6844713

Please sign in to comment.