Skip to content

Commit

Permalink
Add Delete Account test
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Nov 22, 2021
1 parent 5c59803 commit 379df7c
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.ivy.wallet.compose.helpers

import android.icu.util.Currency
import androidx.activity.ComponentActivity
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.printTree
import com.ivy.wallet.ui.theme.Ivy

class AccountsTab<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {
private val mainBottomBar = MainBottomBar(composeTestRule)
private val accountModal = AccountModal(composeTestRule)
private val amountInput = AmountInput(composeTestRule)

fun assertAccountBalance(
account: String,
Expand All @@ -24,11 +30,59 @@ class AccountsTab<A : ComponentActivity>(
.and(hasAnyDescendant(hasTextExactly(balance, balanceDecimal, currency)))
).assertExists()

val baseCurrencyBalanceRow = composeTestRule.onNode(
hasText(account)
.and(hasAnyDescendant(hasTestTag("baseCurrencyEquivalent")))
)
if (baseCurrencyEquivalent) {
composeTestRule.onNode(
hasText(account)
.and(hasAnyDescendant(hasTestTag("baseCurrencyEquivalent")))
).assertIsDisplayed()
baseCurrencyBalanceRow.assertIsDisplayed()
} else {
baseCurrencyBalanceRow.assertDoesNotExist()
}
}

fun clickAccount(
account: String
) {
composeTestRule.onNode(hasText(account)).performClick()
}

fun assertAccountNotExists(
account: String
) {
composeTestRule.onNode(hasText(account)).assertDoesNotExist()
}

fun addAccount(
name: String,
color: Color = Ivy,
icon: String? = null,
currency: String? = null,
initialBalance: String? = null
) {
mainBottomBar.clickAddFAB()

accountModal.apply {
enterTitle(name)

ivyColorPicker.chooseColor(color = color)

if (icon != null) {
chooseIconFlow.chooseIcon(icon)
}

if (currency != null) {
chooseCurrency()
currencyPicker.searchAndSelect(Currency.getInstance(currency))
}


if (initialBalance != null) {
clickBalance()
amountInput.enterNumber(initialBalance)
}

clickAdd()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ivy.wallet.compose.helpers

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

class ItemStatisticScreen<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {

fun clickDelete() {
composeTestRule.onNodeWithTag("delete_button")
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ivy.wallet.compose.scenario

import android.icu.util.Currency
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.ivy.wallet.compose.IvyComposeTest
import com.ivy.wallet.compose.helpers.*
import com.ivy.wallet.ui.theme.Blue
Expand All @@ -19,6 +21,7 @@ class AccountsTest : IvyComposeTest() {
private val homeTab = HomeTab(composeTestRule)
private val accountsTab = AccountsTab(composeTestRule)
private val editTransactionScreen = EditTransactionScreen(composeTestRule)
private val itemStatisticScreen = ItemStatisticScreen(composeTestRule)


@Test
Expand Down Expand Up @@ -52,8 +55,8 @@ class AccountsTest : IvyComposeTest() {
onboarding.quickOnboarding()

mainBottomBar.clickAccounts()
mainBottomBar.clickAddFAB()

mainBottomBar.clickAddFAB()
accountModal.apply {
enterTitle("Savings")
ivyColorPicker.chooseColor(Purple2)
Expand All @@ -76,4 +79,42 @@ class AccountsTest : IvyComposeTest() {
baseCurrencyEquivalent = true
)
}

@Test
fun DeleteAccount() {
onboarding.quickOnboarding()

mainBottomBar.clickAccounts()

accountsTab.addAccount(
name = "New Account",
initialBalance = "830"
)

accountsTab.assertAccountBalance(
account = "New Account",
balance = "830",
balanceDecimal = ".00",
currency = "USD",
baseCurrencyEquivalent = false
)

accountsTab.clickAccount("New Account")

itemStatisticScreen.clickDelete()
composeTestRule.onNodeWithText("Delete").performClick()

accountsTab.assertAccountNotExists(
account = "New Account"
)

mainBottomBar.clickHome()
homeTab.assertBalance(
amount = "0",
amountDecimal = ".00",
currency = "USD"
)
}

//TODO: Reorder accounts
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package com.ivy.wallet.ui.theme.components
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.ivy.wallet.R
import com.ivy.wallet.ui.theme.GradientRed
import com.ivy.wallet.ui.theme.White

@Composable
fun DeleteButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {
IvyCircleButton(
modifier = Modifier
.size(48.dp),
modifier = modifier
.size(48.dp)
.testTag("delete_button"),
backgroundPadding = 6.dp,
icon = R.drawable.ic_delete,
backgroundGradient = GradientRed,
Expand Down

0 comments on commit 379df7c

Please sign in to comment.