Skip to content

Commit

Permalink
Add new test for smooth scrolling changes of lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Sep 25, 2024
1 parent 03c19f3 commit dad6c5c
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,49 @@ class AlignmentLookupTest : DpadRecyclerViewTest() {
assertThat(viewBounds.bottom).isEqualTo(recyclerViewBounds.bottom)
}

@Test
fun testAlignmentLookupSmoothScrolling() = report {
Given("Launch Fragment with top alignment") {
launchFragment()
}

var scrolled = false
When("Set AlignmentLookup for 50% of screen height") {
onRecyclerView("Set alignment") { recyclerView ->
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState != RecyclerView.SCROLL_STATE_IDLE) {
scrolled = true
}
}
})
recyclerView.setAlignmentLookup(
object : AlignmentLookup {
override fun getParentAlignment(
viewHolder: RecyclerView.ViewHolder,
): ParentAlignment {
return ParentAlignment(fraction = 0.5f)
}

override fun getChildAlignment(
viewHolder: RecyclerView.ViewHolder,
): ChildAlignment {
return ChildAlignment(fraction = 0.5f)
}
},
smooth = true
)
}
}

Then("RecyclerView scrolled to new position") {
waitForIdleScrollState()
val recyclerViewBounds = getRecyclerViewBounds()
val viewBounds = getItemViewBounds(position = 0)
assertThat(scrolled).isTrue()
assertThat(viewBounds.centerY()).isEqualTo(recyclerViewBounds.height() / 2)
}
}

}

0 comments on commit dad6c5c

Please sign in to comment.