Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
fix-issue-3488
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Sep 12, 2024
1 parent b30851e commit 69238ad
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private fun BoxWithConstraintsScope.UI(

if (state.showCategorySearchBar) {
Spacer(Modifier.height(16.dp))
SearchField(onSearch = {})
SearchField(onSearch = { onEvent(CategoriesScreenEvent.OnSearchQueryUpdate(it)) })
}
Spacer(Modifier.height(16.dp))
}
Expand Down Expand Up @@ -797,6 +797,16 @@ fun CategoriesScreenUiTest(isDark: Boolean) {
Preview(theme)
}

/** For screenshot testing */
@Composable
fun CategoriesScreenWithSearchBarUiTest(isDark: Boolean) {
val theme = when (isDark) {
true -> Theme.DARK
false -> Theme.LIGHT
}
Preview(theme = theme, displaySearchBarEnabled = true)
}

/** For screenshot testing */
@Composable
fun CategoriesScreenCompactUiTest(isDark: Boolean) {
Expand All @@ -805,4 +815,14 @@ fun CategoriesScreenCompactUiTest(isDark: Boolean) {
false -> Theme.LIGHT
}
Preview(theme, compactModeEnabled = true)
}

/** For screenshot testing */
@Composable
fun CategoriesScreenWithSearchBarCompactUiTest(isDark: Boolean) {
val theme = when (isDark) {
true -> Theme.DARK
false -> Theme.LIGHT
}
Preview(theme, compactModeEnabled = true, displaySearchBarEnabled = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ sealed interface CategoriesScreenEvent {
data class OnSortOrderModalVisible(val visible: Boolean) : CategoriesScreenEvent
data class OnCategoryModalVisible(val categoryModalData: CategoryModalData?) :
CategoriesScreenEvent
data class OnSearchQueryUpdate(val queryString: String) : CategoriesScreenEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.ivy.base.legacy.SharedPrefs
import com.ivy.base.legacy.Transaction
import com.ivy.base.time.TimeConverter
import com.ivy.base.time.TimeProvider
import com.ivy.ui.ComposeViewModel
import com.ivy.data.repository.CategoryRepository
import com.ivy.domain.features.Features
import com.ivy.frp.action.thenMap
import com.ivy.frp.thenInvokeAfter
import com.ivy.legacy.data.model.TimePeriod
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.utils.ioThread
import com.ivy.ui.ComposeViewModel
import com.ivy.wallet.domain.action.account.AccountsAct
import com.ivy.wallet.domain.action.category.LegacyCategoryIncomeWithAccountFiltersAct
import com.ivy.wallet.domain.action.settings.BaseCurrencyAct
Expand Down Expand Up @@ -55,6 +55,8 @@ class CategoriesViewModel @Inject constructor(
private val baseCurrency = mutableStateOf("")
private val categories =
mutableStateOf<ImmutableList<CategoryData>>(persistentListOf<CategoryData>())
private val allCategories =
mutableStateOf<ImmutableList<CategoryData>>(persistentListOf<CategoryData>())
private val reorderModalVisible = mutableStateOf(false)
private val categoryModalData = mutableStateOf<CategoryModalData?>(null)
private val sortModalVisible = mutableStateOf(false)
Expand All @@ -78,6 +80,7 @@ class CategoriesViewModel @Inject constructor(
)
}


@Composable
private fun getCompactCategoriesMode(): Boolean {
return features.compactCategoriesMode.asEnabledState()
Expand Down Expand Up @@ -132,7 +135,11 @@ class CategoriesViewModel @Inject constructor(
ioThread {
val range = TimePeriod.currentMonth(
startDayOfMonth = ivyContext.startDayOfMonth
).toRange(ivyContext.startDayOfMonth, timeConverter, timeProvider) // this must be monthly
).toRange(
ivyContext.startDayOfMonth,
timeConverter,
timeProvider
) // this must be monthly

allAccounts = accountsAct(Unit)
baseCurrency.value = baseCurrencyAct(Unit)
Expand All @@ -141,7 +148,7 @@ class CategoriesViewModel @Inject constructor(
TrnsWithRangeAndAccFiltersAct.Input(
range = range,
accountIdFilterSet = suspend { allAccounts } thenMap { it.id }
thenInvokeAfter { it.toHashSet() }
thenInvokeAfter { it.toHashSet() }
)
)

Expand Down Expand Up @@ -177,9 +184,23 @@ class CategoriesViewModel @Inject constructor(
}

val sortedList = sortList(categories, sortOrder.value).toImmutableList()
this.allCategories.value = sortedList
this.categories.value = this.allCategories.value

}
}

this.categories.value = sortedList
private fun filterCategories(queryString: String) {
var unsortedList : List<CategoryData>
if (queryString.isNotEmpty()) {
unsortedList = this.allCategories.value.filter {
it.category.name.value.toLowerCase().contains(queryString.toLowerCase().trim())
}

} else {
unsortedList = this.allCategories.value
}
this.categories.value = sortList(unsortedList, sortOrder.value).toImmutableList()
}

private suspend fun reorder(
Expand Down Expand Up @@ -250,6 +271,8 @@ class CategoriesViewModel @Inject constructor(
is CategoriesScreenEvent.OnCategoryModalVisible -> {
categoryModalData.value = event.categoryModalData
}

is CategoriesScreenEvent.OnSearchQueryUpdate -> filterCategories(event.queryString)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@ class CategoriesScreenPaparazziTest(
}
}

@Test
fun `snapshot Categories nonCompact Screen with search bar`() {
snapshot(theme) {
CategoriesScreenWithSearchBarUiTest(theme == PaparazziTheme.Dark)
}
}

@Test
fun `snapshot Categories compact Screen`() {
snapshot(theme) {
CategoriesScreenCompactUiTest(theme == PaparazziTheme.Dark)
}
}

@Test
fun `snapshot Categories compact Screen with search bar`() {
snapshot(theme) {
CategoriesScreenWithSearchBarCompactUiTest(theme == PaparazziTheme.Dark)
}
}
}

0 comments on commit 69238ad

Please sign in to comment.