Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit 6392087

Browse files
author
Daniel Jette
committed
Add synchronization
1 parent 426fae7 commit 6392087

5 files changed

Lines changed: 15 additions & 2 deletions

File tree

Ext/Compose/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ android {
8383
implementation "androidx.compose.ui:ui-tooling-preview:${versions.compose}"
8484
implementation "androidx.compose.ui:ui:${versions.compose}"
8585
implementation "androidx.lifecycle:lifecycle-runtime-ktx:${versions.androidx.lifecycleKtx}"
86+
implementation "androidx.test.espresso:espresso-core:${versions.androidx.test.espresso}"
8687
implementation "androidx.test:rules:${versions.androidx.test.rules}"
8788
implementation "androidx.test:runner:${versions.androidx.test.runner}"
8889
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"

Ext/Compose/src/main/java/com/shopify/testify/ComposableScreenshotRule.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ import android.app.Activity
2727
import android.graphics.Bitmap
2828
import androidx.compose.runtime.Composable
2929
import androidx.compose.ui.platform.ComposeView
30+
import androidx.test.espresso.Espresso
3031
import com.shopify.testify.compose.R
3132
import com.shopify.testify.internal.disposeComposition
32-
import org.junit.Before
33+
import org.junit.Assert.assertTrue
34+
import java.util.concurrent.CountDownLatch
35+
import java.util.concurrent.TimeUnit
3336

3437
/**
3538
* Helper extension of [ScreenshotRule] which simplifies testing [Composable] functions.
@@ -62,12 +65,17 @@ open class ComposableScreenshotRule(
6265
* Render the composable function after the activity has loaded.
6366
*/
6467
override fun afterActivityLaunched() {
68+
Espresso.onIdle()
69+
val latch = CountDownLatch(1)
6570
activity.runOnUiThread {
6671
val composeView = activity.findViewById<ComposeView>(R.id.compose_container)
6772
composeView.setContent {
6873
composeFunction()
74+
latch.countDown()
6975
}
7076
}
77+
assertTrue(latch.await(COMPOSE_TIMEOUT_SECONDS, TimeUnit.SECONDS))
78+
Espresso.onIdle()
7179
super.afterActivityLaunched()
7280
}
7381

@@ -86,4 +94,8 @@ open class ComposableScreenshotRule(
8694
composeFunction = composable
8795
return this
8896
}
97+
98+
companion object {
99+
private const val COMPOSE_TIMEOUT_SECONDS: Long = 15
100+
}
89101
}
-17.9 KB
Loading
22 KB
Loading

Sample/src/androidTest/java/com/shopify/testify/sample/compose/ComposableScreenshotTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ComposableScreenshotTest {
7878

7979
@ScreenshotInstrumentation
8080
@Test
81-
fun _default() {
81+
fun paddedBoxes() {
8282
rule
8383
.setCompose {
8484
PaddedBox(Color.Gray) {

0 commit comments

Comments
 (0)