Skip to content

Commit

Permalink
Simplify list child declaration
Browse files Browse the repository at this point in the history
lazy { getChild() } -> child {}
  • Loading branch information
aleks-ex committed Mar 7, 2024
1 parent 379dbd7 commit 598929d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ object ComposeListPage : Page<ComposeListPage>() {
fun getContactItemByTestTag(contact: Contact): ComposeFriendListItem = lazyList.getItem(hasTestTag(getContactItemTestTagById(contact)))
fun getContactItemByName(contact: Contact): ComposeFriendListItem = lazyList.getItem(hasAnyDescendant(hasText(contact.name) and hasTestTag(contactNameTestTag)))
class ComposeFriendListItem : UltronComposeListItem() {
val name by lazy { getChild(hasTestTag(contactNameTestTag)) }
val name by child { hasTestTag(contactNameTestTag) }
val status by lazy { getChild(hasTestTag(contactStatusTestTag)) }
val notExisted by lazy { getChild(hasTestTag("NotExistedChild")) }
val notExisted by child { hasTestTag("NotExistedChild") }
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object FriendsListPage : Page<FriendsListPage>() {
}

class FriendRecyclerItem : UltronRecyclerViewItem() {
val name by lazy { getChild(withId(R.id.tv_name)) }
val name by child { withId(R.id.tv_name) }
val status by lazy { getChild(withId(R.id.tv_status)) }
val avatar by lazy { getChild(withId(R.id.avatar)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ open class UltronComposeListItem {
*/
protected constructor()

fun child(block: () -> SemanticsMatcher): Lazy<UltronComposeSemanticsNodeInteraction> = lazy {
getChild(block())
}

fun setExecutor(ultronComposeList: UltronComposeList, itemMatcher: SemanticsMatcher) {
this.executor = MatcherComposeItemExecutor(ultronComposeList, itemMatcher)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ open class UltronRecyclerViewItem {
*/
protected constructor()

fun child(block: () -> Matcher<View>): Lazy<Matcher<View>> = lazy {
getChild(block())
}

constructor(
ultronRecyclerView: UltronRecyclerView,
itemViewMatcher: Matcher<View>,
Expand Down

0 comments on commit 598929d

Please sign in to comment.