Skip to content

Commit

Permalink
Unfortunately on API 29 only sleep makes test reliable due to android…
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Feb 13, 2022
1 parent 389ca4f commit f716487
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ package org.totschnig.myexpenses.test.espresso
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.assertj.core.api.Assertions.assertThat
import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.containsString
import org.junit.Rule
import org.junit.Test
import org.totschnig.myexpenses.R
import org.totschnig.myexpenses.activity.ManageCurrencies
import org.totschnig.myexpenses.activity.ProtectedFragmentActivity
import org.totschnig.myexpenses.model.Account
import org.totschnig.myexpenses.model.AccountType
import org.totschnig.myexpenses.model.Money
import org.totschnig.myexpenses.model.Transaction
import org.totschnig.myexpenses.testutils.BaseUiTest
import org.totschnig.myexpenses.viewmodel.data.Currency
import org.totschnig.myexpenses.viewmodel.data.Currency.Companion.create
import java.math.BigDecimal
import java.util.concurrent.atomic.AtomicReference


class ManageCurrenciesTest : BaseUiTest<ManageCurrencies>() {
Expand Down Expand Up @@ -58,17 +51,18 @@ class ManageCurrenciesTest : BaseUiTest<ManageCurrencies>() {
op.save()
val before = account.totalBalance
assertThat(before.amountMajor).isEqualByComparingTo(BigDecimal(38))
val currency = AtomicReference<Currency>()
testScenario.onActivity { activity: ProtectedFragmentActivity? -> currency.set(create(CURRENCY_CODE, activity)) }
onData(Matchers.`is`(currency.get()))
val currency = create(CURRENCY_CODE, targetContext)
onData(Matchers.`is`(currency))
.inAdapterView(withId(android.R.id.list)).perform(click())
onView(withId(R.id.edt_currency_fraction_digits))
.perform(replaceText("3"), closeSoftKeyboard())
Thread.sleep(1000)
if (withUpdate) {
onView(withId(R.id.checkBox)).perform(click())
}
onView(withText(android.R.string.ok)).perform(click())
onView(withText(allOf(containsString(currency.get().toString()), containsString("3")))).check(matches(isDisplayed()))
onView(withId(android.R.id.button1)).perform(click())
onData(Matchers.`is`(currency))
.inAdapterView(withId(android.R.id.list)).check(matches(withText(containsString("3"))))
val after = Account.getInstanceFromDb(account.id).totalBalance
if (withUpdate) {
assertThat(after.amountMajor).isEqualByComparingTo(before.amountMajor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class Currency(val code: String, val displayName: String, val usages: Int =
}

companion object {
fun create(code: String, context: Context?): Currency {
fun create(code: String, context: Context): Currency {
return create(code, Utils.localeFromContext(context))
}

Expand Down

0 comments on commit f716487

Please sign in to comment.