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

Commit

Permalink
Added unit tests for skip and pay planned payments in the home screen…
Browse files Browse the repository at this point in the history
… and account detail screen.
  • Loading branch information
jevo160296 committed Jun 12, 2022
1 parent b9dd2bd commit 5ba2b8d
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class HomeTab<A : ComponentActivity>(
currency: String = "USD"
) {
composeTestRule.onNodeWithTag("home_balance")
.performScrollTo()
.assertTextEquals(currency, amount, amountDecimal)
}

Expand Down Expand Up @@ -113,7 +114,9 @@ class HomeTab<A : ComponentActivity>(
composeTestRule.onNodeWithTag(
testTag = "upcoming_title",
useUnmergedTree = true
).performClick()
)
.performScrollTo()
.performClick()
}

fun clickTransactionPay() {
Expand All @@ -125,6 +128,15 @@ class HomeTab<A : ComponentActivity>(
.performClick()
}

fun clickTransactionSkip() {
composeTestRule.onNode(
hasText("Skip")
.and(hasAnyAncestor(hasTestTag("transaction_card")))
)
.performScrollTo()
.performClick()
}

fun assertGreeting(
greeting: String
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule

class ItemStatisticScreen<A : ComponentActivity>(
Expand All @@ -24,6 +21,32 @@ class ItemStatisticScreen<A : ComponentActivity>(

fun clickClose() {
composeTestRule.onNodeWithTag("toolbar_close")
.performScrollTo()
.performClick()
}

fun clickUpcoming() {
composeTestRule.onNodeWithTag(
testTag = "upcoming_title",
useUnmergedTree = true
).performClick()
}

fun clickTransactionSkip(){
composeTestRule.onNode(
hasText("Skip")
.and(hasAnyAncestor(hasTestTag("transaction_card")))
)
.performScrollTo()
.performClick()
}

fun clickTransactionPay(){
composeTestRule.onNode(
hasText("Pay")
.and(hasAnyAncestor(hasTestTag("transaction_card")))
)
.performScrollTo()
.performClick()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import com.ivy.wallet.compose.IvyComposeTest
import com.ivy.wallet.compose.helpers.*
import com.ivy.wallet.compose.waitMillis
import com.ivy.wallet.domain.data.IntervalType
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.utils.timeNowUTC
Expand All @@ -21,6 +22,10 @@ class PlannedPaymentsTest : IvyComposeTest() {
private val deleteConfirmationModal = DeleteConfirmationModal(composeTestRule)
private val homeMoreMenu = HomeMoreMenu(composeTestRule)
private val plannedPaymentsScreen = PlannedPaymentsScreen(composeTestRule)
private val accountsTab = AccountsTab(composeTestRule)
private val itemStatisticScreen = ItemStatisticScreen(composeTestRule)
private val accountModal = AccountModal(composeTestRule)
private val amountInput = AmountInput(composeTestRule)

@Test
fun Onboard_CreatePlannedPaymentFromPrompt() = testWithRetry {
Expand Down Expand Up @@ -274,4 +279,163 @@ class PlannedPaymentsTest : IvyComposeTest() {
amountDecimal = ".00"
)
}

@Test
fun skipPlannedPaymentsOnHomeTab() = testWithRetry{
onboardingFlow.quickOnboarding()

// Dismiss initial prompt
mainBottomBar.clickAccounts()
accountsTab.clickAccount("Bank")
itemStatisticScreen.clickEdit()
accountModal.apply {
clickBalance()
amountInput.enterNumber("13")
clickSave()
}
itemStatisticScreen.clickEdit()
accountModal.apply{
clickBalance()
amountInput.enterNumber("0")
clickSave()
}
itemStatisticScreen.clickClose()

mainBottomBar.clickHome()
// Dismiss initial prompt


try {
mainBottomBar.clickAddPlannedPayment()
} catch (e: Exception) {
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddPlannedPayment()
}

editPlannedScreen.addPlannedPayment(
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
homeTab.clickUpcoming()
homeTab.clickTransactionSkip()
homeTab.assertUpcomingDoesNotExist()
}

@Test
fun payPlannedPaymentsOnHomeTab() = testWithRetry{
onboardingFlow.quickOnboarding()

// Dismiss initial prompt
mainBottomBar.clickAccounts()
accountsTab.clickAccount("Bank")
itemStatisticScreen.clickEdit()
accountModal.apply {
clickBalance()
amountInput.enterNumber("13")
clickSave()
}
itemStatisticScreen.clickEdit()
accountModal.apply{
clickBalance()
amountInput.enterNumber("0")
clickSave()
}
itemStatisticScreen.clickClose()

mainBottomBar.clickHome()
// Dismiss initial prompt

try {
mainBottomBar.clickAddPlannedPayment()
} catch (e: Exception) {
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddPlannedPayment()
}

editPlannedScreen.addPlannedPayment(
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
homeTab.clickUpcoming()
homeTab.clickTransactionPay()
homeTab.assertUpcomingDoesNotExist()
homeTab.assertBalance(
amount = "-530",
amountDecimal = ".25"
)
}

@Test
fun skipPlannedPaymentsOnAccountTab() = testWithRetry{
onboardingFlow.quickOnboarding()
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddPlannedPayment()
editPlannedScreen.addPlannedPayment(
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
mainBottomBar.clickAccounts()
accountsTab.clickAccount("Cash")

//Wait until the upcoming payments are loaded
composeTestRule.waitMillis(500)

itemStatisticScreen.clickUpcoming()
itemStatisticScreen.clickTransactionSkip()
itemStatisticScreen.clickClose()

mainBottomBar.clickHome()
homeTab.assertUpcomingDoesNotExist()
}

@Test
fun payPlannedPaymentsOnAccountTab() = testWithRetry{
onboardingFlow.quickOnboarding()
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddPlannedPayment()
editPlannedScreen.addPlannedPayment(
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
mainBottomBar.clickAccounts()
accountsTab.clickAccount("Cash")

//Wait until the upcoming payments are loaded
composeTestRule.waitMillis(500)

itemStatisticScreen.clickUpcoming()
itemStatisticScreen.clickTransactionPay()
itemStatisticScreen.clickClose()

mainBottomBar.clickHome()
homeTab.assertUpcomingDoesNotExist()
homeTab.assertBalance(
amount = "-530",
amountDecimal = ".25"
)
}
}

0 comments on commit 5ba2b8d

Please sign in to comment.