Skip to content

Commit

Permalink
New attempt to deflake tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Mar 15, 2024
1 parent c7476e6 commit 4eeb075
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class DpadComposeFocusViewHolderTest {
assertFocus(item = 0, isFocused = true)
assertSelection(item = 0, isSelected = true)

assertFocus(item = 1, isFocused = false)
assertSelection(item = 1, isSelected = false)

KeyEvents.pressDown()
waitForIdleScroll()

Expand All @@ -72,41 +69,27 @@ class DpadComposeFocusViewHolderTest {
assertFocus(item = 0, isFocused = false)
assertSelection(item = 0, isSelected = true)

assertFocus(item = 1, isFocused = false)
assertSelection(item = 1, isSelected = false)

assertFocus(item = 2, isFocused = false)
assertSelection(item = 2, isSelected = false)

composeTestRule.activityRule.scenario.onActivity { activity ->
activity.requestFocus()
}

assertFocus(item = 0, isFocused = true)
assertSelection(item = 0, isSelected = true)

assertFocus(item = 1, isFocused = false)
assertSelection(item = 1, isSelected = false)

assertFocus(item = 2, isFocused = false)
assertSelection(item = 2, isSelected = false)
}

@Test
fun testClicksAreDispatched() {
KeyEvents.click()

KeyEvents.pressDown()
waitForIdleScroll()

KeyEvents.click()

// given
var clicks: List<Int> = emptyList()
composeTestRule.activityRule.scenario.onActivity { activity ->
clicks = activity.getClicks()
}

assertThat(clicks).isEqualTo(listOf(0, 1))
// when
KeyEvents.click()

// then
assertThat(clicks).isEqualTo(listOf(0))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ class DpadComposeViewHolderTest {

@Test
fun testClicksAreDispatched() {
KeyEvents.click()

KeyEvents.pressDown()
waitForIdleScroll()

KeyEvents.click()

// given
var clicks: List<Int> = emptyList()
composeTestRule.activityRule.scenario.onActivity { activity ->
clicks = activity.getClicks()
}

assertThat(clicks).isEqualTo(listOf(0, 1))
// when
KeyEvents.click()

// then
assertThat(clicks).isEqualTo(listOf(0))
}

@Test
Expand Down

0 comments on commit 4eeb075

Please sign in to comment.