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

Commit

Permalink
WIP: The Great tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jun 11, 2022
1 parent 1d421e9 commit 810c504
Show file tree
Hide file tree
Showing 39 changed files with 542 additions and 497 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.junit.Before
import org.junit.Rule
import javax.inject.Inject

typealias IvyComposeTestRule = AndroidComposeTestRule<ActivityScenarioRule<RootActivity>, RootActivity>

@HiltAndroidTest
abstract class IvyComposeTest {
Expand All @@ -48,9 +49,8 @@ abstract class IvyComposeTest {

//----------------------------
protected val onboarding = OnboardingFlow(composeTestRule)
protected val amountInput = AmountInput(composeTestRule)
protected val amountInput = IvyAmountInput(composeTestRule)
protected val accountModal = AccountModal(composeTestRule)
protected val mainBottomBar = MainBottomBar(composeTestRule)
protected val transactionFlow = TransactionFlow(composeTestRule)
protected val homeTab = HomeTab(composeTestRule)
protected val accountsTab = AccountsTab(composeTestRule)
Expand Down Expand Up @@ -140,7 +140,7 @@ abstract class IvyComposeTest {
attempt: Int = 0,
maxAttempts: Int = 3,
firstFailure: Throwable? = null,
test: OnboardingFlow<RootActivity>.() -> Unit
test: OnboardingFlow.() -> Unit
) {
try {
onboarding.test()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,77 @@
package com.ivy.wallet.compose.helpers

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.IvyComposeTestRule

class AccountModal<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {
val ivyColorPicker = IvyColorPicker(composeTestRule)
val chooseIconFlow = ChooseIconFlow(composeTestRule)
val currencyPicker = CurrencyPicker(composeTestRule)
class AccountModal(
private val composeTestRule: IvyComposeTestRule
) : ColorPicker<AccountModal>, IconPicker<AccountModal>,
CurrencyPicker<AccountModal>, AmountInput<AccountModal> {

fun enterTitle(
title: String
) {
): AccountModal {
composeTestRule.onNodeWithTag("base_input")
.performTextReplacement(title)
return this
}

fun clickBalance() {
private fun clickBalance(): IvyAmountInput {
composeTestRule
.onNode(hasTestTag("amount_balance"))
.performClick()
return IvyAmountInput(composeTestRule)
}

fun chooseCurrency() {
private fun clickCurrency(): IvyCurrencyPicker {
composeTestRule.onNodeWithTag("account_modal_currency")
.performClick()
return IvyCurrencyPicker(composeTestRule)
}

fun clickSave() {
fun <N> clickSave(next: N): N {
composeTestRule
.onNode(hasText("Save"))
.performClick()
return next
}

fun clickAdd() {
fun clickAdd(): AccountsTab {
composeTestRule
.onNode(hasText("Add"))
.performClick()
return AccountsTab(composeTestRule)
}

fun tapIncludeInBalance() {
fun tapIncludeInBalance(): AccountModal {
composeTestRule.onNodeWithText("Include account")
.performClick()
return this
}

override fun chooseColor(color: Color): AccountModal {
IvyColorPicker(composeTestRule).chooseColor(color)
return this
}

override fun chooseIcon(icon: String): AccountModal {
ChooseIconFlow(composeTestRule).chooseIcon(icon)
return this
}


override fun chooseCurrency(currencyCode: String): AccountModal {
clickCurrency()
.chooseCurrency(currencyCode)
return this
}

override fun enterAmount(number: String): AccountModal {
return clickBalance()
.enterNumber(
number = number,
next = this
)
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
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.IvyComposeTestRule
import com.ivy.wallet.compose.hideKeyboard
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)
class AccountsTab(
private val composeTestRule: IvyComposeTestRule
) : MainBottomBar<AccountModal>(composeTestRule) {

fun assertAccountBalance(
account: String,
balance: String,
balanceDecimal: String,
currency: String = "USD",
baseCurrencyEquivalent: Boolean = false
) {
): AccountsTab {
composeTestRule.printTree()

composeTestRule.onNode(
Expand All @@ -40,18 +34,22 @@ class AccountsTab<A : ComponentActivity>(
} else {
baseCurrencyBalanceRow.assertDoesNotExist()
}

return this
}

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

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

fun addAccount(
Expand All @@ -60,38 +58,33 @@ class AccountsTab<A : ComponentActivity>(
icon: String? = null,
currency: String? = null,
initialBalance: String? = null
) {
mainBottomBar.clickAddFAB()

accountModal.apply {
enterTitle(name)

): AccountsTab = clickAddFAB(next = AccountModal(composeTestRule))
.enterTitle(name)
.apply {
composeTestRule.hideKeyboard()

ivyColorPicker.chooseColor(color = color)

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

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


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

clickAdd()
}
}

fun clickReorder() {
fun clickReorder(): ReorderModal {
composeTestRule.onNodeWithTag("reorder_button")
.performClick()
return ReorderModal(composeTestRule)
}

override fun clickAddFAB(): AccountModal {
return clickAddFAB(next = AccountModal(composeTestRule))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ivy.wallet.compose.helpers

import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.onNodeWithText
import com.ivy.wallet.compose.IvyComposeTestRule
import com.ivy.wallet.compose.clickWithRetry
import com.ivy.wallet.compose.performClickWithRetry

class AddFABMenu(
private val composeTestRule: IvyComposeTestRule
) {
fun clickAddIncome(): TransactionScreen {
composeTestRule.clickWithRetry(
node = composeTestRule.onNode(hasText("ADD INCOME")),
maxRetries = 3
)
return TransactionScreen(composeTestRule)
}

fun clickAddExpense(): TransactionScreen {
composeTestRule.onNode(hasText("ADD EXPENSE"))
.performClickWithRetry(composeTestRule)
return TransactionScreen(composeTestRule)
}

fun clickAddTransfer(): TransactionScreen {
composeTestRule.onNode(hasText("ACCOUNT TRANSFER"))
.performClickWithRetry(composeTestRule)
return TransactionScreen(composeTestRule)
}

fun clickAddPlannedPayment(): EditPlannedScreen {
composeTestRule.onNodeWithText("Add planned payment")
.performClickWithRetry(composeTestRule)
return EditPlannedScreen(composeTestRule)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.IvyComposeTestRule

class BudgetModal<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
class BudgetModal(
private val composeTestRule: IvyComposeTestRule
) {
private val amountInput = AmountInput(composeTestRule)
private val amountInput = IvyAmountInput(composeTestRule)

fun enterName(budgetName: String) {
composeTestRule.onNodeWithTag("base_input")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.IvyComposeTestRule

class BudgetsScreen<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
class BudgetsScreen(
private val composeTestRule: IvyComposeTestRule
) {
fun clickAddBudget() {
composeTestRule.onNodeWithText("Add budget")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.ivy.wallet.compose.helpers

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.IvyComposeTestRule

class CategoriesScreen<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
class CategoriesScreen(
private val composeTestRule: IvyComposeTestRule
) {
private val categoryModal = CategoryModal(composeTestRule)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextReplacement
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.IvyComposeTestRule

class CategoryModal<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
class CategoryModal(
private val composeTestRule: IvyComposeTestRule
) {
val colorPicker = IvyColorPicker(composeTestRule)
val chooseIconFlow = ChooseIconFlow(composeTestRule)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.IvyComposeTestRule

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

fun selectCategory(categoryName: String) {
fun <N> selectCategory(categoryName: String, next: N): N {
composeTestRule.onNode(
hasTestTag("choose_category_button").and(hasText(categoryName))
).performClick()
return next
}

fun skip() {
fun <N> skip(next: N): N {
composeTestRule.onNodeWithText("Skip")
.performClick()
return next
}
}
Loading

0 comments on commit 810c504

Please sign in to comment.