Skip to content

Instantly share code, notes, and snippets.

@eevajonnapanula
Created June 3, 2024 03:40
Show Gist options
  • Save eevajonnapanula/1444e0898a0a5f5b662764e284bb3b38 to your computer and use it in GitHub Desktop.
Save eevajonnapanula/1444e0898a0a5f5b662764e284bb3b38 to your computer and use it in GitHub Desktop.
class SelectableTest {
@get:Rule
val composeTestRule = createComposeRule()
@Before
fun setup() {
composeTestRule.setContent {
ModifiersExampleTheme {
SelectableScreen()
}
}
}
@Test
fun hasRoleNameValue() {
val selectableElements =
composeTestRule.onAllNodes(hasTestTag("accessible-selectable"))
// Assert accessible name
selectableElements[0].assertTextEquals("Option A")
selectableElements[1].assertTextEquals("Option B")
// Assert role
selectableElements.assertAll(isSelectable())
// Assert value
selectableElements[0].assertIsSelected()
selectableElements[1].performClick()
selectableElements[0].assertIsNotSelected()
selectableElements[1].assertIsSelected()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment