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",