Skip to content

Commit

Permalink
Fix PieChartScreen.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Jun 11, 2022
1 parent d0c259e commit cd186f2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import com.ivy.wallet.compose.IvyComposeTestRule
class PieChartScreen(
private val composeTestRule: IvyComposeTestRule
) {
fun assertTitle(title: String) {
fun assertTitle(title: String): PieChartScreen {
composeTestRule.onNodeWithTag("piechart_title")
.assertTextContains(title)
return this
}

fun assertTotalAmount(
amountInt: String,
decimalPart: String,
currency: String = "USD"
) {
): PieChartScreen {
val matchText: (String) -> SemanticsMatcher = { text ->
hasTestTag("piechart_total_amount")
.and(
Expand All @@ -33,5 +34,7 @@ class PieChartScreen(

composeTestRule.onNode(matchText(currency))
.assertIsDisplayed()

return this
}
}
192 changes: 83 additions & 109 deletions app/src/androidTest/java/com/ivy/wallet/compose/scenario/PieChartTest.kt
Original file line number Diff line number Diff line change
@@ -1,138 +1,112 @@
package com.ivy.wallet.compose.scenario

import com.ivy.wallet.compose.IvyComposeTest
import com.ivy.wallet.compose.helpers.PieChartScreen
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test

@HiltAndroidTest
class PieChartTest : IvyComposeTest() {
private val pieChartScreen = PieChartScreen(composeTestRule)

@Test
fun expensePieChart_realistic() = testWithRetry {
onboarding.quickOnboarding()

transactionFlow.addExpense(
amount = 50.23
)

transactionFlow.addExpense(
amount = 150.72,
category = "Food & Drinks"
)

transactionFlow.addExpense(
amount = 75.0,
category = "Groceries"
)

transactionFlow.addExpense(
amount = 5.0,
title = "Bread",
category = "Groceries"
)
//----------------------------------------------------

homeTab.clickExpenseCard()

pieChartScreen.assertTitle("Expenses")
pieChartScreen.assertTotalAmount(
amountInt = "280",
decimalPart = ".95",
currency = "USD"
)
quickOnboarding()
.addExpense(
amount = 50.23
)
.addExpense(
amount = 150.72,
category = "Food & Drinks"
)
.addExpense(
amount = 75.0,
category = "Groceries"
)
.addExpense(
amount = 5.0,
title = "Bread",
category = "Groceries"
)
//----------------------------------------------------
.clickExpenseCard()
.assertTitle("Expenses")
.assertTotalAmount(
amountInt = "280",
decimalPart = ".95",
currency = "USD"
)
}

@Test
fun expensePieChart_empty() = testWithRetry {
onboarding.quickOnboarding()

transactionFlow.addIncome(
amount = 23.23
)

//----------------------------------------------------

homeTab.clickExpenseCard()

pieChartScreen.assertTitle("Expenses")
pieChartScreen.assertTotalAmount(
amountInt = "0",
decimalPart = ".00",
currency = "USD"
)
quickOnboarding()
.addIncome(
amount = 23.23
)
//----------------------------------------------------
.clickExpenseCard()
.assertTitle("Expenses")
.assertTotalAmount(
amountInt = "0",
decimalPart = ".00",
currency = "USD"
)
}

@Test
fun expensePieChart_oneTrn() = testWithRetry {
onboarding.quickOnboarding()

transactionFlow.addExpense(
amount = 55.01
)

//----------------------------------------------------

homeTab.clickExpenseCard()

pieChartScreen.assertTitle("Expenses")
pieChartScreen.assertTotalAmount(
amountInt = "55",
decimalPart = ".01",
currency = "USD"
)
quickOnboarding()
.addExpense(
amount = 55.01
)
//----------------------------------------------------
.clickExpenseCard()
.assertTitle("Expenses")
.assertTotalAmount(
amountInt = "55",
decimalPart = ".01",
currency = "USD"
)
}

@Test
fun incomePieChart_realistic() = testWithRetry {
onboarding.quickOnboarding()

//To ensure that the code filters expenses
transactionFlow.addExpense(
amount = 10.0
)

transactionFlow.addIncome(
amount = 7200.0,
title = "Salary",
category = "Groceries"
)

transactionFlow.addIncome(
amount = 1.1,
title = "Adjust balance"
)

//----------------------------------------------------

homeTab.clickIncomeCard()

pieChartScreen.assertTitle("Income")
pieChartScreen.assertTotalAmount(
amountInt = "7,201",
decimalPart = ".10",
currency = "USD"
)
quickOnboarding()
//To ensure that the code filters expenses
.addExpense(
amount = 10.0
)
.addIncome(
amount = 7200.0,
title = "Salary",
category = "Groceries"
)
.addIncome(
amount = 1.1,
title = "Adjust balance"
)
//----------------------------------------------------
.clickIncomeCard()
.assertTitle("Income")
.assertTotalAmount(
amountInt = "7,201",
decimalPart = ".10",
currency = "USD"
)
}

@Test
fun incomePieChart_empty() = testWithRetry {
onboarding.quickOnboarding()

transactionFlow.addExpense(
amount = 23.23
)

//----------------------------------------------------

homeTab.clickIncomeCard()

pieChartScreen.assertTitle("Income")
pieChartScreen.assertTotalAmount(
amountInt = "0",
decimalPart = ".00",
currency = "USD"
)
quickOnboarding()
.addExpense(
amount = 23.23
)
//----------------------------------------------------
.clickIncomeCard()
.assertTitle("Income")
.assertTotalAmount(
amountInt = "0",
decimalPart = ".00",
currency = "USD"
)
}
}

0 comments on commit cd186f2

Please sign in to comment.