Has anyone had issues testing a BasicTextField wit...
# compose
m
Has anyone had issues testing a BasicTextField with a custom text style? It seems to cause issues. After i match the text field and call
performTextInput
I can no longer match any other elements on the tree. If i use a style from MaterialTheme like body2 it’s fine, but anything else, I get this error:
Copy code
offset(6) should be less than line limit(0)
java.lang.IndexOutOfBoundsException: offset(6) 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)
Code is in thread
Copy code
@RunWith(AndroidJUnit4::class)
@Config(sdk = [30])
class TextFieldIssue {
    @get:Rule
    val composeRule = createComposeRule()

    @Test
    fun demonstrateIssue() {
        val value = mutableStateOf("")
        val onClick = mock<() -> Unit>()

        composeRule.setContent {
            MaterialTheme {
                Column {
                    BasicTextField(
                        modifier = Modifier.testTag("input"),
                        value = value.value,
                        onValueChange = { value.value = it },
                        readOnly = false,
                        textStyle = TextStyle(
                            fontFamily = FontFamily.Serif,
                            fontWeight = FontWeight.Normal,
                            fontSize = 16.sp,
                            lineHeight = 24.sp,
                            letterSpacing = 0.00000.em
                        ),
                    )
                    Button(
                        modifier = Modifier.testTag("button"),
                        onClick = onClick

                    ) {
                        Text("Submit")
                    }
                }
            }
        }

        println(composeRule.onRoot(useUnmergedTree = true).printToString())

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


        composeRule
            .onNodeWithTag("input")
            .assert(hasText("foobar"))
    }
}
It’s worth nothing this is a robolectric test, not an espresso test..
b
Hey, just ran into this as well! Have not found a solution yet, but will let you know if I do
c
@mattinger @Bryan Herbst did either of you ever find out a solution? I'm having the same issue
m
Not yet @Chuck Stein. I'm wondering if it's a robolectric bug or a compose bug. Maybe 1.2.0 will fix it. i'll give the beta a try again to see what happens.
Definitely NOT fixed with compose 1.2.0-rc02 and roboletric 4.8.1
But i have narrowed it down specifically to the
lineHeight
attribute. The second i add that in, it barfs
c
Thanks for the update! Definitely a bummer that 1.2.0 isn't fixing it. I wonder if Robolectric is tracking this issue and can make a fix or if it's more in Google's hands