So i’m having trouble testing a TextField with a t...
# compose
m
So i’m having trouble testing a TextField with a text style that has an explicit line height. I’m able to isolate this to a pretty simple test. It fails when i try to execute the done ime action, or if i try to do anything else on any node on the screen, including just printing the tree to a string. Removing the lineHeight attribute in the sample test allows the test to run properly
Copy code
offset(5) should be less than line limit(0)
java.lang.IndexOutOfBoundsException: offset(5) should be less than line limit(0)
	at android.text.TextLine.measure(TextLine.java:353)
	at android.text.Layout.getHorizontal(Layout.java:1213)
	at android.text.Layout.getHorizontal(Layout.java:1190)
	at android.text.Layout.getPrimaryHorizontal(Layout.java:1160)
See thread for test code.
Copy code
@OptIn(ExperimentalComposeUiApi::class)
    @Test
    fun TestStyleIssue() {
        composeRule.setContent {
            MaterialTheme {
                val keyboardController = LocalSoftwareKeyboardController.current
                val (value, onValueChange) = remember { mutableStateOf("") }
                TextField(
                    modifier = Modifier.testTag("input"),
                    value = value,
                    onValueChange = onValueChange,
                    textStyle = TextStyle(
                        fontFamily = FontFamily.SansSerif,
                        fontWeight = FontWeight.Normal,
                        fontSize = 14.sp,
                        lineHeight = 21.sp,
                    ),
                    keyboardActions = KeyboardActions(
                        onDone = {
                            keyboardController?.hide()
                        }
                    ),
                    keyboardOptions = KeyboardOptions(
                        imeAction = ImeAction.Done
                    )
                )
            }
        }

        composeRule.onNodeWithTag("input")
            .assertExists()
            .performTextInput("text0")

        composeRule.onNodeWithTag("input")
            .performImeAction()