diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt index 7a44ec7..e1fa5e1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterService.kt @@ -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 { diff --git a/composeApp/src/commonTest/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterServiceTest.kt b/composeApp/src/commonTest/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterServiceTest.kt new file mode 100644 index 0000000..8ebca52 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/net/codinux/banking/ui/service/AccountTransactionsFilterServiceTest.kt @@ -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 + ) +} \ No newline at end of file