-
-
Save eevajonnapanula/b1fc376d09fa08504a0fc65ddc7b01ef to your computer and use it in GitHub Desktop.
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
class ClickableTest { | |
@get:Rule | |
val composeTestRule = createComposeRule() | |
@Test | |
fun hasRoleNameValue() { | |
composeTestRule.setContent { | |
ModifiersExampleTheme { | |
ClickableScreen() | |
} | |
} | |
val clickableElement = | |
composeTestRule.onNode(hasTestTag("clickable")) | |
// Assert accessible name | |
clickableElement.assertTextEquals("Bookmark this item") | |
// Assert role | |
clickableElement.assert( | |
SemanticsMatcher("has correct role") { | |
it.config.getOrNull(SemanticsProperties.Role) == Role.Button | |
}, | |
) | |
// Assert state description | |
clickableElement.assertStateDescription("Not bookmarked") | |
clickableElement.performClick() | |
clickableElement.assertStateDescription("Bookmarked") | |
} | |
private fun SemanticsNodeInteraction.assertStateDescription( | |
stateDescription: String | |
) = | |
assert( | |
SemanticsMatcher("has correct state description") { | |
it.config.getOrNull(SemanticsProperties.StateDescription) == stateDescription | |
}, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment