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

Fix Missing Translations by Passing the Correct Context to retrieveLocations. #3709

Merged
merged 1 commit into from
Jan 31, 2025
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 @@ -179,12 +179,13 @@
searchQuery = searchViewModel.searchQuery,
search = { searchText ->
geoWidgetLauncherViewModel.run {
onEvent(GeoWidgetEvent.ClearMap)
onEvent(GeoWidgetEvent.ClearMap, context)

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L182

Added line #L182 was not covered by tests
onEvent(
GeoWidgetEvent.RetrieveFeatures(
searchQuery = SearchQuery(searchText, SearchMode.KeyboardInput),
geoWidgetConfig = geoWidgetConfiguration,
),
context,

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L188

Added line #L188 was not covered by tests
)
}
},
Expand Down Expand Up @@ -227,13 +228,14 @@
is CurrentSyncJobStatus.Failed, -> {
appMainViewModel.updateAppDrawerUIState(currentSyncJobStatus = syncJobStatus)
if (syncJobStatus is CurrentSyncJobStatus.Succeeded) {
geoWidgetLauncherViewModel.onEvent(GeoWidgetEvent.ClearMap)
geoWidgetLauncherViewModel.onEvent(GeoWidgetEvent.ClearMap, context = requireContext())

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L231

Added line #L231 was not covered by tests
}
geoWidgetLauncherViewModel.onEvent(
GeoWidgetEvent.RetrieveFeatures(
geoWidgetConfig = geoWidgetConfiguration,
searchQuery = searchViewModel.searchQuery.value,
),
context = requireContext(),

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L238

Added line #L238 was not covered by tests
)
}
else -> appMainViewModel.updateAppDrawerUIState(currentSyncJobStatus = syncJobStatus)
Expand All @@ -252,12 +254,13 @@
is AppEvent.OnSubmitQuestionnaire, -> {
appMainViewModel.countRegisterData()
geoWidgetLauncherViewModel.run {
onEvent(GeoWidgetEvent.ClearMap)
onEvent(GeoWidgetEvent.ClearMap, context = requireContext())

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L257

Added line #L257 was not covered by tests
onEvent(
GeoWidgetEvent.RetrieveFeatures(
geoWidgetConfig = geoWidgetConfiguration,
searchQuery = searchViewModel.searchQuery.value,
),
context = requireContext(),

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L263

Added line #L263 was not covered by tests
)
}
}
Expand Down Expand Up @@ -296,6 +299,7 @@
geoWidgetConfig = geoWidgetConfiguration,
searchQuery = searchViewModel.searchQuery.value,
),
context = requireContext(),

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

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/geowidget/GeoWidgetLauncherFragment.kt#L302

Added line #L302 was not covered by tests
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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.asSharedFlow
Expand Down Expand Up @@ -67,7 +66,6 @@
val sharedPreferencesHelper: SharedPreferencesHelper,
val rulesExecutor: RulesExecutor,
val configurationRegistry: ConfigurationRegistry,
@ApplicationContext val context: Context,
) : ViewModel() {
val clearMapLiveData: MutableLiveData<Boolean> = MutableLiveData()
val geoJsonFeatures: MutableLiveData<List<GeoJsonFeature>> = MutableLiveData()
Expand All @@ -88,17 +86,22 @@

private val decodedImageMap = mutableStateMapOf<String, Bitmap>()

fun onEvent(geoWidgetEvent: GeoWidgetEvent) {
fun onEvent(geoWidgetEvent: GeoWidgetEvent, context: Context) {
when (geoWidgetEvent) {
is GeoWidgetEvent.RetrieveFeatures ->
retrieveLocations(geoWidgetEvent.geoWidgetConfig, geoWidgetEvent.searchQuery.query)
retrieveLocations(
geoWidgetEvent.geoWidgetConfig,
geoWidgetEvent.searchQuery.query,
context,

Check warning on line 95 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#L92-L95

Added lines #L92 - L95 were not covered by tests
)
GeoWidgetEvent.ClearMap -> clearMapLiveData.postValue(true)
}
}

private fun retrieveLocations(
geoWidgetConfig: GeoWidgetConfiguration,
searchText: String?,
context: Context,
) {
viewModelScope.launch {
_isSyncing.postValue(true)
Expand Down Expand Up @@ -235,7 +238,10 @@
}
}

suspend fun showNoLocationDialog(geoWidgetConfiguration: GeoWidgetConfiguration) {
suspend fun showNoLocationDialog(
geoWidgetConfiguration: GeoWidgetConfiguration,
context: Context,
) {
geoWidgetConfiguration.noResults?.let {
_noLocationFoundDialog.postValue(
context.retrieveRelatedEntitySyncLocationState(MultiSelectViewAction.SYNC_DATA).isEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {
sharedPreferencesHelper = sharedPreferencesHelper,
rulesExecutor = rulesExecutor,
configurationRegistry = configurationRegistry,
context = applicationContext,
)
runBlocking { defaultRepository.addOrUpdate(resource = location) }
}
Expand All @@ -125,15 +124,15 @@ class GeoWidgetLauncherViewModelTest : RobolectricTest() {
servicePointConfig = null,
)

viewModel.showNoLocationDialog(geoWidgetConfiguration)
viewModel.showNoLocationDialog(geoWidgetConfiguration, context = applicationContext)

val value = viewModel.noLocationFoundDialog.value
assertNull(value)
}

@Test
fun testShowNoLocationDialogShouldSetLiveDataValueWhenConfigIsPresent() = runTest {
viewModel.showNoLocationDialog(geoWidgetConfiguration)
viewModel.showNoLocationDialog(geoWidgetConfiguration, applicationContext)
val value = viewModel.noLocationFoundDialog.value
assertNotNull(value)
assertTrue(value!!)
Expand Down
Loading