Fixed bug that whitespace at begin or end was not ignored, leading to missing search results

This commit is contained in:
dankito 2024-09-19 01:50:47 +02:00
parent ba156a8512
commit d447f2991c
2 changed files with 36 additions and 1 deletions

View File

@ -25,7 +25,7 @@ class AccountTransactionsFilterService {
appliedAccountFilter = appliedAccountFilter.filter { it.valueDate.year == year && (month == null || it.valueDate.monthNumber == month) } appliedAccountFilter = appliedAccountFilter.filter { it.valueDate.year == year && (month == null || it.valueDate.monthNumber == month) }
} }
val searchTerms = filter.searchTerm.split(SearchTermOrSeparatorSymbol).filter { it.isNotBlank() } val searchTerms = filter.searchTerm.split(SearchTermOrSeparatorSymbol).filter { it.isNotBlank() }.map { it.trim() }
return if (searchTerms.isEmpty()) { return if (searchTerms.isEmpty()) {
appliedAccountFilter appliedAccountFilter
} else { } else {

View File

@ -0,0 +1,35 @@
package net.codinux.banking.ui.service
import kotlinx.datetime.*
import net.codinux.banking.client.model.Amount
import net.codinux.banking.client.model.DefaultValues
import net.codinux.banking.client.model.extensions.EuropeBerlin
import net.codinux.banking.ui.model.AccountTransactionViewModel
import net.codinux.banking.ui.model.AccountTransactionsFilter
import kotlin.test.Test
import kotlin.test.assertEquals
class AccountTransactionsFilterServiceTest {
private val underTest = AccountTransactionsFilterService()
@Test
fun filterAccounts_TermsSeparatedByComma_WhitespaceGetsFilteredOut() {
// before whitespace after comma led to that for " rewe" was search which yielded no results (as opposed to "rewe") -> ensure whitespace gets remove
val filter = filter("edeka, rewe")
val result = underTest.filterAccounts(listOf(transaction("Edeka"), transaction("Rewe")), filter)
assertEquals(2, result.size)
}
private fun filter(searchTerm: String = "") = AccountTransactionsFilter().apply {
this.updateSearchTerm(searchTerm)
}
private fun transaction(reference: String? = null, otherPartyName: String? = null, valueDate: LocalDate = Clock.System.todayIn(TimeZone.EuropeBerlin)) = AccountTransactionViewModel(
-1, -1, -1, Amount("0"), DefaultValues.DefaultCurrency, reference, valueDate, otherPartyName
)
}