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

Commit

Permalink
Merge pull request #944 from ILIYANGERMANOV/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ILIYANGERMANOV authored May 24, 2022
2 parents 6823214 + bebfa5a commit 902a840
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 25 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 = description,
)
}

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 @@ -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

class TransactionScreen<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
Expand Down Expand Up @@ -46,6 +47,26 @@ class TransactionScreen<A : ComponentActivity>(
.performTextReplacement(newTitle)
}

fun removeDescription() {
composeTestRule.hideKeyboard()

composeTestRule.onNodeWithTag("trn_description")
.performClick()

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

fun assertDescription(desc: String) {
composeTestRule.onNodeWithTag("trn_description", useUnmergedTree = true)
.assertTextEquals(desc)
}

fun assertAddDescriptionButtonVisible() {
composeTestRule.onNodeWithText("Add description")
.assertIsDisplayed()
}

fun clickClose() {
composeTestRule.onNodeWithContentDescription("close")
.performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,66 @@ 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"
)

editTransactionScreen.assertDescription("Tablet for learning purposes.")
}

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

transactionFlow.addIncome(
amount = 123.0,
title = "Income",
description = "-a\n-b\n-c\n-d"
)

homeTab.assertBalance(
"123",
amountDecimal = ".00"
)

homeTab.dismissPrompt()

homeTab.clickTransaction(
amount = "123.00",
title = "Income",
)

editTransactionScreen.assertDescription("-a\n-b\n-c\n-d")

// No remove desc ---------------------------------------------------------------
editTransactionScreen.removeDescription()
editTransactionScreen.save()

homeTab.clickTransaction(
amount = "123.00",
title = "Income",
)
editTransactionScreen.assertAddDescriptionButtonVisible()
}
}
18 changes: 10 additions & 8 deletions app/src/main/java/com/ivy/wallet/ui/edit/core/Description.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
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
import androidx.compose.ui.unit.dp
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.wallet.R
import com.ivy.wallet.ui.IvyWalletComponentPreview
import com.ivy.wallet.ui.edit.PrimaryAttributeColumn
import com.ivy.wallet.ui.theme.components.AddPrimaryAttributeButton
import com.ivy.wallet.utils.isNotNullOrBlank
import dev.jeziellago.compose.markdowntext.MarkdownText

@Composable
fun Description(
Expand Down Expand Up @@ -52,17 +54,17 @@ private fun DescriptionText(
) {
Spacer(Modifier.height(12.dp))

MarkdownText(
Text(
modifier = Modifier
.clickable {
onClick()
}
.padding(horizontal = 24.dp),
markdown = description,
textAlign = TextAlign.Left,
color = UI.colors.pureInverse,
fontSize = UI.typo.b2.fontSize,
fontResource = R.font.raleway_medium
.padding(horizontal = 24.dp)
.testTag("trn_description"),
text = description,
style = UI.typo.nB2.style(
textAlign = TextAlign.Left
),
)

Spacer(Modifier.height(20.dp))
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
2 changes: 1 addition & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">انشاء فئى</string>
<string name="category_name">اسم الفئة</string>
<string name="choose_category">اتر الفئة</string>
<string name="description_text_field_hint">(Markdown تدعم صيغة) ادخل اي تفاصيل هنا</string>
<string name="description_text_field_hint"> ادخل اي تفاصيل هنا</string>
<string name="clean_filter">إزالة التصفيات</string>
<string name="filter">تصفية</string>
<string name="apply_filter">تطبيق التصفيات</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">Създай категория</string>
<string name="category_name">Име на категория</string>
<string name="choose_category">Избери категория</string>
<string name="description_text_field_hint">Добави детайли (поддържа Markdown)</string>
<string name="description_text_field_hint">Добави детайли</string>
<string name="clean_filter">Изчисти филтър</string>
<string name="filter">Филтър</string>
<string name="apply_filter">Задай филтър</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">Crear categoría</string>
<string name="category_name">Nombre de la categoría</string>
<string name="choose_category">Elegir la categoría</string>
<string name="description_text_field_hint">Ingrese cualquier detalle aquí (admite Markdown)</string>
<string name="description_text_field_hint">Ingrese cualquier detalle aquí</string>
<string name="clean_filter">Borrar filtros</string>
<string name="filter">Filtrar</string>
<string name="apply_filter">Aplicar filtros</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">Crea una categoria</string>
<string name="category_name">Nome della categoria</string>
<string name="choose_category">Scegli la categoria</string>
<string name="description_text_field_hint">Inserisci qui ogni dettaglio (supporta il Markdown)</string>
<string name="description_text_field_hint">Inserisci qui ogni dettaglio</string>
<string name="clean_filter">Cancella filtro</string>
<string name="filter">Filtro</string>
<string name="apply_filter">Applica il filtro</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">Создать категорию</string>
<string name="category_name">Название категории</string>
<string name="choose_category">Выбрать категорию</string>
<string name="description_text_field_hint">Добавьте детали (поддерживается Markdown)</string>
<string name="description_text_field_hint">Добавьте детали</string>
<string name="clean_filter">Очистить фильтр</string>
<string name="filter">Фильтр</string>
<string name="apply_filter">Применить фильтр</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
<string name="create_category">Create category</string>
<string name="category_name">Category name</string>
<string name="choose_category">Choose category</string>
<string name="description_text_field_hint">Enter any details here (supports Markdown)</string>
<string name="description_text_field_hint">Enter any details here</string>
<string name="clean_filter">Clear filter</string>
<string name="filter">Filter</string>
<string name="apply_filter">Apply filter</string>
Expand Down
Loading

0 comments on commit 902a840

Please sign in to comment.