Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Geowidget to only show the Set Location dialog if no Locations to sync by have been selected #3526

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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.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 @@
val sharedPreferencesHelper: SharedPreferencesHelper,
val resourceDataRulesExecutor: ResourceDataRulesExecutor,
val configurationRegistry: ConfigurationRegistry,
@ApplicationContext val context: Context,

Check warning on line 68 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherViewModel.kt#L68

Added line #L68 was not covered by tests
) : ViewModel() {
private val _snackBarStateFlow = MutableSharedFlow<SnackBarMessageConfig>()
val snackBarStateFlow = _snackBarStateFlow.asSharedFlow()
Expand Down Expand Up @@ -175,8 +178,10 @@
}
}

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

Check warning on line 183 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherViewModel.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherViewModel.kt#L183

Added line #L183 was not covered by tests
}
}

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
Loading