From 243eeb366cc5b3f4f767ce4e606111faa7562e47 Mon Sep 17 00:00:00 2001 From: Brion Date: Thu, 9 Jul 2026 13:32:13 +0530 Subject: [PATCH] Inject `id` into components --- .../thunderid/compose/components/actions/SignInButton.kt | 6 +++++- .../compose/components/presentation/auth/SignIn.kt | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/dev/thunderid/compose/components/actions/SignInButton.kt b/src/main/kotlin/dev/thunderid/compose/components/actions/SignInButton.kt index dd97938..f991f3a 100644 --- a/src/main/kotlin/dev/thunderid/compose/components/actions/SignInButton.kt +++ b/src/main/kotlin/dev/thunderid/compose/components/actions/SignInButton.kt @@ -25,6 +25,7 @@ import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp @@ -34,11 +35,12 @@ import dev.thunderid.compose.LocalThunderID @Composable fun SignInButton( modifier: Modifier = Modifier, + testTag: String? = null, onTap: (() -> Unit)? = null, ) { val state = LocalThunderID.current val label = state.i18n.resolve("signIn.button") - BaseSignInButton(label = label, isLoading = state.isLoading, modifier = modifier) { + BaseSignInButton(label = label, isLoading = state.isLoading, modifier = modifier, testTag = testTag) { onTap?.invoke() } } @@ -49,6 +51,7 @@ fun BaseSignInButton( label: String, isLoading: Boolean = false, modifier: Modifier = Modifier, + testTag: String? = null, onClick: () -> Unit, ) { Box( @@ -56,6 +59,7 @@ fun BaseSignInButton( modifier = modifier .defaultMinSize(minWidth = 44.dp, minHeight = 44.dp) + .then(if (testTag != null) Modifier.testTag(testTag) else Modifier) .semantics { contentDescription = label } .then(if (!isLoading) Modifier.clickable(onClick = onClick) else Modifier), ) { diff --git a/src/main/kotlin/dev/thunderid/compose/components/presentation/auth/SignIn.kt b/src/main/kotlin/dev/thunderid/compose/components/presentation/auth/SignIn.kt index 16bde1f..65566cb 100644 --- a/src/main/kotlin/dev/thunderid/compose/components/presentation/auth/SignIn.kt +++ b/src/main/kotlin/dev/thunderid/compose/components/presentation/auth/SignIn.kt @@ -37,6 +37,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.input.KeyboardType @@ -110,7 +111,11 @@ fun SignIn( OutlinedTextField( value = signInState.fieldValue(input.name), onValueChange = { signInState.setField(input.name, it) }, - modifier = Modifier.fillMaxWidth().semantics { contentDescription = input.name }, + modifier = + Modifier + .fillMaxWidth() + .testTag("thunderid-field-${input.name}") + .semantics { contentDescription = input.name }, placeholder = { Text(input.name) }, visualTransformation = if (isPassword) PasswordVisualTransformation() else VisualTransformation.None, @@ -123,7 +128,7 @@ fun SignIn( Button( onClick = { signInState.submit(action.id ?: action.ref ?: "") }, enabled = !signInState.isLoading, - modifier = Modifier.fillMaxWidth(), + modifier = Modifier.fillMaxWidth().testTag("thunderid-action-${action.id ?: action.ref}"), ) { Text(action.label ?: i18n.resolve("signIn.submit")) }