I'm migrating a project from Compose Material 2 to...
# compose
j
I'm migrating a project from Compose Material 2 to Material 3 and following test code is failing now for some reason....just in case anyone else has come across this. More info in thread...
Copy code
val personListNode = composeTestRule.onNodeWithTag(PersonListTag)
personListNode.assertIsDisplayed()
    .onChildren().assertCountEquals(people.size)

people.forEachIndexed { index, person ->
    val rowNode = personListNode.onChildAt(index)
    rowNode.printToLog("TAG")
    rowNode.assertTextContains(person.name)
    rowNode.assertTextContains(person.homeworld.name)
}
Each row in list contains following
Copy code
ListItem(
    headlineContent = { Text(person.name, style = MaterialTheme.typography.titleLarge) },
    supportingContent = { Text(person.homeworld.name, style = MaterialTheme.typography.titleMedium, color = Color.DarkGray) }
)
this is the error I'm getting
Copy code
java.lang.AssertionError: Failed to assert the following: (Text + EditableText contains 'Name 1' (ignoreCase: false))
Semantics of the node:
Node #4 at (l=0.0, t=136.0, r=1440.0, b=388.0)px
IsTraversalGroup = 'true'
Has 1 child
Selector used: (((TestTag = 'PersonList').children)[0])
and the following is the result of that
printToLog
(for material 2 and 3)
Copy code
// Material 2 (working)
09-25 20:35:08.518  6279  6298 D TAG     : Node #4 at (l=0.0, t=136.0, r=1440.0, b=360.0)px
09-25 20:35:08.518  6279  6298 D TAG     : Text = '[Name 1, Home world 1]'
09-25 20:35:08.518  6279  6298 D TAG     : Actions = [GetTextLayoutResult]

// Material 3 (not working)
09-25 20:28:03.039  5953  5972 D TAG     : Node #4 at (l=0.0, t=136.0, r=1440.0, b=388.0)px
09-25 20:28:03.039  5953  5972 D TAG     : IsTraversalGroup = 'true'
09-25 20:28:03.039  5953  5972 D TAG     :  |-Node #5 at (l=56.0, t=164.0, r=1384.0, b=360.0)px
09-25 20:28:03.039  5953  5972 D TAG     :    Text = '[Name 1, Home world 1]'
09-25 20:28:03.039  5953  5972 D TAG     :    Actions = [GetTextLayoutResult]
So, in case this is useful to others the key reason test is failing is that in Compose Material 3
ListItem
is using a
Surface
(whereas it didn't in Material 2 where test was passing).....and
Surface
in turn contains following. Not fully sure what best fix is yet.
Copy code
.semantics(mergeDescendants = false) {
    isContainer = true
}
👀 1
using following works but seems like bit of a hack
Copy code
rowNode.onChild().assertTextContains(person.name)