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

Commit

Permalink
Add test for adding transaction with description
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 24, 2022
1 parent 4abc146 commit c49dfd9
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.hideKeyboard
import com.ivy.wallet.utils.format

class TransactionFlow<A : ComponentActivity>(
Expand All @@ -17,7 +18,8 @@ class TransactionFlow<A : ComponentActivity>(
amount: Double,
title: String? = null,
category: String? = null,
account: String = "Cash"
account: String = "Cash",
description: String? = null,
) {
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddIncome()
Expand All @@ -26,15 +28,17 @@ class TransactionFlow<A : ComponentActivity>(
amount = amount,
title = title,
category = category,
account = account
account = account,
description = null,
)
}

fun addExpense(
amount: Double,
title: String? = null,
category: String? = null,
account: String = "Cash"
account: String = "Cash",
description: String? = null,
) {
mainBottomBar.clickAddFAB()
mainBottomBar.clickAddExpense()
Expand All @@ -43,14 +47,16 @@ class TransactionFlow<A : ComponentActivity>(
amount = amount,
title = title,
category = category,
account = account
account = account,
description = description
)
}

private fun addTransaction(
amount: Double,
title: String?,
category: String?,
description: String?,
account: String = "Cash"
) {
composeTestRule.onNode(
Expand All @@ -71,6 +77,21 @@ class TransactionFlow<A : ComponentActivity>(
.performTextInput(title)
}

if (description != null) {
composeTestRule.hideKeyboard()

composeTestRule.onNodeWithText("Add description")
.performClick()

composeTestRule.onNode(
hasTestTag("modal_desc_input"),
useUnmergedTree = true
).performTextReplacement(description)

composeTestRule.onNodeWithTag("modal_desc_save")
.performClick()
}

composeTestRule.onNodeWithText("Add")
.performClick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,32 @@ class OperationsCoreTest : IvyComposeTest() {
amountDecimal = ".00"
)
}

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

transactionFlow.addExpense(
amount = 2178.0,
title = "Samsung Galaxy Tab S8+",
category = "Groceries",
description = "Tablet for learning purposes."
)

homeTab.assertBalance(
"-2,178",
amountDecimal = ".00"
)

homeTab.dismissPrompt()

homeTab.clickTransaction(
amount = "2,178.00",
title = "Samsung Galaxy Tab S8+",
category = "Groceries"
)

composeTestRule.onNodeWithTag("trn_description", useUnmergedTree = true)
.assertTextEquals("Tablet for learning purposes.")
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/ivy/wallet/ui/edit/core/Description.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -58,7 +59,8 @@ private fun DescriptionText(
.clickable {
onClick()
}
.padding(horizontal = 24.dp),
.padding(horizontal = 24.dp)
.testTag("trn_description"),
text = description,
style = UI.typo.nB2.style(
textAlign = TextAlign.Left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.*
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -29,6 +30,7 @@ import com.ivy.wallet.utils.isNotNullOrBlank
fun IvyDescriptionTextField(
modifier: Modifier = Modifier,
textModifier: Modifier = Modifier,
testTag: String = "desc_input",
value: TextFieldValue,
hint: String?,
fontWeight: FontWeight = FontWeight.Medium,
Expand Down Expand Up @@ -60,7 +62,7 @@ fun IvyDescriptionTextField(

val view = LocalView.current
BasicTextField(
modifier = textModifier,
modifier = textModifier.testTag(testTag),
value = value,
onValueChange = onValueChanged,
textStyle = UI.typo.nB2.style(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,34 @@ fun ModalDynamicPrimaryAction(
initialEmpty: Boolean,
initialChanged: Boolean,

testTagSave: String = "tag_save",
testTagDelete: String = "tag_delete",

onDelete: () -> Unit,
dismiss: () -> Unit,
onSave: () -> Unit
) {
when {
initialEmpty -> {
ModalAdd {
ModalAdd(
testTag = testTagSave
) {
onSave()
dismiss()
}
}
else -> {
if (!initialChanged) {
ModalDelete {
ModalDelete(
testTag = testTagDelete
) {
onDelete()
dismiss()
}
} else {
ModalSave {
ModalSave(
modifier = Modifier.testTag(testTagSave)
) {
onSave()
dismiss()
}
Expand Down Expand Up @@ -121,9 +130,11 @@ fun ModalSave(
@Composable
fun ModalAdd(
enabled: Boolean = true,
testTag: String = "modal_add",
onClick: () -> Unit
) {
ModalPositiveButton(
modifier = Modifier.testTag(testTag),
text = stringResource(R.string.add),
iconStart = R.drawable.ic_plus,
enabled = enabled,
Expand Down Expand Up @@ -197,12 +208,13 @@ fun ModalPrimaryButton(
@Composable
fun ModalDelete(
enabled: Boolean = true,
testTag: String = "modal_delete",
onClick: () -> Unit
) {
IvyCircleButton(
modifier = Modifier
.size(40.dp)
.testTag("modal_delete"),
.testTag(testTag),
icon = R.drawable.ic_delete,
backgroundGradient = GradientRed,
enabled = enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ fun BoxWithConstraintsScope.DescriptionModal(
ModalDynamicPrimaryAction(
initialEmpty = description.isNullOrBlank(),
initialChanged = description != descTextFieldValue.text,

testTagSave = "modal_desc_save",
testTagDelete = "modal_desc_delete",

onSave = {
onDescriptionChanged(descTextFieldValue.text)
view.hideKeyboard()
Expand Down Expand Up @@ -88,6 +92,7 @@ fun BoxWithConstraintsScope.DescriptionModal(
.padding(horizontal = 32.dp)
.fillMaxWidth()
.focusRequester(focus),
testTag = "modal_desc_input",
keyboardOptions = KeyboardOptions(
autoCorrect = true,
capitalization = KeyboardCapitalization.Sentences,
Expand Down

0 comments on commit c49dfd9

Please sign in to comment.