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
LazyColumn(modifier = Modifier.testTag("myLazyColumn")) { | |
// any content | |
} |
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
enum class SwitchStatus(@DrawableRes val imageRes: Int) { | |
ON(R.drawable.pacman_lamp_on), OFF(R.drawable.pacman_lamp_off) | |
} |
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
@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() |
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
<resources> | |
<string name="app_name">Semantics Testing Playground</string> | |
<string name="pacman_lamp_image_description">Pacman lamp image</string> | |
<string name="on_button_description">On button</string> | |
<string name="off_button_description">Off button</string> | |
<string name="current_status_description">Status description</string> | |
</resources> |
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) |
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
@Composable | |
fun SwitchLayout() { | |
val context = LocalContext.current | |
var status: SwitchStatus by remember { | |
mutableStateOf(SwitchStatus.OFF) | |
} | |
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(32.dp)) { | |
Image( | |
modifier = Modifier | |
.width(196.dp) |
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 MyLayoutTest { | |
@get:Rule | |
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | |
@Test | |
fun testGreetingButtonClick() { | |
composeTestRule.setContent { | |
MyLayout() | |
} | |
composeTestRule.onNode(hasParent(hasText(“Greeting Button”)) |
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 MyLayoutTest { | |
@get:Rule | |
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | |
@Test | |
fun testGreetingButtonClick() { | |
composeTestRule.setContent { | |
MyLayout() | |
} | |
composeTestRule.onNodeWithContentDescription( |
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 MyLayoutTest { | |
@get:Rule | |
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | |
@Test | |
fun testGreetingButtonExists() { | |
// Start the app | |
composeTestRule.setContent { | |
MyLayout() |
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 MyLayoutTest { | |
@get:Rule | |
val composeTestRule = createAndroidComposeRule<ComponentActivity>() | |
@Test | |
fun testGreetingButtonClick() { | |
// Start the app | |
composeTestRule.setContent { | |
MyLayout() | |
} |
NewerOlder