Skip to content

Instantly share code, notes, and snippets.

@ngallazzi
Last active December 29, 2023 16:14
Show Gist options
  • Save ngallazzi/8fd62c2f043c45782d958f2007178a4d to your computer and use it in GitHub Desktop.
Save ngallazzi/8fd62c2f043c45782d958f2007178a4d to your computer and use it in GitHub Desktop.
@Test
fun testButtonOff_setsOffState() {
val context = composeTestRule.activity
val onButtonNodeIdentifier = context.getString(R.string.on_button_description)
val offButtonNodeIdentifier = context.getString(R.string.off_button_description)
val currentStatusNodeIdentifier = context.getString(R.string.current_status_description)
// Start the app
composeTestRule.setContent {
SemanticsTestingPlaygroundTheme {
SwitchLayout()
}
}
// Click off button
composeTestRule.onNodeWithContentDescription(offButtonNodeIdentifier).performClick()
composeTestRule.onNodeWithContentDescription(currentStatusNodeIdentifier)
.assertTextEquals("Status is: ${SwitchStatus.OFF.name}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment