feat(sidecar): match idPrefix in the tap-by-selector path

This commit is contained in:
pj committed 2026-08-13 00:04:40 +05:30
1 parent a8444cc34f
commit b1a0678bf9
2 files changed
+25

No files matched your search

@@ -958,6 +958,12 @@ internal fun findBoundsInTree(
} ==
true
"idPrefix" -> attrs["resource-id"]?.let { id ->
val local = id.indexOf(":id/")
id.startsWith(value) ||
(local >= 0 && id.substring(local + 4).startsWith(value))
} == true
"text" -> attrs["text"] == value
"desc" -> attrs["content-desc"] == value
@@ -111,6 +111,25 @@ class DeviceOutputParserTest {
assertEquals(listOf(5, 6, 7, 8), findBoundsBySelector(tree, "descPrefix:AccountCard")?.toList())
}
@Test fun findBoundsBySelectorMatchesIdPrefixWithoutThePackage() {
val tree = node(
"resource-id" to "root",
children = listOf(
node(
"resource-id" to "com.example:id/customer_row_abc",
"bounds" to "[1,2,3,4]",
),
node("resource-id" to "supplier_row_x", "bounds" to "[5,6,7,8]"),
),
)
val prefix = findBoundsBySelector(tree, "idPrefix:customer_row_")
assertEquals(listOf(1, 2, 3, 4), prefix?.toList())
val qualified =
findBoundsBySelector(tree, "idPrefix:com.example:id/customer_row")
assertEquals(listOf(1, 2, 3, 4), qualified?.toList())
assertNull(findBoundsBySelector(tree, "idPrefix:invoice_row_"))
}
@Test fun findBoundsBySelectorReturnsNullForBadSelectorOrNoMatch() {
val tree = node("resource-id" to "com.example:id/x", "bounds" to "[0,0,1,1]")
assertNull(findBoundsBySelector(tree, "id"))