forked from philipplackner/IvyWallet-PL_Version
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a355f0
commit 3c1723b
Showing
7 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.ivy | ||
|
||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import com.ivy.common.androidtest.IvyAndroidTest | ||
import com.ivy.core.data.CategoryType | ||
import com.ivy.home.HomeScreenRobot | ||
import com.ivy.navigation.Navigator | ||
import com.ivy.transaction.NewTransactionRobot | ||
import com.ivy.wallet.ui.RootActivity | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidTest | ||
class CreateTransactionE2E: IvyAndroidTest() { | ||
|
||
@get:Rule | ||
val composeRule = createAndroidComposeRule<RootActivity>() | ||
|
||
@Inject | ||
lateinit var navigator: Navigator | ||
|
||
@Test | ||
fun testCreatingExpenseWithCategoriesAndAccount() { | ||
val homeScreenRobot = HomeScreenRobot(composeRule) | ||
|
||
homeScreenRobot | ||
.navigateTo(navigator) | ||
.clickNewTransaction() | ||
.clickExpense() | ||
|
||
NewTransactionRobot(composeRule) | ||
.addAccount("PayPal") | ||
.selectAccount("PayPal") | ||
.enterTransactionAmount(65) | ||
.addCategory("Transport", CategoryType.Expense, null) | ||
.addCategory("Car", CategoryType.Expense, "Transport") | ||
.chooseSubCategory("Transport", "Car") | ||
.enterTransactionTitle("Fuel") | ||
.enterTransactionDescription("For my Ford") | ||
.clickAddTransaction() | ||
|
||
homeScreenRobot | ||
.assertTotalExpensesIs(65) | ||
.assertTransactionIsDisplayed( | ||
transactionTitle = "Fuel", | ||
accountName = "PayPal", | ||
categoryName = "Car" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
app/src/androidTest/java/com/ivy/transaction/NewTransactionRobot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.ivy.transaction | ||
|
||
import androidx.compose.ui.test.hasClickAction | ||
import androidx.compose.ui.test.hasTestTag | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.onAllNodesWithText | ||
import androidx.compose.ui.test.onLast | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import com.ivy.IvyComposeRule | ||
import com.ivy.core.data.CategoryType | ||
|
||
class NewTransactionRobot( | ||
private val composeRule: IvyComposeRule | ||
) { | ||
fun addAccount(name: String): NewTransactionRobot { | ||
composeRule.onNodeWithText("Add account").performClick() | ||
composeRule.onNodeWithContentDescription("New account").performTextInput(name) | ||
composeRule.onAllNodesWithText("Add account").onLast().performClick() | ||
return this | ||
} | ||
|
||
fun selectAccount(name: String): NewTransactionRobot { | ||
composeRule.onNodeWithText(name).performClick() | ||
return this | ||
} | ||
|
||
fun enterTransactionAmount(amount: Int): NewTransactionRobot { | ||
val digits = amount.toString().map { it.digitToInt() } | ||
digits.forEach { digit -> | ||
composeRule.onNode( | ||
hasText(digit.toString()) and hasClickAction() | ||
).performClick() | ||
} | ||
composeRule.onNodeWithText("Enter").performClick() | ||
return this | ||
} | ||
|
||
fun addCategory(name: String, type: CategoryType, parentName: String?): NewTransactionRobot { | ||
clickAddCategoryOnNewCategoryModal() | ||
.enterCategoryName(name) | ||
.selectCategoryType(type) | ||
.apply { | ||
if(parentName != null) { | ||
chooseParent(parentName) | ||
} | ||
} | ||
.clickAddCategoryOnNewCategoryModal() | ||
return this | ||
} | ||
|
||
private fun clickAddCategoryOnNewCategoryModal(): NewTransactionRobot { | ||
composeRule.onAllNodesWithText("Add category").onLast().performClick() | ||
return this | ||
} | ||
|
||
private fun enterCategoryName(name: String): NewTransactionRobot { | ||
composeRule.onNodeWithContentDescription("New Category").performTextInput(name) | ||
return this | ||
} | ||
|
||
private fun selectCategoryType(type: CategoryType): NewTransactionRobot { | ||
composeRule.onNode( | ||
hasText(type.toString()) and hasTestTag("category_type_button") | ||
).performClick() | ||
return this | ||
} | ||
|
||
private fun chooseParent(parentName: String): NewTransactionRobot { | ||
composeRule.onNodeWithText("Choose parent").performClick() | ||
composeRule.onAllNodesWithText(parentName).onLast().performClick() | ||
return this | ||
} | ||
|
||
fun chooseSubCategory(parentName: String, subName: String): NewTransactionRobot { | ||
composeRule.onNodeWithText(parentName).performClick() | ||
composeRule.onNodeWithText(subName).performClick() | ||
return this | ||
} | ||
|
||
fun enterTransactionTitle(title: String): NewTransactionRobot { | ||
composeRule.onNodeWithContentDescription("Title").performTextInput(title) | ||
return this | ||
} | ||
|
||
fun enterTransactionDescription(description: String): NewTransactionRobot { | ||
composeRule.onNodeWithText("Add description").performClick() | ||
composeRule | ||
.onNodeWithContentDescription("Enter any details here") | ||
.performTextInput(description) | ||
composeRule.onAllNodesWithText("Add").onLast().performClick() | ||
return this | ||
} | ||
|
||
fun clickAddTransaction(): NewTransactionRobot { | ||
composeRule.onNodeWithText("Add").performClick() | ||
return this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters