diff --git a/app/src/androidTest/java/com/ivy/wallet/compose/helpers/PieChartScreen.kt b/app/src/androidTest/java/com/ivy/wallet/compose/helpers/PieChartScreen.kt index 569f12ee9c..90ab0d8349 100644 --- a/app/src/androidTest/java/com/ivy/wallet/compose/helpers/PieChartScreen.kt +++ b/app/src/androidTest/java/com/ivy/wallet/compose/helpers/PieChartScreen.kt @@ -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( @@ -33,5 +34,7 @@ class PieChartScreen( composeTestRule.onNode(matchText(currency)) .assertIsDisplayed() + + return this } } \ No newline at end of file diff --git a/app/src/androidTest/java/com/ivy/wallet/compose/scenario/PieChartTest.kt b/app/src/androidTest/java/com/ivy/wallet/compose/scenario/PieChartTest.kt index 9b78b87831..98db14196d 100644 --- a/app/src/androidTest/java/com/ivy/wallet/compose/scenario/PieChartTest.kt +++ b/app/src/androidTest/java/com/ivy/wallet/compose/scenario/PieChartTest.kt @@ -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" + ) } } \ No newline at end of file