upgraded dependencies to be compatible with android_33

This commit is contained in:
2025-05-20 01:24:14 +01:00
parent 4b8f2944cb
commit 1b77020e06
12 changed files with 263 additions and 109 deletions

View File

@@ -4,42 +4,20 @@ import com.appttude.h_mal.easycc.application.TestRunner.Companion.idlingResource
import com.appttude.h_mal.easycc.data.network.response.CurrencyResponse
import com.appttude.h_mal.easycc.data.network.response.ResponseObject
import com.appttude.h_mal.easycc.data.repository.Repository
import com.appttude.h_mal.easycc.models.CurrencyModel
import com.appttude.h_mal.easycc.models.CurrencyObject
import kotlinx.coroutines.delay
import javax.inject.Inject
class MockRepository @Inject constructor() : Repository {
override suspend fun getDataFromApi(fromCurrency: String, toCurrency: String): ResponseObject {
override suspend fun getDataFromApi(fromCurrency: String, toCurrency: String): CurrencyModel {
idlingResources.increment()
delay(500)
return ResponseObject(
results = mapOf(
Pair(
"AUD_GBP", CurrencyObject(
id = "AUD_GBP",
fr = "AUD",
to = "GBP",
value = 0.546181
)
)
)
).also {
idlingResources.decrement()
}
}
override suspend fun getBackupDataFromApi(
fromCurrency: String,
toCurrency: String
): CurrencyResponse {
idlingResources.increment()
delay(500)
return CurrencyResponse(
rates = mapOf(Pair("GBP", 0.54638)),
amount = 1.0,
base = "AUD",
date = "2021-06-11"
return CurrencyModel(
from = "AUD",
to = "GBP",
rate = 0.546181
).also {
idlingResources.decrement()
}

View File

@@ -0,0 +1,87 @@
package com.appttude.h_mal.easycc.helper
import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.util.TreeIterables
import org.hamcrest.Matcher
import java.lang.Thread.sleep
/**
* Perform action of implicitly waiting for a certain view.
* This differs from EspressoExtensions.searchFor in that,
* upon failure to locate an element, it will fetch a new root view
* in which to traverse searching for our @param match
*
* @param viewMatcher ViewMatcher used to find our view
*/
fun waitForView(
viewMatcher: Matcher<View>,
waitMillis: Int = 5000,
waitMillisPerTry: Long = 100
): ViewInteraction {
// Derive the max tries
val maxTries = waitMillis / waitMillisPerTry.toInt()
var tries = 0
for (i in 0..maxTries)
try {
// Track the amount of times we've tried
tries++
// Search the root for the view
onView(isRoot()).perform(searchFor(viewMatcher))
// If we're here, we found our view. Now return it
return onView(viewMatcher)
} catch (e: Exception) {
if (tries == maxTries) {
throw e
}
sleep(waitMillisPerTry)
}
throw Exception("Error finding a view matching $viewMatcher")
}
/**
* Perform action of waiting for a certain view within a single root view
* @param viewMatcher Generic Matcher used to find our view
*/
fun searchFor(viewMatcher: Matcher<View>): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> = isRoot()
override fun getDescription(): String {
return "searching for view $this in the root view"
}
override fun perform(uiController: UiController, view: View) {
var tries = 0
val childViews: Iterable<View> = TreeIterables.breadthFirstViewTraversal(view)
// Look for the match in the tree of child views
childViews.forEach {
tries++
if (viewMatcher.matches(it)) {
// found the view
return
}
}
throw NoMatchingViewException.Builder()
.withRootView(view)
.withViewMatcher(viewMatcher)
.build()
}
}
}

View File

@@ -6,7 +6,9 @@ import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import com.appttude.h_mal.easycc.R
import com.appttude.h_mal.easycc.helper.waitForView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers
@@ -18,48 +20,48 @@ fun currencyRobot(func: CurrencyRobot.() -> Unit) = CurrencyRobot()
class CurrencyRobot {
fun clickOnTopList() {
Espresso.onView(ViewMatchers.withId(R.id.currencyOne)).perform(ViewActions.click())
waitForView(withId(R.id.currencyOne)).perform(ViewActions.click())
}
fun clickOnBottomList() {
Espresso.onView(ViewMatchers.withId(R.id.currencyTwo)).perform(ViewActions.click())
waitForView(withId(R.id.currencyTwo)).perform(ViewActions.click())
}
fun searchInCurrencyList(search: String) {
Espresso.onView(ViewMatchers.withId(R.id.search_text))
waitForView(withId(R.id.search_text))
.perform(ViewActions.replaceText(search), ViewActions.closeSoftKeyboard())
}
fun enterValueInTopEditText(text: String) {
Espresso.onView(ViewMatchers.withId(R.id.topInsertValue))
waitForView(withId(R.id.topInsertValue))
.perform(ViewActions.replaceText(text), ViewActions.closeSoftKeyboard())
}
fun selectItemInCurrencyList() {
Espresso.onData(Matchers.anything())
.inAdapterView(
Matchers.allOf(
ViewMatchers.withId(R.id.list_view),
childAtPosition(
ViewMatchers.withClassName(Matchers.`is`("androidx.cardview.widget.CardView")),
0
)
)
val viewMatcher = Matchers.allOf(
withId(R.id.list_view),
childAtPosition(
ViewMatchers.withClassName(Matchers.`is`("androidx.cardview.widget.CardView")),
0
)
)
waitForView(viewMatcher)
Espresso.onData(Matchers.anything())
.inAdapterView(viewMatcher)
.atPosition(0)
.perform(ViewActions.click())
}
fun assertTextInTop(text: String) {
Espresso.onView(
ViewMatchers.withId(R.id.topInsertValue)
withId(R.id.topInsertValue)
).check(ViewAssertions.matches(ViewMatchers.withText(text)))
}
fun assertTextInBottom(text: String) {
Espresso.onView(
ViewMatchers.withId(R.id.bottomInsertValues)
waitForView(
withId(R.id.bottomInsertValues)
).check(ViewAssertions.matches(ViewMatchers.withText(text)))
}