mattinger
02/02/2022, 2:59 PMperformTextInput
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:
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@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"))
}
}
Bryan Herbst
02/15/2022, 3:25 PMChuck Stein
06/23/2022, 8:36 PMmattinger
06/23/2022, 11:19 PMlineHeight
attribute. The second i add that in, it barfsChuck Stein
06/27/2022, 5:42 AM