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 #218 from ILIYANGERMANOV/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ILIYANGERMANOV authored Dec 6, 2021
2 parents 731e822 + 3c2acf6 commit cd9fffb
Show file tree
Hide file tree
Showing 26 changed files with 764 additions and 84 deletions.
20 changes: 12 additions & 8 deletions app/src/androidTest/java/com/ivy/wallet/compose/IvyComposeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ abstract class IvyComposeTest {

@After
fun tearDown() {
idlingResource?.let {
composeTestRule.unregisterIdlingResource(it)
}
resetTestIdling()

TestingContext.inTest = false

resetApp()
}

private fun resetTestIdling() {
idlingResource?.let {
composeTestRule.unregisterIdlingResource(it)
}
}

private fun resetApp() {
clearSharedPrefs()
resetDatabase()
Expand All @@ -105,11 +109,12 @@ abstract class IvyComposeTest {
protected fun testWithRetry(
attempt: Int = 0,
maxAttempts: Int = 3,
firstFailure: Throwable? = null,
test: () -> Unit
) {
try {
test()
} catch (e: AssertionError) {
} catch (e: Throwable) {
if (attempt < maxAttempts) {
//reset state && retry test
resetApp()
Expand All @@ -118,20 +123,19 @@ abstract class IvyComposeTest {
TestIdlingResource.reset()

//Restart IvyActivity
val intent = composeTestRule.activity.intent
composeTestRule.activity.finish()
composeTestRule.activity.startActivity(intent)
composeTestRule.activityRule.scenario.recreate()

composeTestRule.waitMillis(300) //wait for activity to start

testWithRetry(
attempt = attempt + 1,
maxAttempts = maxAttempts,
firstFailure = if (attempt == 0) e else firstFailure,
test = test
)
} else {
//propagate exception
throw e
throw firstFailure ?: e
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class LoansScreen<A : ComponentActivity>(
fun assertLoan(
name: String,
loanType: LoanType,
amount: String,
amountDecimal: String,
amountLeft: String,
amountLeftDecimal: String,
loanAmount: String,
amountPaid: String,
percentPaid: String,
currency: String = "USD"
Expand All @@ -39,8 +40,8 @@ class LoansScreen<A : ComponentActivity>(
)
.performScrollTo()
.assertTextEquals(
name, typeText, amount, amountDecimal, currency,
"$amountPaid $currency / $amount$amountDecimal $currency ($percentPaid%)"
name, typeText, amountLeft, amountLeftDecimal, currency,
"$amountPaid $currency / $loanAmount $currency ($percentPaid%)"
)
}

Expand Down Expand Up @@ -73,11 +74,14 @@ class LoansScreen<A : ComponentActivity>(
clickAdd()
}

val loanAmount = amount.split(".").first()
val loanAmountDecimal = amount.split(".").getOrNull(1)?.let { ".$it" } ?: ".00"
assertLoan(
name = loanName,
amount = amount.split(".").first(),
amountDecimal = amount.split(".").getOrNull(1)?.let { ".$it" } ?: ".00",
loanType = loanType,
amountLeft = loanAmount,
amountLeftDecimal = loanAmountDecimal,
loanAmount = loanAmount + loanAmountDecimal,
currency = "USD",
amountPaid = "0.00",
percentPaid = "0.00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class LoansTest : IvyComposeTest() {

loansScreen.assertLoan(
name = "Loan 1",
amount = "4,800",
amountDecimal = ".32",
amountLeft = "4,800",
amountLeftDecimal = ".32",
loanAmount = "4,800.32",
loanType = LoanType.BORROW,
currency = "USD",
amountPaid = "0.00",
Expand All @@ -66,8 +67,9 @@ class LoansTest : IvyComposeTest() {
}
loansScreen.assertLoan(
name = "Razer Blade",
amount = "4,800",
amountDecimal = ".00",
amountLeft = "4,800",
amountLeftDecimal = ".00",
loanAmount = "4,800.00",
loanType = LoanType.LEND,
currency = "USD",
amountPaid = "0.00",
Expand Down Expand Up @@ -111,8 +113,9 @@ class LoansTest : IvyComposeTest() {
loansScreen.assertLoan(
name = "Laptop",
loanType = LoanType.BORROW,
amount = "4,000",
amountDecimal = ".25",
amountLeft = "4,000",
amountLeftDecimal = ".25",
loanAmount = "4,000.25",
amountPaid = "0.00",
percentPaid = "0.00"
)
Expand Down Expand Up @@ -222,8 +225,9 @@ class LoansTest : IvyComposeTest() {
loansScreen.assertLoan(
name = "Loan 1",
loanType = LoanType.BORROW,
amount = "1,000",
amountDecimal = ".00",
amountLeft = "749",
amountLeftDecimal = ".50",
loanAmount = "1,000.00",
amountPaid = "250.50",
percentPaid = "25.05"
)
Expand Down Expand Up @@ -284,8 +288,9 @@ class LoansTest : IvyComposeTest() {
loansScreen.assertLoan(
name = "Loan",
loanType = LoanType.LEND,
amount = "10,000",
amountDecimal = ".00",
amountLeft = "5,000",
amountLeftDecimal = ".00",
loanAmount = "10,000.00",
amountPaid = "5,000.00",
percentPaid = "50.00"
)
Expand Down Expand Up @@ -338,8 +343,9 @@ class LoansTest : IvyComposeTest() {
loansScreen.assertLoan(
name = "Loan",
loanType = LoanType.LEND,
amount = "1,250",
amountDecimal = ".50",
amountLeft = "1,250",
amountLeftDecimal = ".50",
loanAmount = "1,250.50",
amountPaid = "0.00",
percentPaid = "0.00"
)
Expand Down Expand Up @@ -465,9 +471,10 @@ class LoansTest : IvyComposeTest() {

loansScreen.assertLoan(
name = "Loan",
amount = "1,000",
amountDecimal = ".00",
amountLeft = "-1,000",
amountLeftDecimal = ".50",
amountPaid = "2,000.50",
loanAmount = "1,000.00",
percentPaid = "200.05",
loanType = LoanType.BORROW
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import androidx.compose.ui.test.IdlingResource
import com.ivy.wallet.BuildConfig
import java.util.concurrent.atomic.AtomicInteger

object TestingContext {
var inTest = false
}

object TestIdlingResource {
private val counter = AtomicInteger(0)

Expand All @@ -34,4 +30,8 @@ object TestIdlingResource {
fun reset() {
counter.set(0)
}

fun get(): Int {
return counter.get()
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/ivy/wallet/base/TestingContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ivy.wallet.base

object TestingContext {
var inTest = false
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/IvyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.ivy.wallet.ui.paywall.PaywallScreen
import com.ivy.wallet.ui.planned.edit.EditPlannedScreen
import com.ivy.wallet.ui.planned.list.PlannedPaymentsScreen
import com.ivy.wallet.ui.reports.ReportScreen
import com.ivy.wallet.ui.search.SearchScreen
import com.ivy.wallet.ui.settings.SettingsScreen
import com.ivy.wallet.ui.statistic.level1.PieChartStatisticScreen
import com.ivy.wallet.ui.statistic.level2.ItemStatisticScreen
Expand Down Expand Up @@ -172,6 +173,7 @@ class IvyActivity : AppCompatActivity() {
is Screen.Budget -> BudgetScreen(screen = screen)
is Screen.Loans -> LoansScreen(screen = screen)
is Screen.LoanDetails -> LoanDetailsScreen(screen = screen)
is Screen.Search -> SearchScreen(screen = screen)
is Screen.WebView -> WebViewScreen(screen = screen)
null -> {
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/Screens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ sealed class Screen {

object Loans : Screen()

object Search : Screen()

data class LoanDetails(
val loanId: UUID
) : Screen()
Expand Down
Loading

0 comments on commit cd9fffb

Please sign in to comment.