Fixed bug that whitespace at begin or end was not ignored, leading to missing search results
This commit is contained in:
parent
ba156a8512
commit
d447f2991c
|
@ -25,7 +25,7 @@ class AccountTransactionsFilterService {
|
|||
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()) {
|
||||
appliedAccountFilter
|
||||
} else {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue