Created
October 8, 2023 00:02
-
-
Save giovanileitevitor/550dc8c90f521596a4a595dd6d6f0b1c 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
@Composable | |
fun SimpleButtonDemo(){ | |
val textA = stringResource(id = R.string.textA) | |
val textB = stringResource(id = R.string.textB) | |
val colorA = colorResource(id = R.color.purple_200) | |
val colorB = colorResource(id = R.color.teal_700) | |
var text by remember{ mutableStateOf(textA)} | |
var color by remember { mutableStateOf(colorA) } | |
Box( | |
modifier = Modifier.fillMaxSize().testTag("BOXTAG"), | |
contentAlignment = Alignment.Center | |
){ | |
Button( | |
onClick = { | |
if(text == textA) { | |
text = textB | |
color = colorB | |
} else{ | |
text = textA | |
color = colorB | |
} | |
} | |
){ | |
Text( | |
text = text, | |
color = colorB, | |
modifier = Modifier | |
.testTag("TEXTTAG") | |
) | |
} | |
} | |
} |
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
@RunWith(AndroidJUnit4::class) | |
class SimpleButtonInstTest { | |
@get:Rule | |
val rule = createComposeRule() | |
@Before | |
fun setup(){ | |
rule.setContent { | |
SimpleButtonDemo() | |
} | |
rule.onNode(hasTestTag("BOXTAG"), useUnmergedTree = true).assertExists() | |
rule.onNode(hasTestTag("TEXTTAG"), useUnmergedTree = true).assertExists() | |
} | |
@Test | |
fun TestIfBoxExists(){ | |
rule.onNode(hasTestTag("BOXTAG"), useUnmergedTree = true) | |
.assertExists() | |
} | |
@Test | |
fun TextIfTextonButtonExists(){ | |
rule.onNode(hasTestTag("TEXTTAG"), useUnmergedTree = true) | |
.assertExists() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment