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

Commit

Permalink
WIP: Prepare for tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jun 12, 2022
1 parent 27bd6fc commit a85a26e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.ivy.wallet.compose.component.ItemStatisticScreen
import com.ivy.wallet.compose.component.ReorderModal
import com.ivy.wallet.compose.component.home.MainBottomBar
import com.ivy.wallet.compose.hideKeyboard
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.compose.util.printTree
import com.ivy.wallet.ui.theme.Ivy

class AccountsTab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.ivy.wallet.compose.component.category.CategoriesScreen
import com.ivy.wallet.compose.component.loan.LoansScreen
import com.ivy.wallet.compose.component.planned.PlannedPaymentsScreen
import com.ivy.wallet.compose.component.settings.SettingsScreen
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.compose.util.printTree

class HomeMoreMenu(
private val composeTestRule: IvyComposeTestRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.ivy.wallet.compose.component.PieChartScreen
import com.ivy.wallet.compose.component.edittrn.ChooseCategoryModal
import com.ivy.wallet.compose.component.edittrn.screen.TransactionScreen
import com.ivy.wallet.compose.component.edittrn.screen.TransferScreen
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.compose.util.printTree
import com.ivy.wallet.utils.format

class HomeTab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.ui.test.*
import com.ivy.wallet.compose.IvyComposeTestRule
import com.ivy.wallet.compose.component.DeleteConfirmationModal
import com.ivy.wallet.compose.component.DeleteItem
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.compose.util.printTree

class LoanDetailsScreen(
private val composeTestRule: IvyComposeTestRule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ivy.wallet.compose
package com.ivy.wallet.compose.util

import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onRoot
Expand Down
51 changes: 51 additions & 0 deletions app/src/androidTest/java/com/ivy/wallet/compose/util/Scroll.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.ivy.wallet.compose.util

import androidx.compose.ui.test.*
import com.ivy.wallet.compose.IvyComposeTestRule

fun IvyComposeTestRule.scrollNextUntilFound(
lazyColumnTag: String,
index: Int = 0,
maxIndex: Int = 10,
interaction: () -> Unit
) {
try {
onNodeWithTag(lazyColumnTag)
.performScrollToIndex(index)

interaction()
} catch (ignored: Exception) {
if (index <= maxIndex) {
scrollNextUntilFound(
lazyColumnTag = lazyColumnTag,
index = index + 1,
maxIndex = maxIndex,
interaction = interaction
)
}
}
}

fun <T> T.scroll(
container: SemanticsNodeInteraction,
toIndex: Int
): T {
container.performScrollToIndex(index = toIndex)
return this
}

fun <T> T.scroll(
container: SemanticsNodeInteraction,
toKey: String
): T {
container.performScrollToKey(key = toKey)
return this
}

fun <T> T.scroll(
container: SemanticsNodeInteraction,
toMatcher: SemanticsMatcher
): T {
container.performScrollToNode(toMatcher)
return this
}
9 changes: 9 additions & 0 deletions app/src/androidTest/java/com/ivy/wallet/compose/util/Wait.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ivy.wallet.compose.util

import com.ivy.wallet.compose.IvyComposeTestRule
import com.ivy.wallet.compose.waitSeconds

fun <T> T.waitSeconds(composeTestRule: IvyComposeTestRule, seconds: Int): T {
composeTestRule.waitSeconds(seconds.toLong())
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ private fun LazyListScope.upcomingSection(
if (upcoming == null) return //guard

if (upcoming.trns.isNotEmpty()) {
item {
item(
key = "upcoming_section"
) {
SectionDivider(
expanded = upcoming.expanded,
setExpanded = setExpanded,
Expand Down Expand Up @@ -146,7 +148,9 @@ private fun LazyListScope.overdueSection(
if (overdue == null) return

if (overdue.trns.isNotEmpty()) {
item {
item(
key = "overdue_section"
) {
SectionDivider(
expanded = overdue.expanded,
setExpanded = setExpanded,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -297,7 +298,8 @@ fun HomeLazyColumn(
LazyColumn(
modifier = Modifier
.fillMaxSize()
.nestedScroll(nestedScrollConnection),
.nestedScroll(nestedScrollConnection)
.testTag("home_lazy_column"),
state = listState
) {
item {
Expand Down

0 comments on commit a85a26e

Please sign in to comment.