test: add dice roll result dialog tests (Closes #35) (#62)

This commit was merged in pull request #62.
This commit is contained in:
2026-03-13 13:43:32 +01:00
parent 9d530ed398
commit 413dcce433
4 changed files with 152 additions and 6 deletions

View File

@@ -30,6 +30,13 @@ object TestTags {
// --- Dice / roll buttons ---
fun rollButton(name: String): String = "roll_button_${name.lowercase().replace(" ", "_")}"
// --- Dice roll result dialog ---
const val DICE_ROLL_DIALOG = "dice_roll_dialog"
const val DICE_ROLL_DICE_COUNT = "dice_roll_dice_count"
const val DICE_ROLL_SUCCESS_COUNT = "dice_roll_success_count"
const val DICE_ROLL_DISMISS_BUTTON = "dice_roll_dismiss_button"
fun dieChip(index: Int): String = "die_chip_$index"
// --- Top app bar ---
const val TOP_APP_BAR = "top_app_bar"
const val THEME_TOGGLE = "theme_toggle"

View File

@@ -8,9 +8,11 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import org.shahondin1624.lib.components.TestTags
import org.shahondin1624.lib.functions.DiceRoll
/**
@@ -29,6 +31,7 @@ fun DiceRollResultDialog(
AlertDialog(
onDismissRequest = onDismiss,
modifier = Modifier.testTag(TestTags.DICE_ROLL_DIALOG),
title = {
Text(
text = rollLabel,
@@ -46,10 +49,12 @@ fun DiceRollResultDialog(
) {
Text(
text = "${diceRoll.numberOfDice} dice rolled",
modifier = Modifier.testTag(TestTags.DICE_ROLL_DICE_COUNT),
style = MaterialTheme.typography.bodyMedium
)
Text(
text = "${diceRoll.numberOfSuccesses} successes",
modifier = Modifier.testTag(TestTags.DICE_ROLL_SUCCESS_COUNT),
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold,
color = if (diceRoll.numberOfSuccesses > 0)
@@ -92,7 +97,10 @@ fun DiceRollResultDialog(
}
},
confirmButton = {
TextButton(onClick = onDismiss) {
TextButton(
onClick = onDismiss,
modifier = Modifier.testTag(TestTags.DICE_ROLL_DISMISS_BUTTON)
) {
Text("OK")
}
}
@@ -106,14 +114,14 @@ private fun DiceResultGrid(results: List<Int>) {
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
for (value in results) {
DieChip(value)
for ((index, value) in results.withIndex()) {
DieChip(value, index)
}
}
}
@Composable
private fun DieChip(value: Int) {
private fun DieChip(value: Int, index: Int) {
val isSuccess = value >= 5
val isOne = value == 1
@@ -131,7 +139,8 @@ private fun DieChip(value: Int) {
Box(
modifier = Modifier
.size(32.dp)
.background(backgroundColor, CircleShape),
.background(backgroundColor, CircleShape)
.testTag(TestTags.dieChip(index)),
contentAlignment = Alignment.Center
) {
Text(