From e0ad5d8ef52198d9276cd487631fd5dd20114b36 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 19 Jun 2024 22:49:36 +0200 Subject: [PATCH] Deflake looping layout tests --- .../test/tests/layout/LoopingLayoutTest.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LoopingLayoutTest.kt b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LoopingLayoutTest.kt index 20d2010e..970460e3 100644 --- a/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LoopingLayoutTest.kt +++ b/dpadrecyclerview/src/androidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/layout/LoopingLayoutTest.kt @@ -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) @@ -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) @@ -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) }