Skip to content

Commit

Permalink
Deflake looping layout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Jun 19, 2024
1 parent 69e9d2c commit e0ad5d8
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ class LoopingLayoutTest : DpadRecyclerViewTest() {
fun testLayoutScrollsBackwardsToStartPosition() {
launchFragment(getDefaultAdapterConfiguration().copy(numberOfItems = 10))

KeyEvents.pressLeft(times = 10)
waitForIdleScrollState()
repeat(10) {
KeyEvents.pressLeft()
waitForIdleScrollState()
}

val currentBounds = getItemViewBounds(position = 0)
assertFocusAndSelection(position = 0)
Expand All @@ -110,8 +112,10 @@ class LoopingLayoutTest : DpadRecyclerViewTest() {
fun testLayoutScrollsForwardsToStartPosition() {
launchFragment(getDefaultAdapterConfiguration().copy(numberOfItems = 10))

KeyEvents.pressRight(times = 10)
waitForIdleScrollState()
repeat(10) {
KeyEvents.pressRight()
waitForIdleScrollState()
}

val currentBounds = getItemViewBounds(position = 0)
assertFocusAndSelection(position = 0)
Expand Down Expand Up @@ -144,14 +148,20 @@ class LoopingLayoutTest : DpadRecyclerViewTest() {
}

// Scroll forwards to begin the loop
KeyEvents.pressRight(times = 10)
repeat(10) {
KeyEvents.pressRight()
waitForIdleScrollState()
}

assertFocusAndSelection(position = 0)
assertThat(getItemViewBounds(position = 0).centerX())
.isEqualTo(getRecyclerViewBounds().centerX())

// Scroll backwards and validate start loop doesn't exist
KeyEvents.pressLeft(times = 15)
repeat(15) {
KeyEvents.pressLeft()
waitForIdleScrollState()
}
assertFocusAndSelection(position = 0)
assertThat(getChildrenBounds()).isEqualTo(startChildrenBounds)
}
Expand Down

0 comments on commit e0ad5d8

Please sign in to comment.