library/avatar: surface lifecycle and recomposition coverage (#tests)
- Commit
ce5870abe18f718dcbed72dd972e2f55012c75e0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 14:03 UTC (19 days ago)
- Parents
59db7de
Adds a SurfaceView changed-before-create/destroy gate test and a YuuAvatar3D recomposition test (pose/config state change) so the native-available paths execute under Robolectric. Coverage (createMergedCoverageReport, instruction): library/avatar 79.9% (762/954) -> 80.1% (764/954). Verified: :library:avatar:testDebugUnitTest, detekt and lint green without the ignore-failures init script.
Diff
library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatar3DTest.kt
diff --git a/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatar3DTest.kt b/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatar3DTest.ktindex bea007aa46..567c56f1c5 100644--- a/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatar3DTest.kt+++ b/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatar3DTest.kt@@ -5,6 +5,8 @@ import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onRoot+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner@@ -48,6 +50,26 @@ class YuuAvatar3DTest { rule.onNodeWithText("fallback hero").assertIsDisplayed() } + @Test+ fun `recomposing with a new pose reconfigures the surface`() {+ var pose by androidx.compose.runtime.mutableStateOf("idle")+ var config by androidx.compose.runtime.mutableStateOf("{\"skin\":1}")+ rule.setContent {+ YuuAvatar3D(+ configJson = config,+ poseId = pose,+ surfaceId = 5,+ fallback = { Text("hero $pose") },+ )+ }+ rule.runOnIdle {+ pose = "wave"+ config = "{\"skin\":2}"+ }+ rule.waitForIdle()+ rule.onNodeWithText("hero wave").assertIsDisplayed()+ }+ @Test fun `renders nothing without a fallback`() { rule.setContent {
library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatarSurfaceViewTest.kt
diff --git a/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatarSurfaceViewTest.kt b/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatarSurfaceViewTest.ktindex 946df66472..d9ad80d791 100644--- a/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatarSurfaceViewTest.kt+++ b/library/avatar/src/test/java/com/vayunmathur/library/avatar/components/YuuAvatarSurfaceViewTest.kt@@ -21,6 +21,19 @@ class YuuAvatarSurfaceViewTest { assertEquals(0, YuuAvatarSurfaceView(context).surfaceId, "default surface id") } + @Test+ fun `changed only forwards after create and destroy resets the gate`() {+ val view = YuuAvatarSurfaceView(context, surfaceId = 9)+ // Not ready yet: a stray changed callback must not reach native.+ view.surfaceChanged(view.holder, PixelFormat.RGBA_8888, 10, 10)+ view.surfaceCreated(view.holder)+ view.surfaceChanged(view.holder, PixelFormat.RGBA_8888, 640, 480)+ view.surfaceChanged(view.holder, PixelFormat.RGB_565, 320, 240)+ view.surfaceDestroyed(view.holder)+ // After destroy the gate is closed again.+ view.surfaceChanged(view.holder, PixelFormat.RGBA_8888, 10, 10)+ }+ @Test fun `lifecycle callbacks are safe without native`() { val view = YuuAvatarSurfaceView(context, surfaceId = 3)