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

Commit

Permalink
Refactor unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevo160296 committed Jun 12, 2022
1 parent 3957e68 commit 1c83d1e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ class HomeTab(
return this
}

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

fun assertGreeting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,35 @@ open class ItemStatisticScreen(
composeTestRule.onNodeWithTag("toolbar_close")
.performScrollTo()
.performClick()
return next
}

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

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

fun clickTransactionPay(){
fun clickTransactionPay(): ItemStatisticScreen{
composeTestRule.onNode(
hasText("Pay")
.and(hasAnyAncestor(hasTestTag("transaction_card")))
)
.performScrollTo()
.performClick()
return next
return this
}

fun assertBalance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.ivy.wallet.compose.helpers.HomeTab
import com.ivy.wallet.compose.helpers.PlannedPaymentsScreen
import com.ivy.wallet.domain.data.IntervalType
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.ui.main.MainTab
import com.ivy.wallet.utils.timeNowUTC
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test
Expand All @@ -18,18 +19,6 @@ import org.junit.Test
class PlannedPaymentsTest : IvyComposeTest() {


private val onboardingFlow = OnboardingFlow(composeTestRule)
private val transactionFlow = TransactionFlow(composeTestRule)
private val editPlannedScreen = EditPlannedScreen(composeTestRule)
private val homeTab = HomeTab(composeTestRule)
private val mainBottomBar = MainBottomBar(composeTestRule)
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 {
quickOnboarding()
Expand Down Expand Up @@ -267,160 +256,104 @@ class PlannedPaymentsTest : IvyComposeTest() {

@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()
quickOnboarding()
.clickAddFAB()
.clickAddPlannedPayment()
.addPlannedPayment(
next = HomeTab(composeTestRule),
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
.clickUpcoming()
.clickTransactionSkip()
.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"
)
quickOnboarding()
.clickAddFAB()
.clickAddPlannedPayment()
.addPlannedPayment(
next = HomeTab(composeTestRule),
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
.clickUpcoming()
.clickTransactionPay()
.assertUpcomingDoesNotExist()
.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")
quickOnboarding()
.clickAddFAB()
.clickAddPlannedPayment()
.addPlannedPayment(
next = HomeTab(composeTestRule),
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
.clickAccountsTab()
.clickAccount("Cash")
.clickUpcoming()
.clickTransactionSkip()
.clickClose(AccountsTab(composeTestRule))
.clickHomeTab()
.assertUpcomingDoesNotExist()

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

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

mainBottomBar.clickHome()
homeTab.assertUpcomingDoesNotExist()
/*composeTestRule.waitMillis(500)*/
}

@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"
)
quickOnboarding()
.clickAddFAB()
.clickAddPlannedPayment()
.addPlannedPayment(
next=HomeTab(composeTestRule),
type = TransactionType.EXPENSE,
oneTime = true,
amount = "530.25",
category = "Transport",
startDate = null,
intervalN = null,
intervalType = null,
title = "Netherlands airplane"
)
.clickAccountsTab()
.clickAccount("Cash")
.clickUpcoming()
.clickTransactionPay()
.clickClose(AccountsTab(composeTestRule))
.clickHomeTab()
.assertUpcomingDoesNotExist()
.assertBalance(
amount = "-530",
amountDecimal = ".25"
)
}
}

0 comments on commit 1c83d1e

Please sign in to comment.