Skip to content

Commit

Permalink
Rework LoansTest.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jun 11, 2022
1 parent d83e087 commit e350ff2
Show file tree
Hide file tree
Showing 7 changed files with 414 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,80 @@ import com.ivy.wallet.compose.printTree

class LoanDetailsScreen(
private val composeTestRule: IvyComposeTestRule
) {
) : DeleteItem<LoansScreen> {

fun clickEdit() {
fun clickEdit(): LoanModal {
composeTestRule.onNodeWithText("Edit")
.performClick()
return LoanModal(composeTestRule)
}

fun assertLoanAmount(
amount: String,
amountDecimal: String,
currency: String = "USD"
) {
): LoanDetailsScreen {
composeTestRule.onNodeWithTag("loan_amount")
.assertTextEquals(currency, amount, amountDecimal)
return this
}

fun assertLoanName(
loanName: String
) {
): LoanDetailsScreen {
composeTestRule.onNodeWithTag("loan_name", useUnmergedTree = true)
.assertTextEquals(loanName)
return this
}

fun assertAmountPaid(
amountPaid: String,
loanAmount: String
) {
): LoanDetailsScreen {
composeTestRule.onNodeWithTag("amount_paid", useUnmergedTree = true)
.assertTextEquals("$amountPaid / $loanAmount")
return this
}

fun assertPercentPaid(
percentPaid: String
) {
): LoanDetailsScreen {
composeTestRule.onNodeWithTag("percent_paid", useUnmergedTree = true)
.assertTextEquals(percentPaid)
return this
}

fun assertLeftToPay(
leftToPayAmount: String,
currency: String = "USD"
) {
): LoanDetailsScreen {
composeTestRule.onNodeWithTag("left_to_pay", useUnmergedTree = true)
.assertTextEquals("$leftToPayAmount $currency left")
return this
}

fun clickDelete() {
private fun clickDelete(): DeleteConfirmationModal {
composeTestRule.onNodeWithTag("delete_button")
.performClick()
return DeleteConfirmationModal(composeTestRule)
}

fun clickClose() {
fun clickClose(): LoansScreen {
composeTestRule.onNodeWithTag("toolbar_close")
.performClick()
return LoansScreen(composeTestRule)
}

fun addRecord() {
fun addRecord(): LoanRecordModal {
composeTestRule.onNodeWithText("Add record")
.performClick()
return LoanRecordModal(composeTestRule)
}

fun clickLoanRecord(
amount: String,
note: String? = null,
) {
): LoanRecordModal {
var matcher = hasTestTag("loan_record_item")
.and(hasAnyDescendant(hasText(amount)))

Expand All @@ -85,10 +94,18 @@ class LoanDetailsScreen(
.assertHasClickAction()
.performScrollTo()
.performClick()

return LoanRecordModal(composeTestRule)
}

fun assertNoRecordsEmptyState() {
fun assertNoRecordsEmptyState(): LoanDetailsScreen {
composeTestRule.onNodeWithText("No records")
.assertIsDisplayed()
return this
}

override fun deleteWithConfirmation(): LoansScreen {
return clickDelete()
.confirmDelete(next = LoansScreen(composeTestRule))
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.ivy.wallet.compose.helpers

import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextReplacement
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.*
import com.ivy.wallet.compose.IvyComposeTestRule
import com.ivy.wallet.domain.data.LoanType

class LoanModal(
private val composeTestRule: IvyComposeTestRule
) {
private val amountInput = IvyAmountInput(composeTestRule)
val colorPicker = IvyColorPicker(composeTestRule)
val chooseIconFlow = ChooseIconFlow(composeTestRule)
val accountsTab = AccountsTab(composeTestRule)

fun enterName(loanName: String) {
) : AmountInput<LoanModal>, ColorPicker<LoanModal>, IconPicker<LoanModal> {
fun enterName(loanName: String): LoanModal {
composeTestRule.onNodeWithTag("base_input")
.performTextReplacement(loanName)
return this
}

fun selectLoanType(loanType: LoanType) {
fun selectLoanType(loanType: LoanType): LoanModal {
when (loanType) {
LoanType.BORROW -> {
composeTestRule.onNodeWithText("Borrow money")
Expand All @@ -31,26 +25,44 @@ class LoanModal(
.performClick()
}
}
return this
}

fun enterAmount(amount: String) {
private fun clickLoanAmount(): IvyAmountInput {
composeTestRule.onNodeWithTag("amount_balance")
.performClick()

amountInput.enterNumber(amount)
return IvyAmountInput(composeTestRule)
}

fun clickAdd() {
fun clickAdd(): LoansScreen {
composeTestRule.onNodeWithText("Add")
.performClick()
return LoansScreen(composeTestRule)
}

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

fun selectDefaultLoanAccount(): LoanModal {
composeTestRule.onNode(hasText("Cash")).performClick()
return this
}

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

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

fun selectDefaultLoanAccount(){
accountsTab.clickAccount(account = "Cash")
override fun enterAmount(number: String): LoanModal {
return clickLoanAmount()
.enterNumber(number = number, next = this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,60 @@ import com.ivy.wallet.compose.IvyComposeTestRule

class LoanRecordModal(
private val composeTestRule: IvyComposeTestRule
) {
private val amountInput = IvyAmountInput(composeTestRule)
) : AmountInput<LoanRecordModal>, DeleteItem<LoanDetailsScreen> {

fun enterAmount(amount: String) {
override fun enterAmount(amount: String): LoanRecordModal {
return clickLoanAmount()
.enterNumber(number = amount, next = LoanRecordModal(composeTestRule))
}

private fun clickLoanAmount(): IvyAmountInput {
composeTestRule.onNodeWithTag("amount_balance")
.performClick()
return IvyAmountInput(composeTestRule)
}

inputAmountOpenModal(amount)
fun enterAmountWhenAmountInputOpened(amount: String): LoanRecordModal {
return firstOpenAddNew()
.enterNumber(number = amount, next = this)
}

fun inputAmountOpenModal(amount: String) {
amountInput.enterNumber(amount)
private fun firstOpenAddNew(): IvyAmountInput {
return IvyAmountInput(composeTestRule)
}

fun enterNote(note: String) {
fun enterNote(note: String): LoanRecordModal {
composeTestRule.onNodeWithTag("base_input")
.performTextReplacement(note)
return this
}

fun clickAdd() {
fun clickAdd(): LoanDetailsScreen {
composeTestRule.onNodeWithText("Add")
.performClick()
return LoanDetailsScreen(composeTestRule)
}

fun clickSave() {
fun clickSave(): LoanDetailsScreen {
composeTestRule.onNodeWithText("Save")
.performClick()
return LoanDetailsScreen(composeTestRule)
}

fun clickDelete() {
private fun clickDelete(): DeleteConfirmationModal {
composeTestRule.onNodeWithTag("modal_delete")
.performClick()
return DeleteConfirmationModal(composeTestRule)
}

override fun deleteWithConfirmation(): LoanDetailsScreen {
return clickDelete()
.confirmDelete(next = LoanDetailsScreen(composeTestRule))
}

fun clickClose(): LoanDetailsScreen {
composeTestRule.onNodeWithTag("modal_close_button")
.performClick()
return LoanDetailsScreen(composeTestRule)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import com.ivy.wallet.domain.data.LoanType
class LoansScreen(
private val composeTestRule: IvyComposeTestRule
) {
private val loanModal = LoanModal(composeTestRule)

fun clickAddLoan() {
fun clickAddLoan(): LoanModal {
composeTestRule.onNodeWithText("Add loan")
.performClick()
return LoanModal(composeTestRule)
}

fun assertLoan(
Expand All @@ -24,7 +24,7 @@ class LoansScreen(
amountPaid: String,
percentPaid: String,
currency: String = "USD"
) {
): LoansScreen {
val typeText = when (loanType) {
LoanType.BORROW -> "BORROWED"
LoanType.LEND -> "LENT"
Expand All @@ -41,13 +41,15 @@ class LoansScreen(
name, typeText, amountLeft, amountLeftDecimal, currency,
"$amountPaid $currency / $loanAmount $currency ($percentPaid%)"
)
return this
}

fun clickLoan(loanName: String) {
fun clickLoan(loanName: String): LoanDetailsScreen {
composeTestRule.onNode(
hasTestTag("loan_item")
.and(hasText(loanName, substring = true))
).performClick()
return LoanDetailsScreen(composeTestRule)
}

fun addLoanFlow(
Expand All @@ -56,22 +58,23 @@ class LoansScreen(
color: Color? = null,
icon: String? = null,
loanType: LoanType
) {
): LoansScreen {
clickAddLoan()
loanModal.apply {
enterName(loanName)
enterAmount(amount)
selectLoanType(loanType)
selectDefaultLoanAccount()
if (color != null) {
colorPicker.chooseColor(color)
.enterName(loanName)
.enterAmount(amount)
.selectLoanType(loanType)
.selectDefaultLoanAccount()
.apply {
if (color != null) {
chooseColor(color)
}
}
if (icon != null) {
chooseIconFlow.chooseIcon(icon)
.apply {
if (icon != null) {
chooseIcon(icon)
}
}

clickAdd()
}
.clickAdd()

val loanAmount = amount.split(".").first()
val loanAmountDecimal = amount.split(".").getOrNull(1)?.let { ".$it" } ?: ".00"
Expand All @@ -85,6 +88,8 @@ class LoansScreen(
amountPaid = "0.00",
percentPaid = "0.00"
)

return this
}

fun assertEmptyState() {
Expand Down
Loading

0 comments on commit e350ff2

Please sign in to comment.