Skip to content

Commit

Permalink
Refactor CreatePlannedPayment test
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Nov 24, 2021
1 parent 4cffcc6 commit f325c7f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import androidx.compose.ui.test.printToLog

const val COMPOSE_TEST_TAG = "compose_test"

fun ComposeTestRule.printTree() {
this.onRoot(useUnmergedTree = false).printToLog(COMPOSE_TEST_TAG)
fun ComposeTestRule.printTree(useUnmergedTree: Boolean = true) {
this.onRoot(useUnmergedTree = useUnmergedTree).printToLog(COMPOSE_TEST_TAG)
}
28 changes: 28 additions & 0 deletions app/src/androidTest/java/com/ivy/wallet/compose/helpers/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,32 @@ class HomeTab<A : ComponentActivity>(
.and(hasText(amount))
).assertDoesNotExist()
}

fun assertUpcomingIncome(
amount: String,
currency: String
) {
composeTestRule.onNodeWithTag(
testTag = "upcoming_income",
useUnmergedTree = true
).assertTextEquals("$amount $currency")
}

fun assertUpcomingExpense(
amount: String,
currency: String
) {
composeTestRule.onNodeWithTag(
testTag = "upcoming_expense",
useUnmergedTree = true
).assertTextEquals("$amount $currency")
}

fun clickUpcoming() {
composeTestRule.onNodeWithTag(
testTag = "upcoming_title",
useUnmergedTree = true
)
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.ivy.wallet.compose.scenario

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import com.ivy.wallet.base.timeNowUTC
Expand All @@ -10,7 +8,6 @@ import com.ivy.wallet.compose.helpers.EditPlannedScreen
import com.ivy.wallet.compose.helpers.HomeTab
import com.ivy.wallet.compose.helpers.OnboardingFlow
import com.ivy.wallet.compose.helpers.TransactionFlow
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.model.IntervalType
import com.ivy.wallet.model.TransactionType
import dagger.hilt.android.testing.HiltAndroidTest
Expand Down Expand Up @@ -45,13 +42,12 @@ class PlannedPaymentsTest : IvyComposeTest() {
title = "Salary"
)

composeTestRule.waitForIdle()

composeTestRule.onNode(hasText("2,000.00 USD"))
.assertIsDisplayed()
.performClick()
homeTab.assertUpcomingIncome(
amount = "2,000.00",
currency = "USD"
)

composeTestRule.printTree()
homeTab.clickUpcoming()

homeTab.clickTransaction(
amount = "2,000.00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class EditPlannedViewModel @Inject constructor(
}

viewModelScope.launch {
TestIdlingResource.increment()

try {
ioThread {
loadedRule = loadedRule().copy(
Expand Down Expand Up @@ -271,6 +273,8 @@ class EditPlannedViewModel @Inject constructor(
} catch (e: Exception) {
e.printStackTrace()
}

TestIdlingResource.decrement()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -52,6 +53,7 @@ fun SectionDivider(

Column {
Text(
modifier = Modifier.testTag("upcoming_title"),
text = title,
style = Typo.body1.style(
fontWeight = FontWeight.ExtraBold,
Expand Down Expand Up @@ -94,6 +96,7 @@ private fun SectionDividerIncomeExpenseRow(
) {
if (expenses > 0) {
Text(
modifier = Modifier.testTag("upcoming_expense"),
text = "${expenses.format(baseCurrency)} $baseCurrency",
style = Typo.numberCaption.style(
fontWeight = FontWeight.ExtraBold,
Expand All @@ -120,6 +123,7 @@ private fun SectionDividerIncomeExpenseRow(

if (income > 0) {
Text(
modifier = Modifier.testTag("upcoming_income"),
text = "${income.format(baseCurrency)} $baseCurrency",
style = Typo.numberCaption.style(
fontWeight = FontWeight.ExtraBold,
Expand Down

0 comments on commit f325c7f

Please sign in to comment.