Improve test framework.

This commit is contained in:
Benoit Marty
2024-02-21 15:56:12 +01:00
committed by Benoit Marty
parent bb4c050819
commit addc3d4782
2 changed files with 11 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ class EnsureCalledOnce : () -> Unit {
}
}
fun ensureCalledOnce(block: (callback: EnsureCalledOnce) -> Unit) {
fun ensureCalledOnce(block: (callback: () -> Unit) -> Unit) {
val callback = EnsureCalledOnce()
block(callback)
callback.assertSuccess()

View File

@@ -34,11 +34,21 @@ fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.clickOn(@StringR
.performClick()
}
/**
* Press the back button in the app bar.
*/
fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.pressBack() {
val text = activity.getString(CommonStrings.action_back)
onNode(hasContentDescription(text)).performClick()
}
/**
* Press the back key.
*/
fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.pressBackKey() {
activity.onBackPressedDispatcher.onBackPressed()
}
fun SemanticsNodeInteractionsProvider.pressTag(tag: String) {
onNode(hasTestTag(tag)).performClick()
}