Skip to content

Instantly share code, notes, and snippets.

@giovanileitevitor
Created October 8, 2023 00:02
Show Gist options
  • Save giovanileitevitor/550dc8c90f521596a4a595dd6d6f0b1c to your computer and use it in GitHub Desktop.
Save giovanileitevitor/550dc8c90f521596a4a595dd6d6f0b1c to your computer and use it in GitHub Desktop.
@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")
)
}
}
}
@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