From 478b159965cf9e3a95d1b859514d89214ffa425d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manu=20Mu=C3=B1oz?= Date: Mon, 29 Apr 2024 12:36:41 +0200 Subject: [PATCH] fix: [ANDROAPP-6062] clear search fields when required attributes to search (#3581) * fix: [ANDROAPP-6062] clear search fields when required attributes to search * add clear test --- .../searchTrackEntity/SearchTEIViewModel.kt | 8 +++++++- .../searchparameters/SearchParametersScreen.kt | 1 + .../searchTrackEntity/SearchTEIViewModelTest.kt | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModel.kt b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModel.kt index ff326ec108..38441502cd 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModel.kt @@ -277,7 +277,11 @@ class SearchTEIViewModel( val updatedItems = uiState.items.map { (it as FieldUiModelImpl).copy(value = null, displayName = null) } - uiState = uiState.copy(items = updatedItems) + uiState = uiState.copy( + items = updatedItems, + searchedItems = mapOf(), + ) + searching = false } private fun updateSearch() { @@ -463,6 +467,8 @@ class SearchTEIViewModel( ) uiState = uiState.copy(minAttributesMessage = message) uiState.updateMinAttributeWarning(true) + setSearchScreen() + _refreshData.postValue(Unit) } } } diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt index 5b7a857361..af52d14a5b 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt @@ -144,6 +144,7 @@ fun SearchParametersScreen( message = message, duration = SnackbarDuration.Short, ) + uiState.updateMinAttributeWarning(false) } } } diff --git a/app/src/test/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModelTest.kt b/app/src/test/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModelTest.kt index 6a28db5deb..143ca66547 100644 --- a/app/src/test/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModelTest.kt +++ b/app/src/test/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModelTest.kt @@ -652,7 +652,17 @@ class SearchTEIViewModelTest { } @Test - fun `should return test`() { + fun `should clear uiState when clearing data`() { + viewModel.uiState = viewModel.uiState.copy(items = getFieldUIModels()) + performSearch() + viewModel.clearQueryData() + assert(viewModel.queryData.isEmpty()) + assert(viewModel.uiState.items.all { it.value == null }) + assert(viewModel.uiState.searchedItems.isEmpty()) + } + + @Test + fun `should return date without format`() { viewModel.uiState = viewModel.uiState.copy(items = getMalformedDateFieldUIModels()) val expectedMap = mapOf( "uid1" to "04",