Last active
December 29, 2023 16:10
-
-
Save ngallazzi/cd336f3c0f84e12e3bed8c1cd028c1a6 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 SwitchLayoutKtTest { | |
// Create test rule, we need android context so we use createAndroidComposeRule factory method | |
@get:Rule | |
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | |
@Test | |
fun testButtonOn_setsOnState() { | |
val context = composeTestRule.activity | |
val onButtonNodeIdentifier = context.getString(R.string.on_button_description) | |
val currentStatusNodeIdentifier = context.getString(R.string.current_status_description) | |
// Start the app | |
composeTestRule.setContent { | |
SemanticsTestingPlaygroundTheme { | |
SwitchLayout() | |
} | |
} | |
// Perform click action on "on button", using its semantics matcher | |
composeTestRule.onNodeWithContentDescription(onButtonNodeIdentifier).performClick() | |
// Assert status text switches to "on status" | |
composeTestRule.onNodeWithContentDescription(currentStatusNodeIdentifier) | |
.assertTextEquals("Status is: ${SwitchStatus.ON.name}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment