Skip to content

Commit

Permalink
Update Geowidget to only show the Set Location dialog if no Locations…
Browse files Browse the repository at this point in the history
… to sync by have been selected (#3526)

* Don't show no results dialogue on map when locations selected on multiselect.

Signed-off-by: Lentumunai-Mark <[email protected]>

* Fix failing tests.

Signed-off-by: Lentumunai-Mark <[email protected]>

---------

Signed-off-by: Lentumunai-Mark <[email protected]>
  • Loading branch information
Lentumunai-Mark authored Oct 7, 2024
1 parent c3166d3 commit 3b66b02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.fhir.datacapture.extensions.logicalId
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -50,6 +51,7 @@ import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.extension.extractLogicalIdUuid
import org.smartregister.fhircore.engine.util.extension.interpolate
import org.smartregister.fhircore.engine.util.extension.retrieveRelatedEntitySyncLocationIds
import org.smartregister.fhircore.geowidget.model.GeoJsonFeature
import org.smartregister.fhircore.geowidget.model.Geometry
import org.smartregister.fhircore.quest.ui.shared.QuestionnaireHandler
Expand All @@ -63,6 +65,7 @@ constructor(
val sharedPreferencesHelper: SharedPreferencesHelper,
val resourceDataRulesExecutor: ResourceDataRulesExecutor,
val configurationRegistry: ConfigurationRegistry,
@ApplicationContext val context: Context,
) : ViewModel() {
private val _snackBarStateFlow = MutableSharedFlow<SnackBarMessageConfig>()
val snackBarStateFlow = _snackBarStateFlow.asSharedFlow()
Expand Down Expand Up @@ -175,8 +178,10 @@ constructor(
}
}

fun showNoLocationDialog(geoWidgetConfiguration: GeoWidgetConfiguration) {
geoWidgetConfiguration.noResults?.let { _noLocationFoundDialog.postValue(true) }
suspend fun showNoLocationDialog(geoWidgetConfiguration: GeoWidgetConfiguration) {
geoWidgetConfiguration.noResults?.let {
_noLocationFoundDialog.postValue(context.retrieveRelatedEntitySyncLocationIds().isEmpty())
}
}

suspend fun onQuestionnaireSubmission(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

package org.smartregister.fhircore.quest.ui.geowidget

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.android.fhir.datacapture.extensions.logicalId
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
import io.mockk.slot
import io.mockk.spyk
import io.mockk.verify
Expand Down Expand Up @@ -68,6 +71,8 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {

@Inject lateinit var resourceDataRulesExecutor: ResourceDataRulesExecutor

private lateinit var applicationContext: Context

private val configurationRegistry = Faker.buildTestConfigurationRegistry()
private lateinit var viewModel: GeoWidgetLauncherViewModel
private val geoWidgetConfiguration =
Expand Down Expand Up @@ -98,20 +103,21 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {
@Before
fun setUp() {
hiltAndroidRule.inject()
applicationContext = ApplicationProvider.getApplicationContext<HiltTestApplication>()
viewModel =
GeoWidgetLauncherViewModel(
defaultRepository = defaultRepository,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
resourceDataRulesExecutor = resourceDataRulesExecutor,
configurationRegistry = configurationRegistry,
context = applicationContext,
)

runBlocking { defaultRepository.addOrUpdate(resource = location) }
}

@Test
fun testShowNoLocationDialogShouldNotSetLiveDataValueWhenConfigIsNull() {
fun testShowNoLocationDialogShouldNotSetLiveDataValueWhenConfigIsNull() = runTest {
val geoWidgetConfiguration =
GeoWidgetConfiguration(
appId = "appId",
Expand All @@ -132,7 +138,7 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {
}

@Test
fun testShowNoLocationDialogShouldSetLiveDataValueWhenConfigIsPresent() {
fun testShowNoLocationDialogShouldSetLiveDataValueWhenConfigIsPresent() = runTest {
viewModel.showNoLocationDialog(geoWidgetConfiguration)
val value = viewModel.noLocationFoundDialog.value
assertNotNull(value)
Expand Down

0 comments on commit 3b66b02

Please sign in to comment.