-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from rubensousa/dpadclickable
Improve dpadClickable to work properly with key events
- Loading branch information
Showing
18 changed files
with
471 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../androidTest/java/com/rubensousa/dpadrecyclerview/compose/DpadClickableIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.rubensousa.dpadrecyclerview.compose | ||
|
||
import androidx.compose.ui.test.SemanticsMatcher | ||
import androidx.compose.ui.test.assert | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import com.google.common.truth.Truth.assertThat | ||
import com.rubensousa.dpadrecyclerview.testing.KeyEvents | ||
import com.rubensousa.dpadrecyclerview.testing.assertions.DpadViewAssertions | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class DpadClickableIntegrationTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createAndroidComposeRule<ComposeFocusTestActivity>() | ||
|
||
@Before | ||
fun setup() { | ||
composeTestRule.waitForIdle() | ||
} | ||
|
||
@Test | ||
fun testPressingBackAfterClickingOnItemClearsFocus() { | ||
// given | ||
KeyEvents.click() | ||
|
||
// when | ||
KeyEvents.back() | ||
|
||
// then | ||
assertFocus(item = 0, isFocused = false) | ||
Espresso.onView( | ||
withId(com.rubensousa.dpadrecyclerview.compose.test.R.id.focusPlaceholder) | ||
).check(DpadViewAssertions.isFocused()) | ||
} | ||
|
||
@Test | ||
fun testClicksAreDispatched() { | ||
// given | ||
var clicks: List<Int> = emptyList() | ||
composeTestRule.activityRule.scenario.onActivity { activity -> | ||
clicks = activity.getClicks() | ||
} | ||
|
||
// when | ||
KeyEvents.click() | ||
|
||
// then | ||
assertThat(clicks).isEqualTo(listOf(0)) | ||
} | ||
|
||
@Test | ||
fun testLongClicksAreDispatched() { | ||
// given | ||
var clicks: List<Int> = emptyList() | ||
composeTestRule.activityRule.scenario.onActivity { activity -> | ||
clicks = activity.getLongClicks() | ||
} | ||
|
||
// when | ||
KeyEvents.longClick() | ||
|
||
// then | ||
assertThat(clicks).isEqualTo(listOf(0)) | ||
} | ||
|
||
private fun assertFocus(item: Int, isFocused: Boolean) { | ||
composeTestRule.onNodeWithText(item.toString()).assertIsDisplayed() | ||
.assert(SemanticsMatcher.expectValue(TestComposable.focusedKey, isFocused)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.