Skip to content

Commit

Permalink
fix: [ANDROAPP-6062] clear search fields when required attributes to …
Browse files Browse the repository at this point in the history
…search (#3581)

* fix: [ANDROAPP-6062] clear search fields when required attributes to search

* add clear test
  • Loading branch information
mmmateos authored Apr 29, 2024
1 parent ea49f9a commit 478b159
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -463,6 +467,8 @@ class SearchTEIViewModel(
)
uiState = uiState.copy(minAttributesMessage = message)
uiState.updateMinAttributeWarning(true)
setSearchScreen()
_refreshData.postValue(Unit)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fun SearchParametersScreen(
message = message,
duration = SnackbarDuration.Short,
)
uiState.updateMinAttributeWarning(false)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 478b159

Please sign in to comment.